Corosync + Pacemaker 搭建高可用Httpd服務

實驗描述

1.兩個測試節點,分別爲node5.redhat.comnode6.redhat.com地址分別爲172.16.100.5172.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: Success

Restaring pcsd on the nodes in order to reload the certificates…
node5.redhat.com: Success *顯示添加成功*
node6.redhat.com: Success *顯示添加成功*

5.兩個節點同時啓動corosyncpacemaker進程

[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.service

root@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.rpmcrmsh-scripts-2.2.0-7.1.noarch.rpmpython-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=false

crm(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查看集羣狀態

Alt text1.jpg

一切正常

2.打開瀏覽器,輸入VIP地址進行查看。

Alt text2.jpg

測試也是正常的

3.將node5節點設置爲standby狀態,查看服務是否轉移成功。

crm(live)# node standby node5.redhat.com
crm(live)# status

Alt text3.jpg

可以看到node服務轉移到了node6節點上

4.再次打開瀏覽器進行測試。

2.jpg

服務依舊正常,這樣就實現了我們高可用的目的。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章