1. 程式人生 > >**VMware Centos7部署三節點ceph叢集**

**VMware Centos7部署三節點ceph叢集**

VMware Centos7部署三節點ceph叢集

一、環境配置
【使用VMware安裝CentOS7】請參考https://blog.csdn.net/hui_2016/article/details/68927487
【VMware上centos7克隆多個虛擬機器】請參考https://www.cnblogs.com/Lynette/p/9470800.html
【CentOS 7將網絡卡名稱eno16777736改為eth0】請參考https://www.linuxidc.com/Linux/2015-09/123396.htm
【Vmware為虛擬機器新增硬碟】請參考https://jingyan.baidu.com/article/63f236284305310208ab3d85.html

因為後邊要用到,所以需要給虛擬機器新增硬碟(10GB以上),三個Centos7都需要。
新增後進行硬碟分割槽:
執行命令:fdisk /dev/sdb
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-102, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-102, default 102): 102


Command (m for help): t
Selected partition 1
Hex code (type L to list codes): FD
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
【****上述需要輸入數字時,按照實際default後面的數字進行操作就可以】

二、部署ceph步驟
注意:後面步驟中vim修改只讀檔案,儲存退出命令:****:w !sudo tee %
在VMware中安裝一個Centos7,然後克隆兩個,共三個Centos7,即三個節點。
執行命令:ifconfig 檢視每個Centos7的ip地址

我的三個節點分別是:
192.168.23.131 節點1 (mon, admin, ceph-deploy)
192.168.23.133 節點2 (osd)
192.168.23.134 節點3 (osd)
【1】分別在三個節點上都關閉selinux
執行命令:vi /etc/selinux/config
將SELINUX值設為disabled
執行命令:reboot
關閉防火牆,執行命令:sudo systemctl stop firewalld
【2】分別在三個節點上建立使用者並賦予root許可權
這裡建立的使用者為:cent 密碼是cent

sudo useradd -d /home/cent -m cent 
sudo passwd cent  
密碼cent
echo "cent ALL=(root)NOPASSWD:ALL" |sudo tee /etc/sudoers.d/cent 
sudo chmod 0440 /etc/sudoers.d/cent 
su cent (切換到cent使用者,不能用root或sudo執行ceph-deploy命令)
【****後續的操作全部在cent下執行】
sudo visudo(修改其中Defaults requiretty為Defaults:cent !requiretty【在比較下面一點】  
sudo hostname node1 (其他的兩個節點就是node2和node3了)        
sudo yum install ntp ntpdate ntp-doc 
sudo yum install openssh-server

【3】修改node1的hosts檔案

vim /etc/hosts
新增:192.168.0.1 node1 192.168.0.2 node2 192.168.0.3 node3

【4】配置node1的yum源

cd /etc/yum.repos.d
vi ceph.repo
	寫入以下內容 
	[Ceph] 
	name=Ceph packages for $basearch 
	baseurl=http://mirrors.163.com/ceph/rpm-jewel/el7/$basearch 
	enabled=1 
	gpgcheck=0 
	type=rpm-md 
	gpgkey=https://mirrors.163.com/ceph/keys/release.asc 
	priority=1
	[Ceph-noarch]
	name=Ceph noarch packages 
	baseurl=http://mirrors.163.com/ceph/rpm-jewel/el7/noarch 
	enabled=1 
	gpgcheck=0 
	type=rpm-md 
	gpgkey=https://mirrors.163.com/ceph/keys/release.asc 
	priority=1 
	[ceph-source] 
	name=Ceph source packages 
	baseurl=http://mirrors.163.com/ceph/rpm-jewel/el7/SRPMS 
	enabled=1 
	gpgcheck=0 
	type=rpm-md 
	gpgkey=https://mirrors.163.com/ceph/keys/release.asc 
	priority=1

【5】在node1安裝ceph-deploy

sudo yum install yum-plugin-priorities 
sudo yum install ceph-deploy

【6】配置node1的ssh

ssh-keygen (一直回車,使用預設配置)
ssh-copy-id [email protected]  
ssh-copy-id [email protected] 
ssh-copy-id [email protected]
vim ~/.ssh/config (建立config檔案並寫入以下內容)
		Host node1
		Hostname node1 
		User cent 	
		Host node2 
		Hostname node2 
		User cent 
		Host node3 
		Hostname node3 
		User cent
cd ~/.ssh
sudo chmod 600 config (賦予config檔案許可權)

【7】在node1上建立叢集

su cent
cd ~
mkdir ceph-cluster 
cd ceph-cluster 
ceph-deploy new node1 (成功後會有ceph.conf)
vim ceph.conf (在global段最後新增) 
	       osd pool default size = 2
在ceph-cluster目錄下,執行:
		ceph-deploy install node1 node2 node3 
安裝完成後在node1中執行:
		ceph-deploy mon create-initial

【8】新增並激活osd

ssh node2 
sudo chmod -R 777 /dev/sdb
sudo chmod -R 777 /dev/sdb1
exit
ssh node3 	
sudo chmod -R 777 /dev/sdb
sudo chmod -R 777 /dev/sdb1
exit
ceph-deploy osd prepare node2:/dev/sdb node3:/dev/sdb 
ceph-deploy osd activate node2:/dev/sdb1 node3:/dev/sdb1
【****如果這兩句執行後有錯誤,請嘗試命令:
		ceph-deploy --overwrite-conf osd prepare node2:/dev/sdb node3:/dev/sdb --zap-disk
		ceph-deploy --overwrite-conf osd activate node2:/dev/sdb1 node3:/dev/sdb1】
【****如果前面步驟沒有關閉防火牆,這裡會使osd啟用不成功。如果遇到osd啟用不成功,請試著關閉防火牆】
ceph-deploy admin node1 node2 node3
sudo chmod +r /etc/ceph/ceph.client.admin.keyring

【9】檢視ceph叢集狀態

ceph -s

如果顯示HEALTH_OK,則部署成功