Pacemaker 僅僅做資源管理器(CRM)。底下的消息系統採用 corosync。
安裝
以 ubuntu 為例,
sudo aptitude install -y pacemaker corosync
配置 corosync
改動 /etc/default/corosync
文件。改動 start=yes
,否則服務腳本無法啟動。
/etc/corosync/corosync.conf
中,改動 bindnetaddr
的值為節點之間互相通知監聽的網段(比如 eth1 所在的 10.0.100.0
網段)。
加入例如以下內容。讓corosync 啟動的時候也啟動 pacemaker(ubuntu 上執行會有 bug,還得是手動啟動)。
service { ver: 0 name: pacemaker}
改動 expected_votes
的值為大於節點數目一半的數字。
運行 corosync-keygen
命令,會生成 /etc/corosync/authkey 文件。該文件和 corosync.conf,分別拷貝到集群的各個成員節點上。
啟動 pacemaker 和 corosync
$ sudo service pacemaker restart $ sudo service corosync restart
假設啟動成功了,能夠通過 sudo corosync-cmapctl |grep members
或者 sudo crm status
查看集群中成員的狀態。
配置資源信息
在隨意一個 node 上運行以下的 crm 配置命令(實際上是通過 CLI 來編輯后面的 XML 文件)。
# crm crm(live)# configure #進入配置模式 crm(live)configure# verify #校驗配置 error: unpack_resources: Resource start-up disabled since no STONITH resources have been defined error: unpack_resources: Either configure some or disable STONITH with the stonith-enabled option error: unpack_resources: NOTE: Clusters with shared data need STONITH to ensure data integrity Errors found during check: config not valid -V may provide more details crm(live)configure# property stonith-enabled=false #依據校驗情況,關閉 stonith crm(live)configure# commit # 提交改動 crm(live)configure# verify # 又一次校驗 crm(live)configure# primitive web_ip ocf:IPaddr params ip=9.186.100.102 #定義 IP 資源,這個 ip 資源會被主節點配到自己的網卡上 crm(live)configure# primitive nginx_service lsb:nginx #定義服務資源 crm(live)configure# commit crm(live)configure# group mygroup web_ip nginx_service #定義資源組 crm(live)configure# commit crm(live)configure# property no-quorum-policy=ignore #投票權不到一半時的策略 crm(live)configure# commit crm(live)configure# exit
測試
分別在各個節點上啟動 nginx,頁面填入不同內容。
訪問配置的虛 IP,即 9.186.100.102,查看詳細訪問到了哪個節點,然后在該節點上斷開 eth1,同一時候刪除 eth0:0(假設 enable 了 stonith 能夠自己主動完畢。否則要手動解決 split)。過一會又一次查看虛 IP 頁面,會發現自己主動變成了其他的節點。
轉載請注明:http://blog.csdn.net/yeasy/article/details/46638101