以下操作基于rhel6.5
本次實驗保證其他負載均衡和高可用軟體全部關掉!
server1和server4上安裝Haproxy:
server1:
安裝見上篇博文:
scp haproxy-1.6.11-1.x86_64.rpm 172.25.50.4:/root
scp /etc/haproxy/haproxy.cfg 172.25.50。4:/etc/haproxy
scp /etc/security/limits.conf 172.25.50.4:/etc/security
vim /etc/haproxy/haproxy.cfg
37 bind 172.25.50.100:80 name clear #設定隻有通路172.25.50.100才能通路叢集資源
/etc/init.d/haproxy start
測試:打開後端伺服器server2和server3:
server1和server4:curl 172.25.50.100
可以看到server3的之前搭建的php頁面。
server1和server4安裝pacemaker和corosync:
【其中corosync在之前RHCS套件那篇博文時已經安裝,因為RHCS套件的高可用也是利用corosync實作心跳檢測。】
server1:
yum install -y pacemaker corosync
/etc/init.d/corosync start
[[email protected] ~]# cd /etc/corosync/
[[email protected] corosync]# cp corosync.conf.example corosync.conf
[[email protected] corosync]# vim corosync.conf
10 bindnetaddr: 172.25.50.0
11 mcastaddr: 226.94.1.50
12 mcastport: 5405
34 service{
35 name:pacemaker
36 ver:0
37 }
[[email protected] corosync]# scp corosync.conf 172.25.50.4:/etc/corosync/
[[email protected] corosync]# /etc/init.d/corosync start
Starting Corosync Cluster Engine (corosync): [ OK ]
[[email protected] corosync]# tail -f /var/log/messages
#如果日志中有很多error,可能是因為多點傳播位址或者端口沖突
#健康檢查:
[[email protected] ~]# crm_verify -LV 發現沒有fence裝置報錯
#安裝crm管理工具:
[[email protected] ~]# yum install crmsh-1.2.6-0.rc2.2.1.x86_64.rpm pssh-2.3.1-2.1.x86_64.rpm
#配置禁掉fence功能
在主機上:/etc/fence_virtd stop
[[email protected] ~]# crm
crm(live)# configure
crm(live)configure# property stonith-enabled=false
[[email protected] ~]# crm_verify -LV #不報錯
#關閉叢集對節點數量的檢查,叢集預設最少量台主機,如果隻是一台主機不能接管資源
crm(live)configure# property no-quorum-policy=ignore
crm(live)configure# commit
#添加資源,vip
crm(live)configure# primitive vip ocf:heartbeat:IPaddr2 params ip=172.25.50.100 cidr_netmask=24 op monitor interval=20s#添加vip并設定20s對資源監察一次,監控端可以發現vip資源添加上
crm(live)configure# commit
測試:在主機上通路:curl 172.25.50.100
可以看見server3上的html頁面。關掉其中一台corosnsc,vip會上到另一台主機上。
#添加資源haproxy:
crm(live)configure# primitive haproxy lsb:haproxy op monitor interval=30s
crm(live)configure# commit
#添加haproxy後可以看出來vip和haproxy不再一台主機上,資源飄移:
#解決辦法:建立資源組就可以解決
crm(live)configure# group westos vip haproxy
crm(live)configure# commit
#添加資源fence:
添加fence之前首先開啟主機上:systemctl start fence_virtd
yum install -y fence-virt.x86_64 fence-agents.x86_64 #兩台主機上都做(server1和server4) ``!!!!! ``
crm(live)configure# property stonith-enabled=true #開啟fence功能
crm(live)configure# commit
[[email protected] ~]# stonith_admin -I #檢視主機支援fence的代理類型。本次使用fence_xvm
[[email protected] ~]# stonith_admin -M -a fence_xvm
crm(live)configure# primitive vmfence stonith:fence_xvm params pcmk_host_map="server1:server1;server4:server4" op monitor interval=1min
#添加fence資源,并做好叢集節點名和真實server的名字映射
#測試fence功能:
首先設定:corsync在兩台主機上可其自啟動:chkconfig corosync on
reboot(重新開機動)其中一台主機,等主機開啟後會自動加到叢集中!
#對叢集資源的管理:
crm(live)resource# show #顯示資源種類,此處時隻添加了一個資源vip,是以顯示一個
vip (ocf::heartbeat:IPaddr2): Started #開啟vip資源
crm(live)resource# stop vip
crm(live)resource# show
vip (ocf::heartbeat:IPaddr2): Stopped #停掉vip資源
#對叢集節點的管理:
[[email protected] ~]# crm
crm(live)# node
crm(live)node# standby #停掉server1節點
crm(live)node# online #開啟server1節點
server4:和server1是同步的,但此處作為監控
yum install -y pacemaker corosync
/etc/init.d/corosync start
#安裝管理工具:
[[email protected] ~]# yum install pssh-2.3.1-2.1.x86_64.rpm crmsh-1.2.6-0.rc2.2.1.x86_64.rpm
#監控叢集:
[[email protected] ~]# crm_mon
END