本文沒有采用紅帽自帶的pcs配置集羣資源,而採用crm配置集羣資源,各人喜好,crm相對於pcs功能更強,更易上手。
配置集羣前的準備工作:
同步時間、主機名解析
兩節點安裝: yum --y install pcs
兩節點開啓服務:systemctl start pcsd systemctl enable pcsd
設置hacluster密碼:echo "123456" |passwd --stdin hacluster
認證兩臺主機:pcs cluster auth node1 node2 -u hacluster
設置集羣: pcs cluster setup --name myclustername node1 node2 #此時會生成/etc/corosync/corosync.onf的配置文件,修改logging字斷中的日誌存放方式:
logging {
to_logfile:yes
logfile:/var/log/cluster/corosync.log
}
啓動集羣:pcs cluster start --all 或指定集羣名
驗證集羣狀態:corosync-cfgtool -s 或 crm_verify -L -V
檢查成員關係:corosync-cmapctl 或者 # pcs status
此時如果是兩臺可能會看到關於stonith設備的warning,但是可以通過修改集羣全局屬性將此warning關掉。
# pcs property set stonith-enabled=false
下載安裝crmsh來配置與管理集羣資源
下載:crmsh-2.1.4-1.1.x86_64.rpm pssh-2.3.1-4.2.x86_64.rpm python-pssh-2.3.1-4.2.x86_64.rpm
安裝:yum install crmsh-2.1.4-1.1.x86_64.rpm pssh-2.3.1-4.2.x86_64.rpm python-pssh-2.3.1-4.2.x86_64.rpm
顯示洋集羣狀態:crm status
交互式:crm(live)# configure
crm(live)configure# show 查看集羣狀態
NFS集羣具體操作步驟:
1、安裝(node1 and node2)
# yum install pcs
# yum install crmsh-2.1.4-1.1.x86_64.rpm pssh-2.3.1-4.2.x86_64.rpm python- pssh-2.3.1-4.2.x86_64.rpm
2、配置用戶及認證(node1 and node2)
# echo "root123" |passwd --stdin hacluster
# pcs cluster auth node1 node2 -u hacluster
3、安裝集羣(node1 or node2)
# pcs cluster setup --name nfscluster node1 node2
# pcs cluster start --all
4、配置集羣(node1 or node2)
1、修改logfile
# /etc/corosync/corosync.onf
logging {
to_logfile:yes
logfile:/var/log/cluster/corosync.log
}
2、關閉stonith警告
# pcs property set stonith-enabled=false
5、創建 NFS資源代理(node1 or node2)
1、創建ip資源
localhost# crm
crm(live)# configure
crm(live)configure# primitive nfsvip ocf:heartbeat:IPaddr params nic=eth0 ip=xx.xx.xx.xx
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show
crm(live)configure# exit
2、創建磁盤掛載
localhost# crm
crm(live)# configure
crm(live)configure# primitive nfsdriver ocf:heartbeat:Filesystem params device=/dev/sdb1 directory=/S1/dir1 fstype=ext4
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show
crm(live)configure# exit
3、創建NFS服務代理
localhost# crm
crm(live)# configure
crm(live)configure# primitive nfsserver systemd:nfs-server
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show
crm(live)configure# exit
6、創建資源代理組(node1 or node2)
localhost# crm
crm(live)# configure
crm(live)configure# group nfsservice nfsvip nfsdriver nfsserver
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show
crm(live)configure# exit
7、測試(node1 or node2)
localhost# crm
crm(live)# node standy 置從:資源組轉移至其它節點
crm(live)# node online 恢復