Corosync + Pacemaker 搭建高可用Httpd服務
實驗描述
1.兩個測試節點,分別為node5.redhat.com
和node6.redhat.com
地址分別為172.16.100.5
和172.16.100.6
2.集群服務為httpd,利用nfs做共享存儲,NFS地址為172.16.0.254
,NFS已經共享出了一個/www/htdocs
目錄并且里面有index.html
文件。
3.VIP地址為172.16.100.100
4.兩個節點系統全部為CentOS7.2
5.由于本人還需要上班,所以時間緊張,描述的有點馬虎,請多見諒。如有錯誤的地方,還請提出改正。
配置步驟
1.在所有節點安裝pcs
,并啟動相應的pcsd
進程
[root@node5 ~]# yum install pcs -y
[root@node5 ~]# systemctl start pcsd.service[root@node6 ~]# yum install pcs -y
[root@node6 ~]# systemctl start pcsd.service
2.給所有節點上的hacluster
用戶設置一個密碼。
[root@node5 ~]# echo “redhat” | passwd –stdin hacluster
[root@node6 ~]# echo “redhat” | passwd –stdin hacluster
3.在一個節點上驗證兩個節點
[root@node5 ~]# pcs cluster auth node5.redhat.com node6.redhat.com
Username: hacluster
Password:這里輸入的密碼默認不會顯示
node5.redhat.com: Authorized
node6.redhat.com: Authorized
4.將兩個節點加入集群
[root@node5 ~]# pcs cluster setup –name mycluster node5.redhat.com node6.redhat.com
添加節點的輸出信息
Shutting down pacemaker/corosync services…
Redirecting to /bin/systemctl stop pacemaker.service
Redirecting to /bin/systemctl stop corosync.service
Killing any remaining services…
Removing all cluster configuration files…
node5.redhat.com: Succeeded
node6.redhat.com: Succeeded
Synchronizing pcsd certificates on nodes node5.redhat.com, node6.redhat.com…
node5.redhat.com: Success
node6.redhat.com: SuccessRestaring pcsd on the nodes in order to reload the certificates…
node5.redhat.com: Success*顯示添加成功*
node6.redhat.com: Success*顯示添加成功*
5.兩個節點同時啟動corosync
和pacemaker
進程
[root@node5 ~]# systemctl start corosync.service
[root@node5 ~]# systemctl start pacemaker.service[root@node6 ~]# systemctl start corosync.service
[root@node6 ~]# systemctl start pacemaker.service
6.在兩個節點上安裝httpd進程并設置為開機啟動
root@node5 ~]# yum install httpd -y
systemctl enable httpd.serviceroot@node6 ~]# yum install httpd -y
systemctl enable httpd.service
7.在兩個節點上安裝nft-utils
以實現支持掛載nfs共享
[root@node5 ~]# yum install nfs-utils
[root@node6 ~]# yum install nfs-utils
8.安裝crmsh
,CentOS7默認不帶crmsh,需要去網上下載rpm包,我用的是crmsh-2.2.0-7.1.noarch.rpm
和crmsh-scripts-2.2.0-7.1.noarch.rpm
、python-parallax-1.0.1-10.1.noarch.rpm
[root@node5 ~]# yum install crmsh-2.2.0-7.1.noarch.rpm crmsh-scripts-2.2.0-7.1.noarch.rpm python-parallax-1.0.1-10.1.noarch.rpm -y
[root@node6 ~]# yum install crmsh-2.2.0-7.1.noarch.rpm crmsh-scripts-2.2.0-7.1.noarch.rpm python-parallax-1.0.1-10.1.noarch.rpm -y
9.利用crmsh配置資源
[root@node5 ~]# crm configure
配置VIP資源
crm(live)configure# primitive webip ocf:heartbeat:IPaddr ip=’172.16.100.100’ op monitor interval=20s timeout=40s配置NFS資源
crm(live)configure# primitive webstore ocf:heartbeat:Filesystem params device=’172.16.0.254:/www/htdocs’ directory=’/var/www/html’ fstype=’nfs’ op start timeout=60s op stop timeout=60s op monitor interval=20s timeout=40s配置WEB資源
crm(live)configure# primitive webserver systemd:httpd op start timeout=60s op stop timeout=60s op monitor interval=20s timeout=60s
因為是兩節點集群,需要關閉stonith
crm(live)configure# property stonith-enabled=falsecrm(live)configure# commit
10.設置這三個服務要同時在一個節點上運行,并且啟動順序一定為VIP -> NFS -> httpd
設置三個服務在同一節點上運行有兩種方法實現,一種是將所有資源設置到同一個組
里面,或者設置排列約束
。當然,即設置了組,又定義為了排列約束也是可以的。設置啟動順序那么必須使用順序約束
。
設置組
crm(live)configure# group webservice webip webstore webserver
或排列約束
crm(live)configure# colocation webip_with_webstore inf: webip webstore
crm(live)configure# colocation webstore_with_webserver inf: webstore webserver順序約束
crm(live)configure# order webip_before_webstore Mandatory: webip webstore
crm(live)configure# order webstore_before_webserver Mandatory: webstore webserver
crm(live)configure# commit
驗證配置
1.首先查看集群狀態
crm(live)configure# cd 退出到crmsh的主配置界面
crm(live)#status 輸出status查看集群狀態
一切正常
2.打開瀏覽器,輸入VIP地址進行查看。
測試也是正常的
3.將node5節點設置為standby狀態,查看服務是否轉移成功。
crm(live)# node standby node5.redhat.com
crm(live)# status
可以看到node服務轉移到了node6節點上
4.再次打開瀏覽器進行測試。
服務依舊正常,這樣就實現了我們高可用的目的。
原創文章,作者:張小凡,如若轉載,請注明出處:http://www.www58058.com/14207
結構清晰明白,內容詳略得當,贊