一、pacemaker 是什麼
二、pacemaker 特點
三、pacemaker 軟體包供應商
四、pacemaker 版本資訊
五、pacemaker 配置案例
六、pacemaker 支援叢集架構
七、pacemaker 内部結構
八、pacemaker 源代碼組成
九、Centos6.4+Corosync+Pacemaker 實作高可用的Web叢集
Linux 高可用(HA)叢集基本概念詳解 http://www.linuxidc.com/Linux/2013-08/88522.htm
Linux 高可用(HA)叢集之Heartbeat詳解 http://www.linuxidc.com/Linux/2013-08/88521.htm
Corosync+Pacemaker+DRBD+MySQL 實作高可用(HA)的MySQL叢集 http://www.linuxidc.com/Linux/2013-08/89036.htm
1.pacemaker 簡單說明
pacemaker(直譯:心髒起搏器),是一個群集資料總管。它實作較大可用性群集服務(亦稱資源管理)的節點和資源級故障檢測和恢複使用您的推薦叢集基礎設施(OpenAIS的或Heaerbeat)提供的消息和成員能力。
它可以做乎任何規模的叢集,并配備了一個強大的依賴模型,使管理者能夠準确地表達群集資源之間的關系(包括順序和位置)。幾乎任何可以編寫腳本,可以管理作為心髒起搏器叢集的一部分。
我再次說明一下,pacemaker是個資料總管,不是提供心跳資訊的,因為它似乎是一個普遍的誤解,也是值得的。pacemaker是一個延續的CRM(亦稱Heartbeat V2資料總管),最初是為心跳,但已經成為獨立的項目。
2.pacemaker 由來
大家都知道,Heartbeat 到了V3版本後,拆分為多個項目,其中pacemaker就是拆分出來的資料總管。
Heartbeat 3.0拆分之後的組成部分:
- Heartbeat:将原來的消息通信層獨立為heartbeat項目,新的heartbeat隻負責維護叢集各節點的資訊以及它們之前通信;
- Cluster Glue:相當于一個中間層,它用來将heartbeat和pacemaker關聯起來,主要包含2個部分,即為LRM和STONITH。
- Resource Agent:用來控制服務啟停,監控服務狀态的腳本集合,這些腳本将被LRM調用進而實作各種資源啟動、停止、監控等等。
- Pacemaker : 也就是Cluster Resource Manager (簡稱CRM),用來管理整個HA的控制中心,用戶端通過pacemaker來配置管理監控整個叢集。

- 主機和應用程式級别的故障檢測和恢複
- 幾乎支援任何備援配置
- 同時支援多種叢集配置模式
- 配置政策處理法定人數損失(多台機器失敗時)
- 支援應用啟動/關機順序
- 支援,必須/必須在同一台機器上運作的應用程式
- 支援多種模式的應用程式(如主/從)
- 可以測試任何故障或群集的群集狀态
注:說白了意思就是功能強大,現在最主流的資料總管。
目前pacemaker支援主流的作業系統,
- Fedora(12.0)
- 紅帽企業Linux(5.0,6.0)
- openSUSE(11.0)
- Debian
- Ubuntu的LTS(10.4)
- CentOS (5.0,6.0)
目前,版的是pacemaker 1.1.10 ,是2013年7月釋出的
1.主/從架構
說明:許多高可用性的情況下,使用Pacemaker和DRBD的雙節點主/從叢集是一個符合成本效益的解決方案。
2.多節點備份叢集
說明:支援多少節點,Pacemaker可以顯着降低硬體成本通過允許幾個主/從群集要結合和共享一個公用備份節點。
3.共享存儲叢集
說明:有共享存儲時,每個節點可能被用于故障轉移。Pacemaker甚至可以運作多個服務。
4.站點叢集
說明:Pacemaker 1.2 将包括增強簡化設立分站點叢集
接下來請看第2頁精彩内容: http://www.linuxidc.com/Linux/2013-08/89037p2.htm
六、pacemaker 支援叢集
1.基于OpenAIS的叢集
2.傳統叢集架構,基于心跳資訊
1.群集元件說明:
- stonithd:心跳系統。
- lrmd:本地資源管理守護程序。它提供了一個通用的接口支援的資源類型。直接調用資源代理(腳本)。
- pengine:政策引擎。根據目前狀态和配置叢集計算的下一個狀态。産生一個過渡圖,包含行動和依賴關系的清單。
- CIB:群集資訊庫。包含所有群集選項,節點,資源,他們彼此之間的關系和現狀的定義。同步更新到所有群集節點。
- CRMD:叢集資源管理守護程序。主要是消息代理的PEngine和LRM,還選舉一個上司者(DC)統籌活動(包括啟動/停止資源)的叢集。
- OpenAIS:OpenAIS的消息和成員層。
- Heartbeat:心跳消息層,OpenAIS的一種替代。
- CCM:共識群內建員,心跳成員層。
2.功能概述
CIB使用XML表示叢集的叢集中的所有資源的配置和目前狀态。CIB的内容會被自動在整個叢集中同步,使用PEngine計算叢集的理想狀态,生成指令清單,然後輸送到DC(指定協調員)。Pacemaker 叢集中所有節點選舉的DC節點作為主決策節點。如果當選DC節點當機,它會在所有的節點上, 迅速建立一個新的DC。DC将PEngine生成的政策,傳遞給其他節點上的LRMd(本地資源管理守護程式)或CRMD通過叢集消息傳遞基礎結構。當叢集中有節點當機,PEngine重新計算的理想政策。在某些情況下,可能有必要關閉節點,以保護共享資料或完整的資源回收。為此,Pacemaker配備了stonithd裝置。STONITH可以将其它節點“爆頭”,通常是實作與遠端電源開關。Pacemaker會将STONITH裝置,配置為資源儲存在CIB中,使他們可以更容易地監測資源失敗或當機。
說明:大家可以看到Pacemaker主要是由C語言寫的,其次是Python,說明其效率非常高。最後我們來說一個小案例,實作高可用的Web叢集。
九、CentOS6.4+Corosync+Pacemaker 實作高可用的Web叢集
1.環境說明
(1).作業系統
CentOS 6.4 X86_64 位系統
(2).軟體環境
Corosync 1.4.1
Pacemaker 1.1.8
crmsh 1.2.6
(3).拓撲準備
2.Corosync與Pacemaker 安裝與配置
Corosync與Pacemaker安裝與配置我就不在這裡重複說明了,大家參考一下這篇博文:http://www.linuxidc.com/Linux/2013-08/88733.htm (Linux 高可用(HA)叢集之Corosync詳解)
3.Pacemaker 配置資源方法
(1).指令配置方式
crmsh
pcs
(2).圖形配置方式
pygui
hawk
LCMC
注:本文主要的講解的是crmsh
4.crmsh 簡單說明
注:以下上pacemaker 1.1.8的更新說明,最重要的我用紅色标記出來,從pacemaker 1.1.8開始,crm sh 發展成一個獨立項目,pacemaker中不再提供,說明我們安裝好pacemaker後,是不會有crm這個指令行模式的資料總管的。
[root@node1 ~]# cd /usr/share/doc/pacemaker-1.1.8/
[root@node1 pacemaker-1.1.8]# ll
總用量 132
-rw-r--r-- 1 root root 1102 2月 22 13:05 AUTHORS
-rw-r--r-- 1 root root 109311 2月 22 13:05 ChangeLog
-rw-r--r-- 1 root root 18046 2月 22 13:05 COPYING
[root@node1 pacemaker-1.1.8]# vim ChangeLog
* Thu Sep 20 2012 Andrew Beekhof <[email protected]> Pacemaker-1.1.8-1
- Update source tarball to revision: 1a5341f
- Statistics:
Changesets: 1019
Diff: 2107 files changed, 117258 insertions(+), 73606 deletions(-)
- All APIs have been cleaned up and reduced to essentials
- Pacemaker now includes a replacement lrmd that supports systemd and upstart agents
- Config and state files (cib.xml, PE inputs and core files) have moved to new locations
- The crm shell has become a separate project and no longer included with Pacemaker (crm shell 已成為一個獨立的項目,pacemaker中一再提供)
- All daemons/tools now have a unified set of error codes based on errno.h (see crm_error)
[root@node1 ~]# crm
crmadmin crm_diff crm_failcount crm_mon crm_report crm_shadow crm_standby crm_verify
crm_attribute crm_error crm_master crm_node crm_resource crm_simulate crm_ticket
注:大家可以看到,安裝好pacemaker後,就沒有crm shell指令行工具,我們得單獨安裝。下面我們就來說說怎麼安裝crm sh
5.安裝crmsh資源管理工具
(1).crmsh官方網站
https://savannah.nongnu.org/forum/forum.php?forum_id=7672
(2).crmsh下載下傳位址
http://download.openSUSE.org/repositories/network:/ha-clustering:/Stable/
(3).安裝crmsh
[root@node1 ~]# rpm -ivh crmsh-1.2.6-0.rc2.2.1.x86_64.rpm
warning: crmsh-1.2.6-0.rc2.2.1.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 7b709911: NOKEY
error: Failed dependencies:
pssh is needed by crmsh-1.2.6-0.rc2.2.1.x86_64
python-dateutil is needed by crmsh-1.2.6-0.rc2.2.1.x86_64
python-lxml is needed by crmsh-1.2.6-0.rc2.2.1.x86_64
注:大家可以看到年缺少依賴包,我們先用yum安裝依賴包
[root@node1 ~]# yum install -y python-dateutil python-lxml
[root@node1 ~]# rpm -ivh crmsh-1.2.6-0.rc2.2.1.x86_64.rpm --nodeps
Preparing... ########################################### [100%]
1:crmsh ########################################### [100%]
[root@node1 ~]# crm #安裝好後出現一個crm指令,說明安裝完成
crm crm_attribute crm_error crm_master crm_node crm_resource crm_simulate crm_ticket
[root@node1 ~]# crm #輸入crm指令,進入資源配置模式
Cannot change active directory to /var/lib/pacemaker/cores/root: No such file or directory (2)
crm(live)# help #檢視一下幫助
This is crm shell, a Pacemaker command line interface.
Available commands:
cib manage shadow CIBs
resource resources management
configure CRM cluster configuration
node nodes management
options user preferences
history CRM cluster history
site Geo-cluster support
ra resource agents information center
status show cluster status
help,? show help (help topics for list of topics)
end,cd,up go back one level
quit,bye,exit exit the program
crm(live)#
注:到此準備工作全部完成,下面我們來具體配置一下高可用的Web叢集,在配置之前我們還得簡的說明一下,crm sh 如何使用!
6.crmsh使用說明
注:簡單說明一下,其實遇到一個新指令較好的方法就是man一下!簡單的先熟悉一下這個指令,然後再慢慢嘗試。
[root@node1 ~]# crm #輸入crm指令,進入crm sh 模式
crm(live)# help #輸入help檢視一下,會出下很多子指令
configure CRM cluster configuration
crm(live)# configure #輸入configure就會進入,configure模式下,
crm(live)configure# #敲兩下tab鍵就會顯示configure下全部指令
? default-timeouts group node rename simulate
bye delete help op_defaults role template
cd edit history order rsc_defaults up
cib end load primitive rsc_template upgrade
cibstatus erase location property rsc_ticket user
clone exit master ptest rsctest verify
collocation fencing_topology modgroup quit save xml
colocation filter monitor ra schema
commit graph ms refresh show
crm(live)configure# help node #輸入help加你想了解的任意指令,就會顯示該指令的使用幫助與案例
The node command describes a cluster node. Nodes in the CIB are
commonly created automatically by the CRM. Hence, you should not
need to deal with nodes unless you also want to define node
attributes. Note that it is also possible to manage node
attributes at the `node` level.
Usage:
...............
node <uname>[:<type>]
[attributes <param>=<value> [<param>=<value>...]]
[utilization <param>=<value> [<param>=<value>...]]
type :: normal | member | ping
Example:
node node1
node big_node attributes memory=64
...............
注:好了,簡單說明就到這,其實就是一句話,不會的指令help一下。下面我們開始配置,高可用的Web叢集。
7.crmsh 配置高可用的Web叢集
(1).檢視一下預設配置
crm(live)# configure
crm(live)configure# show
node node1.test.com
node node2.test.com
property $id="cib-bootstrap-options" \
dc-version="1.1.8-7.el6-394e906" \
cluster-infrastructure="classic openais (with plugin)" \
expected-quorum-votes="2" \
(2).檢測一下配置檔案是否有錯
crm(live)# configure
crm(live)configure# verify
crm_verify[5202]: 2011/06/14_19:10:38 ERROR: unpack_resources: Resource start-up disabled since no STONITH resources have been defined
crm_verify[5202]: 2011/06/14_19:10:38 ERROR: unpack_resources: Either configure some or disable STONITH with the stonith-enabled option
crm_verify[5202]: 2011/06/14_19:10:38 ERROR: unpack_resources: NOTE: Clusters with shared data need STONITH to ensure data integrity
注:說我們的STONITH resources沒有定義,因我們這裡沒有STONITH裝置,是以我們先關閉這個屬性
crm(live)configure# property stonith-enabled=false
expected-quorum-votes="2" \
stonith-enabled="false"
crm(live)configure# verify #現在已經不報錯
(3).檢視目前叢集系統所支援的類型
crm(live)# ra
crm(live)ra# classes
lsb
ocf / heartbeat pacemaker RedHat
service
stonith
(4).檢視某種類别下的所用資源代理的清單
crm(live)ra# list lsb
auditd blk-availability corosync corosync-notifyd crond halt
htcacheclean httpd ip6tables iptables killall lvm2-lvmetad
lvm2-monitor messagebus netconsole netfs network nfs
nfslock ntpd ntpdate pacemaker postfix quota_nld
rdisc restorecond rpcbind rpcgssd rpcidmapd rpcsvcgssd
rsyslog sandbox saslauthd single sshd svnserve
udev-post winbind
crm(live)ra# list ocf heartbeat
AoEtarget AudibleAlarm CTDB ClusterMon Delay Dummy
EvmsSCC Evmsd Filesystem ICP IPaddr IPaddr2
IPsrcaddr IPv6addr LVM LinuxSCSI MailTo ManageRAID
ManageVE Pure-FTPd Raid1 Route SAPDatabase SAPInstance
SendArp ServeRAID SphinxSearchDaemon Squid Stateful SysInfo
VIPArip VirtualDomain WAS WAS6 WinPopup Xen
Xinetd anything apache conntrackd db2 drbd
eDir88 ethmonitor exportfs fio iSCSILogicalUnit iSCSITarget
ids iscsi jboss lxc mysql mysql-proxy
nfsserver nginx Oracle oralsnr pgsql pingd
portblock postfix proftpd rsyncd scsi2reservation sfex
symlink syslog-ng tomcat vmware
crm(live)ra# list ocf pacemaker
ClusterMon Dummy HealthCPU HealthSMART Stateful SysInfo SystemHealth controld
o2cb ping pingd
(5).檢視某個資源代理的配置方法
crm(live)ra# info ocf:heartbeat:IPaddr
Manages virtual IPv4 addresses (portable version) (ocf:heartbeat:IPaddr)
This script manages IP alias IP addresses
It can add an IP alias, or remove one.
Parameters (* denotes required, [] the default):
ip* (string): IPv4 address
The IPv4 address to be configured in dotted quad notation, for example
"192.168.1.1".
nic (string, [eth0]): Network interface
The base network interface on which the IP address will be brought
online.
If left empty, the script will try and determine this from the
routing table.
Do NOT specify an alias interface in the form eth0:1 or anything here;
rather, specify the base interface only.
Prerequisite:
There must be at least one static IP address, which is not managed by
the cluster, assigned to the network interface.
If you can not assign any static IP address on the interface,
:
(6).接下來要建立的web叢集建立一個IP位址資源(IP資源是主資源,我們檢視一下怎麼定義一個主資源)
crm(live)configure# primitive
usage: primitive <rsc> {[<class>:[<provider>:]]<type>|@<template>}
[params <param>=<value> [<param>=<value>...]]
[meta <attribute>=<value> [<attribute>=<value>...]]
[utilization <attribute>=<value> [<attribute>=<value>...]]
[operations id_spec
[op op_type [<attribute>=<value>...] ...]]
crm(live)configure# primitive vip ocf:heartbeat:IPaddr params ip=192.168.18.200 nic=eth0 cidr_netmask=24 #增加一個VIP資源
crm(live)configure# show #檢視已增加好的VIP,我用紅色标記了一下
primitive vip ocf:heartbeat:IPaddr \
params ip="192.168.18.200" nic="eth0" cidr_netmask="24"
stonith-enabled="false"
crm(live)configure# verify #檢查一下配置檔案有沒有錯誤
crm(live)configure# commit #送出配置的資源,在指令行配置資源時,隻要不用commit送出配置好資源,就不會生效,一但用commit指令送出,就會寫入到cib.xml的配置檔案中
crm(live)# status #檢視一下配置好的資源狀态,有一個資源vip,運作在node1上
Last updated: Thu Aug 15 14:24:45 2013
Last change: Thu Aug 15 14:21:21 2013 via cibadmin on node1.test.com
Stack: classic openais (with plugin)
Current DC: node1.test.com - partition with quorum
Version: 1.1.8-7.el6-394e906
2 Nodes configured, 2 expected votes
1 Resources configured.
Online: [ node1.test.com node2.test.com ]
vip (ocf::heartbeat:IPaddr): Started node1.test.com
檢視一下node1節點上的ip,大家可以看到vip已經生效,而後我們到node2上通過如下指令停止node1上的corosync服務,再檢視狀态
[root@node1 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:91:45:90
inet addr:192.168.18.201 Bcast:192.168.18.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe91:4590/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:375197 errors:0 dropped:0 overruns:0 frame:0
TX packets:291575 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:55551264 (52.9 MiB) TX bytes:52697225 (50.2 MiB)
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:91:45:90
inet addr:192.168.18.200 Bcast:192.168.18.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:6473 errors:0 dropped:0 overruns:0 frame:0
TX packets:6473 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:875395 (854.8 KiB) TX bytes:875395 (854.8 KiB)
測試,停止node1節點上的corosync,可以看到node1已經離線
[root@node2 ~]# ssh node1 "service corosync stop"
Signaling Corosync Cluster Engine (corosync) to terminate: [确定]
Waiting for corosync services to unload:..[确定]
[root@node2 ~]# crm status
Last updated: Thu Aug 15 14:29:04 2013
Current DC: node2.test.com - partition WITHOUT quorum
Online: [ node2.test.com ]
OFFLINE: [ node1.test.com ]
重點說明:上面的資訊顯示node1.test.com已經離線,但資源vip卻沒能在node2.test.com上啟動。這是因為此時的叢集狀态為"WITHOUT quorum"(紅色标記),即已經失去了quorum,此時叢集服務本身已經不滿足正常運作的條件,這對于隻有兩節點的叢集來講是不合理的。是以,我們可以通過如下的指令來修改忽略quorum不能滿足的叢集狀态檢查:property no-quorum-policy=ignore
crm(live)configure# property no-quorum-policy=ignore
primitive vip ocf:heartbeat:IPaddr \
params ip="192.168.18.200" nic="eth0" cidr_netmask="24"
stonith-enabled="false" \
no-quorum-policy="ignore"
crm(live)configure# commit
片刻之後,叢集就會在目前仍在運作中的節點node2上啟動此資源了,如下所示:
Last updated: Thu Aug 15 14:38:23 2013
Last change: Thu Aug 15 14:37:08 2013 via cibadmin on node2.test.com
Current DC: node2.test.com - partition WITHOUT quorum
OFFLINE: [ node1.test.com ]
vip (ocf::heartbeat:IPaddr): Started node2.test.com
好了,驗正完成後,我們正常啟動node1.test.com
[root@node2 ~]# ssh node1 "service corosync start"
Starting Corosync Cluster Engine (corosync): [确定]
Last updated: Thu Aug 15 14:39:45 2013
Current DC: node2.test.com - partition with quorum
vip (ocf::heartbeat:IPaddr): Started node2.test.com
[root@node2 ~]#