示例是搭建一個高可用性 KVM 系統:
需要的元件 :pacemaker,corosync, libvirt,qemu-kvm and open-iscsi
可以在centos 6.1 版本上完美安裝 yum 安裝就可以了。
叢集包括3個節點 : alice, bob andcharlie 通過 iscsi 連線共享儲存iqn.2011-09.com.hastexo:virtcluster。
每個節點上安裝 libvirt;/KVM 虛擬機器 從iscsi 上劃lun 作為存。
3個虛擬機器分別: xray, yankee and zulu
corosync 的配置:
vi /etc/corosync/corosync.conf
02 | # Enable node authentication & encryption |
05 | # Redundant ring protocol: none, active, passive. |
08 | # Redundant communications interfaces |
11 | bindnetaddr: 192.168.0.0 |
12 | mcastaddr: 239.255.29.144 |
17 | bindnetaddr: 192.168.42.0 |
18 | mcastaddr: 239.255.42.0 |
38 | syslog_facility: daemon |
這裡比較重要的一點是使用了兩個interface : 可以保證節點之間多條連線通路。
authkey : /etc/corosync/authkey
可以通過 corosync-keygen 來生成。
安裝完一臺,把他們copy到其他機器。就可以啟動corosync 服務了
service corosync start
看看狀態:
corosync-cfgtool -s
Printing ring status.Local node ID 303938909RING ID 0 id = 192.168.0.1 status = ring 0 active with no faultsRING ID 1 id = 192.168.42.1 status = ring 1 active with no faults
corosync 啟動之後,就可以啟動pacemaker 了
service pacemaker start
用crm status 或者crm_mon 檢視狀態:
============Last updated: Fri Feb 3 18:40:15 2012Stack: openaisCurrent DC: bob - partition with quorumVersion: 1.1.6-4.el6-89678d4947c5bd466e2f31acd58ea4e1edb854d53 Nodes configured, 3 expected votes0 Resources configured.============
配置資源:
03 | primitive p_iscsi ocf:heartbeat:iscsi \ |
04 | params portal="192.168.122.100:3260" \ |
05 | target="iqn.2011-09.com.hastexo:virtcluster" \ |
06 | op monitor interval="10" |
07 | primitive p_xray ocf:heartbeat:VirtualDomain \ |
08 | params config="/etc/libvirt/qemu/xray.xml" \ |
09 | op monitor interval="30" timeout="30" \ |
10 | op start interval="0" timeout="120" \ |
11 | op stop interval="0" timeout="120" |
12 | primitive p_yankee ocf:heartbeat:VirtualDomain \ |
13 | params config="/etc/libvirt/qemu/yankee.xml" \ |
14 | op monitor interval="30" timeout="30" \ |
15 | op start interval="0" timeout="120" \ |
16 | op stop interval="0" timeout="120" |
17 | primitive p_zulu ocf:heartbeat:VirtualDomain \ |
18 | params config="/etc/libvirt/qemu/zulu.xml" \ |
19 | op monitor interval="30" timeout="30" \ |
20 | op start interval="0" timeout="120" \ |
21 | op stop interval="0" timeout="120" |
23 | colocation c_xray_on_iscsi inf: p_xray cl_iscsi |
24 | colocation c_yankee_on_iscsi inf: p_yankee cl_iscsi |
25 | colocation c_zulu_on_iscsi inf: p_zulu cl_iscsi |
26 | order o_iscsi_before_xray inf: cl_iscsi p_xray |
27 | order o_iscsi_before_yankee inf: cl_iscsi p_yankee |
28 | order o_iscsi_before_zulu inf: cl_iscsi p_zulu |
新增stonish 裝置:
02 | primitive p_ipmi_alice stonith:external/ipmi \ |
03 | params hostname="alice" ipaddr="192.168.15.1" \ |
04 | userid="admin" passwd="foobar" \ |
05 | op start interval="0" timeout="60" \ |
06 | op monitor interval="120" timeout="60" |
07 | primitive p_ipmi_bob stonith:external/ipmi \ |
08 | params hostname="bob" ipaddr="192.168.15.2" \ |
09 | userid="admin" passwd="foobar" \ |
10 | op start interval="0" timeout="60" \ |
11 | op monitor interval="120" timeout="60" |
12 | primitive p_ipmi_charlie stonith:external/ipmi \ |
13 | params hostname="charlie" ipaddr="192.168.15.3" \ |
14 | userid="admin" passwd="foobar" \ |
15 | op start interval="0" timeout="60" \ |
16 | op monitor interval="120" timeout="60" |
17 | location l_ipmi_alice p_ipmi_alice -inf: alice |
18 | location l_ipmi_bob p_ipmi_bob -inf: bob |
19 | location l_ipmi_charlie p_ipmi_charlie -inf: charlie |
20 | property stonith-enabled="true" |
注: 我們的虛擬機器裡沒有stonish 裝置這步可以把 property stonith-enabled 改為false
crm_mon的輸出:
============Last updated: Fri Feb 3 19:46:29 2012Stack: openaisCurrent DC: bob - partition with quorumVersion: 1.1.6-4.el6-89678d4947c5bd466e2f31acd58ea4e1edb854d53 Nodes configured, 3 expected votes9 Resources configured.============Online: [ alice bob charlie ] Clone Set: cl_iscsi [p_iscsi] Started: [ alice bob charlie ] p_ipmi_alice (stonith:external/ipmi): Started bob p_ipmi_bob (stonith:external/ipmi): Started charlie p_ipmi_charlie
(stonith:external/ipmi): Started alice p_xray
(ocf::heartbeat:VirtualDomain):
Started alice p_yankee (ocf::heartbeat:VirtualDomain):
Started bob p_zulu (ocf::heartbeat:VirtualDomain): Started charlie
人為的製作一個故障; crm-mon輸出:
============Last updated: Sat Feb 4 16:18:00 2012Stack: openaisCurrent DC: bob - partition with quorumVersion: 1.1.6-4.el6-89678d4947c5bd466e2f31acd58ea4e1edb854d53 Nodes configured, 2 expected votes9 Resources configured.============Online: [ alice bob ]OFFLINE: [ charlie ]Full list of resources: Clone Set: cl_iscsi [p_iscsi] Started: [ alice bob ] Stopped: [ p_iscsi:2 ] p_ipmi_alice (stonith:external/ipmi): Started bob p_ipmi_bob (stonith:external/ipmi): Started alice p_ipmi_charlie (stonith:external/ipmi): Started alice p_xray
(ocf::heartbeat:VirtualDomain):
Started bob p_yankee (ocf::heartbeat:VirtualDomain):
Started bob p_zulu (ocf::heartbeat:VirtualDomain): Started alice
charlie 當機了。
但是charlie 上的服務轉到了 alice 上執行了。
系統剛搭配後的系統拓撲。
發生故障後的系統拓撲:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/133735/viewspace-741116/,如需轉載,請註明出處,否則將追究法律責任。