在RHEL5下配置安裝Heartbeat+drbd+pacemaker做雙機熱備
在RHEL5下配置安裝Heartbeat+drbd+pacemaker做雙機熱備
前言:近期在做雙機熱備實驗,其間並不順利,幾乎每一步都遇到這樣那樣問題。由於內核支持問題導致drbd.ko編譯不成功,
由於編譯選項導致路徑問題,由於防火牆導致HA split brain,由於內核iptables模塊選項問題導致IPaddr2資源clone失敗等等。
相信也有不少朋友在這些方面被困擾過,因此整理一下分享出來。
實驗目的:雙機熱備,支持服務:httpd、postgresql(註:出於簡潔目的postgresql部分配置本文未貼出來)
環境:
操作系統:Red Hat Enterprise Linux Server release 5.2 (Tikanga)
內核版本:2.6.32.41
虛擬機:VMware Workstation 7.0.0 build-203739
磁碟:系統盤/dev/hda,數據盤/dev/hdb
分區情況:系統分區/dev/hda1,交換分區/dev/hda2,drbd資源分區/dev/hdb1 /dev/hdb2
節點1:ha1 192.168.1.130
節點2:ha2 192.168.1.131
集群IP:192.168.1.132
軟體準備:
//Heartbeat依賴此軟體提供的靜態庫:libnet.a
libnet-1.1.2.1.tar.gz
//heartbeat套件:
Heartbeat-3-0-STABLE-3.0.4.tar.bz2
ClusterLabs-resource-agents-agents-1.0.4-0-gc06b6f3.tar.gz
Pacemaker-1-0-db98485d06ed.tar.bz2
Reusable-Cluster-Components-glue--glue-1.0.7.tar.bz2
//drbd:提供磁碟網路同步
drbd-8.4.0.tar.gz
註:本文檔以符號//為註釋說明,在配置文件或腳本中請刪除掉或用相應註釋符號如#
安裝前準備:
內核需要重新編譯,主要是編譯內核模塊drbd.ko依賴問題。
CONFIG_SYSFS_DEPRECATED=y //解決從2.6.18-92.el5升級到2.6.32.41時,提示:mount: could not find filesystem 『/dev/root』
位置: General setup ---> enable deprecated sysfs features which may confuse old userspace tools
CRYPTO_CRC32C=y //解決載入模塊drbd.ko報錯:未解析的符號:crc32c
位置:-*- Cryptographic API ---> -*- CRC32c CRC algorithm
CONFIG_CONNECTOR=y //解決LD鏈接報錯:connector.o文件沒有找到!
位置:Device Drivers ---> Generic Driver Options ---> <*> Connector - unified userspace <-> kernelspace link
註:上面的選項如果不知道位置可以在內核配置界面按鍵:/ 來查找內容。
File systems --->
如果需要支持負載均衡,那麼需要新的文件系統支持:GFS2或OCFS2(註:drbd雙主模式在RHEL5上沒有測試成功,主要是沒有支持dlm-pcmk、gfs-pcmk等模塊)
GFS2依賴選項(iptables的ClusterIP功能也依賴它):General setup ---> Prompt for development and/or incomplete code/drivers
-*- Networking support --->
如果需要支持負載均衡,那麼這塊內容需要仔細配置了,否則clone IP資源是無法成功啟動的,這個地方我是經歷了N次失敗,
最後查看了日誌文件:/var/log/messagest和ocf腳本/usr/lib/ocf/resource.d/heartbeat/IPaddr2才發現問題出在iptables缺少模塊支持!
建議:<>項設定成模塊,[]項則編譯到內核。也就是:
方式設定所有 Networking options 下的選項。
編譯簡要說明:
make bzImage && make modules && make modules_install && make install
drbd內核模塊是單獨編譯安裝的,安裝路徑:/lib/modules/2.6.32.41/updates/drbd.ko
等drbd編譯並安裝后就可以打包這些模塊,拷貝到節點上了。
打包命令:
tar czvf kerne_l2.6.32.41_package.tar.gz /boot/""{System.map,System.map-2.6.32.41,vmlinuz-2.6.32.41,vmlinuz,initrd-2.6.32.41.img} /boot/grub/grub.conf /lib/firmware/ /lib/modules/2.6.32.41/
安裝打包文件到節點:上傳打包文件到目的節點上
tar -C / --overwrite -xzf kerne_l2.6.32.41_package.tar.gz
安裝部分:
這裡假定以root身份登錄到系統,軟體目錄在,/root/ha/
節點ha1:
cd /root/ha
解壓源文件:
tar xjf Heartbeat-3-0-STABLE-3.0.4.tar.bz2
tar xjf Pacemaker-1-0-db98485d06ed.tar.bz2
tar xjf Reusable-Cluster-Components-glue--glue-1.0.7.tar.bz2
tar xzf ClusterLabs-resource-agents-agents-1.0.4-0-gc06b6f3.tar.gz
tar xzf drbd-8.4.0.tar.gz
tar xzf libnet-1.1.2.1.tar.gz
由於編譯時會調用/usr/bin/xsltproc通過網路獲取doc,因此耗時且麻煩(不能忍受的慢,一個項目就要數小時)。因此想了個辦法阻止:
mv /usr/bin/xsltproc /usr/bin/xsltproc.bak
echo -e '#!/bin/sh \n exit 0' > /usr/bin/xsltproc
chmod +x /usr/bin/xsltproc
如果需要完整安裝,則不要替換此程序,同時需要配置預設路由和DNS伺服器:
route add default gw 192.168.1.1
vim /etc/resolv.conf 添加行:nameserver 202.98.96.68 //當然也可以添加其他dns伺服器地址
cd libnet
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
make && make install
打包到dst目錄:
mkdir dst
make DESTDIR=$PWD/dst install
cd Reusable-Cluster-Components-glue--glue-1.0.7
./autogen.sh
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
make && make -i install //注意這裡添加了-i 選項,由於替換了/usr/bin/xsltproc為一個空腳本(不想聯網取文檔!),不加-i將會退出安裝。
打包到dst目錄:
mkdir dst
make -i DESTDIR=$PWD/dst install
cd ClusterLabs-resource-agents-c06b6f3
./autogen.sh
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
make && make -i install
ocf-shellfuncs路徑問題:
ocf腳本依賴此腳本,有些腳本尋找路徑為:/usr/lib/ocf/resource.d/heartbeat/ocf-shellfuncs
而有些尋找路徑為:/usr/lib/ocf/resource.d/heartbeat/.ocf-shellfuncs
但其真實路徑卻是:/usr/lib/ocf/lib/heartbeat/ocf-shellfuncs
解決辦法:添加軟鏈接到腳本依賴的路徑:其他3個文件同樣處理:ocf-binaries ocf-directories ocf-returncodes
ln -s /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs /usr/lib/ocf/resource.d/heartbeat/.ocf-shellfuncs
ln -s /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs /usr/lib/ocf/resource.d/heartbeat/ocf-shellfuncs
ln -s /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs /usr/lib/ocf/resource.d/heartbeat/.ocf-binaries
ln -s /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs /usr/lib/ocf/resource.d/heartbeat/ocf-binaries
ln -s /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs /usr/lib/ocf/resource.d/heartbeat/.ocf-directories
ln -s /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs /usr/lib/ocf/resource.d/heartbeat/ocf-directories
ln -s /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs /usr/lib/ocf/resource.d/heartbeat/.ocf-returncodes
ln -s /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs /usr/lib/ocf/resource.d/heartbeat/ocf-returncodes
打包到dst目錄:
mkdir dst
make -i DESTDIR=$PWD/dst install
修改打包文件路徑問題:
cd dst/usr/lib/ocf/lib/heartbeat/
ln -s /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs .ocf-shellfuncs
ln -s /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs ocf-shellfuncs
ln -s /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs .ocf-binaries
ln -s /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs ocf-binaries
ln -s /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs .ocf-directories
ln -s /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs ocf-directories
ln -s /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs .ocf-returncodes
ln -s /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs ocf-returncodes
cd Heartbeat-3-0-STABLE-3.0.4
./bootstrap
./configure --help
重要: 需要添加用戶及組啟動服務
groupadd -g 60 haclient
useradd -u 17 -g haclient hacluster
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --with-group-id=60 --with-ccmuser-id=17
make && make -i install
打包到dst目錄:
mkdir dst
make -i DESTDIR=$PWD/dst install
cd Pacemaker-1-0-db98485d06ed
./autogen.sh
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --with-heartbeat
make && make -i install
打包到dst目錄:
mkdir dst
make -i DESTDIR=$PWD/dst install
drbd編譯部分:
drbd編譯分為兩個部分,內核模塊編譯和用戶工具編譯。
首先編譯內核模塊:
cd cd drbd-8.4.0
./configure --with-km
編譯報錯:
提示drbd/drbd_receiver.c的drbd_do_auth中mdev沒有定義,出錯行如下:
#if !defined(CONFIG_CRYPTO_HMAC) && !defined(CONFIG_CRYPTO_HMAC_MODULE)
STATIC int drbd_do_auth(struct drbd_tconn *tconn)
{
dev_err(DEV, "This kernel was build without CONFIG_CRYPTO_HMAC.\n");
dev_err(DEV, "You need to disable 'cram-hmac-alg' in drbd.conf.\n");
return -1;
}
#else
#define CHALLENGE_LEN 64
代碼中就只有調用了dev_err,內有宏定義DEV
估計就是DEV定義問題,查看了內核中相關頭文件定義:
#define DEV mdev
看不出問題原因,只好將這兩行調用全部註釋了,好在僅是輸出消息日誌,估計並無大礙。
make && make install
如果成功模塊將安裝在:/lib/modules/2.6.32.41/updates/drbd.ko
modprobe -v drbd //如果沒有出錯消息,恭喜你安裝OK
用戶工具編譯:
make clean
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --with-utils --with-pacemaker --with-heartbeat
make && make -i install
打包到dst目錄:
mkdir dst
make -i DESTDIR=$PWD/dst install
節點ha2上重複是面安裝步驟。也可以將打包目錄中的安裝文件tar出直接解壓到節點上,節省編譯時間。
至此安裝部分完成,接下來是配置部分。 《解決方案》
本帖最後由 rwx_hc 於 2011-08-29 12:35 編輯
-----------------------------------------------------
配置部分1:heartbeat
-----------------------------------------------------
節點ha1:
主機解析配置:
vim /etc/hosts //添加下面行:
192.168.1.130 ha1
192.168.1.131 ha2
vim /etc/sysconfig/network //修改下面行
HOSTNAME=ha1
//指令方式修改主機名,否則主機名生效需要重啟系統
#hostname ha1
//節點ha2上做相應配置
編輯heartbeat配置文件:詳細參數設置可以參考文檔例子:/usr/share/doc/ha.cf
vim /etc/ha.d/ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
#mcast eth0 225.0.0.0 694 1 0
#ha1
ucast eth0 192.168.1.131
#ha2
#ucast eth0 192.168.1.130
auto_failback on
node ha1
node ha2
ping 192.168.1.2
#ping_group group1 192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4 192.168.1.5
pacemaker respawn
為HeartBeat創建key文件:簽名演演算法可以是md5 sha1 crc crc32c,這裡採用sha1,節點ha2上需要拷貝這個key文件,
兩邊的key文件必須相同!
(echo -ne "auth 1\n1 sha1 ";dd if=/dev/urandom bs=512 count=1 | openssl sha1 ) > /etc/ha.d/authkeys
chmod 600 /etc/ha.d/authkeys
拷貝到節點ha2上:
scp /etc/ha.d/authkeys root@ha2:/etc/ha.d/authkeys
scp /etc/ha.d/ha.cf root@ha2:/etc/ha.d/ha.cf
ha2上:修改ha.cf:兩個節點僅此行配置是不同的,因為需要配置的是對方的IP地址,如果有兩個以上節點則需要組播地址!
#ucast eth0 192.168.1.131
ucast eth0 192.168.1.130
重要:防火牆設置:setup --> Firewall configuration
Security Level: ( ) Enabled (*) Disabled SELinux: Disabled
或者定製:需要開放埠:UDP 694
定製選項中設置:Other ports ha-cluster:udp
直接修改配置文件:
節點ha1和ha2上:
將heartbeat服務設置為開機啟動
chkconfig --level 3 heartbeat on
啟動服務
service heartbeat start
注意查看信息提示和日誌:/var/log/ha-log
如果工作不正常,日誌是很重要的參考信息。
狀態查看:
crm_mon -1
或
crm status
輸出應如下:
crm status
============
Last updated: Fri Aug 26 19:42:31 2011
Stack: Heartbeat
Current DC: ha2 (eec53f08-e761-461c-9bc3-9520159451f2) - partition with quorum
Version: 1.0.11-db98485d06ed3fe0fe236509f023e1bd4a5566f1
2 Nodes configured, unknown expected votes
============
Online: [ ha1 ha2 ]
pacemaker控制文件: /var/lib/heartbeat/crm/cib.xml 《解決方案》
本帖最後由 rwx_hc 於 2011-08-29 12:37 編輯
------------------------------------------------
配置部分2:drbd
------------------------------------------------
準備:硬碟為/dev/hdb,分區為/dev/hdb1,hdb上應預留一些空間來保存drbd數據。
也就是說/dev/hdb分區時應保留最後一些柱面不使用。(查看官方文檔發現使用meta-disk internal需要預留磁碟空間在末端!!)。
計算公式為:disk.MB / 32768 + 1
如果一個G,佔用1.03M
1個T,佔用:31.5M
2個T,佔用:62M
配置文件,這個採用預設即可,無需再配置。
# cat /etc/drbd.conf
# You can find an example in /usr/share/doc/drbd.../drbd.conf.example
include "drbd.d/global_common.conf";
include "drbd.d/*.res";
全局資源文件:
#cat /etc/drbd.d/global_common.conf
global {
usage-count yes;
}
common {
handlers {
pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";
# fence-peer "/usr/lib/drbd/crm-fence-peer.sh";
# split-brain "/usr/lib/drbd/notify-split-brain.sh root";
# out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root";
# before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh -p 15 -- -c 16k";
# after-resync-target /usr/lib/drbd/unsnapshot-resync-target-lvm.sh;
}
startup {
# wfc-timeout degr-wfc-timeout outdated-wfc-timeout wait-after-sb
}
options {
# cpu-mask on-no-data-accessible
}
disk {
# size max-bio-bvecs on-io-error fencing disk-barrier disk-flushes
# disk-drain md-flushes resync-rate resync-after al-extents
# c-plan-ahead c-delay-target c-fill-target c-max-rate
# c-min-rate disk-timeout
}
net {
protocol C;
# protocol timeout max-epoch-size max-buffers unplug-watermark
# connect-int ping-int sndbuf-size rcvbuf-size ko-count
# allow-two-primaries cram-hmac-alg shared-secret after-sb-0pri
# after-sb-1pri after-sb-2pri always-asbp rr-conflict
# ping-timeout data-integrity-alg tcp-cork on-congestion
# congestion-fill congestion-extents csums-alg verify-alg
# use-rle
}
}
資源文件:/etc/drbd.d/*.res //後綴名為res
# cat r0.res
resource r0 {
handlers {
split-brain "/usr/lib/drbd/notify-split-brain.sh root";
}
net {
after-sb-0pri discard-zero-changes;
after-sb-1pri discard-secondary;
after-sb-2pri disconnect;
}
disk {
on-io-error detach;
disk-flushes no;
md-flushes no;
}
volume 0 {
device /dev/drbd1;
disk /dev/hdb1;
meta-disk internal;
}
on ha1 {
address 192.168.1.130:7789;
}
on ha2 {
address 192.168.1.131:7789;
}
}
創建drbd分區:
清除原殘存的文件系統信息:
dd if=/dev/zero bs=1M count=1 of=/dev/hdb1
drbdadm create-md r0
載入內核模塊:
modprobe drbd
啟動資源:
drbdadm up r0
兩個節點同樣配置處理。
查看:
cat /proc/drbd
version: 8.4.0 (api:1/proto:86-100)
GIT-hash: 28753f559ab51b549d16bcf487fe625d5919c49c build by root@AS5-build, 2011-08-10 12:43:25
1: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r-----
ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:977028
設備初始化同步,選定ha1做為源
在ha1上:
drbdadm primary --force r0
或下面命令,推薦用下面命令:
drbdadm -- --overwrite-data-of-peer primary r0
另一節點ha2上會自動同步ha1上的數據!
ha1已成為主設備,可以使用了:
mkfs.xfs /dev/drbd1
mount /dev/drbd1 /mnt
umount /dev/drbd1
註:單主模式下某一時刻僅在主設備上,drbd盤才可以mount使用!
使用crm配置drbd在下面部分介紹。 《解決方案》
--------------------------------------------
配置部分3:使用crm命令行工具
--------------------------------------------
crm提供非交互和互動式兩種界面給用戶,在互動式界面如果按TAB鍵會有幫助提示和命令補全,
這一點和cisco提供的界面很類似!
查看配置:
#crm
#crm(live)#configure
crm(live)configure# show
node $id="76b083b0-ba70-458b-b47a-5a54d9fedd15" ha1
node $id="eec53f08-e761-461c-9bc3-9520159451f2" ha2
property $id="cib-bootstrap-options" \
dc-version="1.0.11-db98485d06ed3fe0fe236509f023e1bd4a5566f1" \
cluster-infrastructure="Heartbeat"
驗證配置是否OK:
crm(live)configure# verify
crm_verify: 2011/08/20_13:16:39 ERROR: unpack_resources: Resource start-up disabled since no STONITH resources have been defined
crm_verify: 2011/08/20_13:16:39 ERROR: unpack_resources: Either configure some or disable STONITH with the stonith-enabled option
crm_verify: 2011/08/20_13:16:39 ERROR: unpack_resources: NOTE: Clusters with shared data need STONITH to ensure data integrity
Errors found during check: config not valid
禁用stonith:
crm configure property stonith-enabled=false
當然也可以是:
crm(live)configure# property stonith-enabled=false
crm(live)configure#commit
禁用節點合法人數檢查://兩個節點必須配置此項為ignore,否則一個節點down了,集群也就不工作了。
crm configure property no-quorum-policy=ignore
資源粘滯設置,防止資源在節點中移動,當一個資源在提供服務時,盡量留在當前節點上。
如果不設置:首先資源運行在node1上,如果node1失效,資源將移至node2,之後node1恢復,資源將重新回到node1上運行,
這樣將導致資源頻繁切換,大多數情況這並不是我們想要的結果。
crm configure rsc_defaults resource-stickiness=100
配置第一個資源,集群IP(共享IP:192.168.1.132)
crm configure
crm(live)configure#primitive ip-cluster ocf:heartbeat:IPaddr2 \
params ip="192.168.1.132" clusterip_hash="sourceip-sourceport" \
op monitor interval="60"
crm中如何修改資源配置://在configure模式下輸入命令edit或edit 資源ID
修改整個配置:
crm(live)configure#edit
只修改資源ip-cluster:
crm(live)configure#edit ip-cluster
預設編輯工具是vim,編輯完成就保存退出即可。
驗證后提交修改:
crm(live)configure# verify
crm(live)configure#commit
查看:資源clusterIP在ha2上啟動
crm(live)#status
Online: [ ha1 ha2 ]
ip-cluster (ocf::heartbeat:IPaddr2): Started ha2
設置資源ip-cluster在某個節點上優先運行:這裡假定希望ha1優先
crm(live)configure# location location-1 ip-cluster 100: ha1
crm(live)configure#commit
crm(live)node#standby ha1
crm(live)node#standby ha2
crm(live)node#online ha1
crm(live)node#online ha2
查看:資源ip-cluster優先在ha1上啟動了!
crm(live)#status
Online: [ ha1 ha2 ]
ip-cluster (ocf::heartbeat:IPaddr2): Started ha1
準備httpd:
系統現狀:預設已安裝Apache服務,配置文件:/etc/httpd/conf/httpd.conf
服務啟動腳本:/etc/init.d/httpd
加入一個頁面:vim /var/www/html/index.html
內容如下:
My Test Site - ha1
另一節點:vim /var/www/html/index.html
My Test Site - ha2
修改httpd配置文件:
vim /etc/httpd/conf/httpd.conf
取消對下面行的註釋://source agent會使用server-status URL來查看服務狀態。
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
測試httpd服務:
# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.1.130 for ServerName
vim /etc/httpd/conf/httpd.conf
找到行:#ServerName www.example.com:80
修改為:ServerName 192.168.1.130:80
重啟服務OK!
資源配置:
crm(live)configure#primitive srv-apache ocf:heartbeat:apache \
params configfile="/etc/httpd/conf/httpd.conf" \
op monitor interval="60" \
op start interval="0" timeout="40" \
op stop interval="0" timeout="60"
crm(live)configure#commit
查看當前集群運行狀態:兩個資源分別運行在不同節點上,heartbeat預設會平均分配資源到不同節點!
crm(live)# status
============
Last updated: Fri Aug 26 20:14:24 2011
Stack: Heartbeat
Current DC: ha2 (eec53f08-e761-461c-9bc3-9520159451f2) - partition with quorum
Version: 1.0.11-db98485d06ed3fe0fe236509f023e1bd4a5566f1
2 Nodes configured, unknown expected votes
2 Resources configured.
============
Online: [ ha1 ha2 ]
ip-cluster (ocf::heartbeat:IPaddr2): Started ha1
srv-apache (ocf::heartbeat:apache): Started ha2
配置兩個資源在同一節點上運行:特別是兩個資源互相依賴時更是需要如此!
crm(live)configure#colocation colocation-1 inf: ip-cluster srv-apache
crm(live)configure# commit
查看:兩個資源已在同一節點上運行!
crm(live)#status
Online: [ ha1 ha2 ]
ip-cluster (ocf::heartbeat:IPaddr2): Started ha1
srv-apache (ocf::heartbeat:apache): Started ha1
配置資源啟動順序:如果資源web依賴資源ip-cluster則可以如下配置,保證ip-cluster先於web啟動。
crm(live)configure# order order-1 inf: ip-cluster srv-apache
crm(live)configure# commit
重置資源失敗記數:
當資源失敗時,手工管理資源,否則集群不會自動重啟資源:
crm(live)resource# failcount srv-apache show ha1
scope=status name=fail-count-srv-apache value=INFINITY
crm(live)resource# failcount srv-apache show ha2
scope=status name=fail-count-web value=INFINITY
失敗計數已被設置為無窮大,資源永遠不會再起來了!
crm(live)resource# failcount srv-apache set ha1 0
crm(live)resource# failcount srv-apache set ha2 0
crm status命令中出現失敗信息:
Failed actions:
srv-apache_monitor_60000 (node=ha2, call=34, rc=7, status=complete): not running
srv-apache_start_0 (node=ha2, call=36, rc=5, status=complete): not installed
清除信息命令如下:
crm(live)resource# cleanup srv-apache ha1
crm(live)resource# cleanup srv-apache ha2
或
crm(live)resource# cleanup srv-apache
crm中配置drbd主從資源:
crm(live)configure#primitive drbd-apache ocf:linbit:drbd \
params drbd_resource="r0" \
op monitor interval="60" role="Master" timeout="10" \
op monitor interval="60" role="Slave" timeout="20" \
op start interval="0" timeout="240" \
op stop interval="0" timeout="100"
crm(live)configure#ms ms-drbd-apache drbd-apache \
meta clone-max="2" clone-node-max="1" master-max="1" master-node-max="1" notify="yes" globally-unique="false" target-role="Started"
配置文件系統資源:
crm(live)configure#primitive fs-apache ocf:heartbeat:Filesystem \
params fstype="ext3" directory="/var/www/html" device="/dev/drbd1" \
op monitor interval="10" timeout="40" \
op start interval="0" timeout="60" \
op stop interval="0" timeout="60"
配置資源組:當配置成資源組時,這些資源就最好以組的面目出現了,否則可能出現死鎖情況。
個人經驗:一個組中的資源最好不要有啟動順序依賴關係,組的作用僅是管理上的方便。
crm(live)configure#group group-apache ip-cluster srv-apache
這一步操作后,crm會自動調整和這個組資源group-apache相關的配置,但其調整並不是很完美,
還需要手工編輯:
crm(live)configure#edit
編輯完成結果如下:
crm(live)configure#show
node $id="76b083b0-ba70-458b-b47a-5a54d9fedd15" ha1 \
attributes standby="off"
node $id="eec53f08-e761-461c-9bc3-9520159451f2" ha2 \
attributes standby="off"
primitive drbd-apache ocf:linbit:drbd \
params drbd_resource="r0" \
op monitor interval="60" role="Master" timeout="10" \
op monitor interval="60" role="Slave" timeout="20" \
op start interval="0" timeout="240" \
op stop interval="0" timeout="100"
primitive fs-apache ocf:heartbeat:Filesystem \
params fstype="xfs" directory="/var/www/html" device="/dev/drbd1" \
op monitor interval="10" timeout="40" \
op start interval="0" timeout="60" \
op stop interval="0" timeout="60"
primitive ip-cluster ocf:heartbeat:IPaddr2 \
params ip="192.168.1.132" clusterip_hash="sourceip-sourceport" \
op monitor interval="60"
primitive srv-apache ocf:heartbeat:apache \
params configfile="/etc/httpd/conf/httpd.conf" \
op monitor interval="60" \
op start interval="0" timeout="40" \
op stop interval="0" timeout="60"
group group-apache ip-cluster srv-apache
ms ms-drbd-apache drbd-apache \
meta clone-max="2" clone-node-max="1" master-max="1" master-node-max="1" notify="yes" globally-unique="false" target-role="Started"
location location-1 group-apache 100: ha1
colocation colocation-1 inf: fs-apache ms-drbd-apache:Master group-apache
order order-1 inf: ms-drbd-apache:promote fs-apache:start group-apache:start
property $id="cib-bootstrap-options" \
stonith-enabled="false" \
no-quorum-policy="ignore" \
dc-version="1.0.11-db98485d06ed3fe0fe236509f023e1bd4a5566f1" \
cluster-infrastructure="Heartbeat" \
last-lrm-refresh="1314397927"
最後查看下集群工作狀態:
crm(live)#status
Online: [ ha1 ha2 ]
fs-apache (ocf::heartbeat:Filesystem): Started ha1
Master/Slave Set: ms-drbd-apache
Masters: [ ha1 ]
Slaves: [ ha2 ]
Resource Group: group-apache
ip-cluster (ocf::heartbeat:IPaddr2): Started ha1
srv-apache (ocf::heartbeat:apache): Started ha1 《解決方案》
-----------------------------------------------------------------------------
其他:
-----------------------------------------------------------------------------
如何查看資源參數設定:
查看資源所有分類:
# crm ra
crm(live)ra# classes
heartbeat
lsb
ocf / heartbeat linbit pacemaker
stonith
查看資源apache:
crm(live)ra# meta apache
or
crm(live)ra# info apache
or
crm(live)ra# info ocf:heartbeat:apache
查看類heartbeat支持的資源:
crm(live)ra# list heartbeat
AudibleAlarm Delay Filesystem ICP IPaddr
IPaddr2 IPsrcaddr IPv6addr LVM LinuxSCSI
MailTo OCF Raid1 SendArp ServeRAID
WAS WinPopup Xinetd apache db2
drbddisk drbdupper hto-mapfuncs ids ldirectord
portblock
在線幫助是非常有用的:
比如查看如何使用命令list:
crm(live)ra# help list
crm(live)ra# help list
List available resource agents for the given class. If the class
is `ocf`, supply a provider to get agents which are available
only from that provider.
Usage:
...............
list []
...............
Example:
...............
list ocf pacemaker
...............
命令行下查看資源解析:
比如某個資源配置不成功,提示解析錯誤時,你可以通過下面命令驗證:例子apache資源解析:
# lrmadmin -M ocf apache heartbeat
如果成功會有該資源的詳細信息輸出,從中可以查看參數配置詳情。如果不成功則要找原因了,
多數情況是依賴路徑有問題!
命令行下查看資源在節點得分情況:查看這個輸出可以發現哪些資源因失敗而被設置為負無窮大而不能起來。
# ptest -sL
查看集群工作狀態:
# crm_mon -1
or
# crm status
查看drbd工作狀態:
# drbd-overview
or
# cat /proc/drbd
參考文檔:
http://www.linux-ha.org/doc/users-guide/users-guide.html
http://www.drbd.org/users-guide-emb/p-intro.html
http://www.clusterlabs.org/doc/zh-CN/Pacemaker/1.1/pdf/Clusters_from_Scratch/Pacemaker-1.1-Clusters_from_Scratch-zh-CN.pdf