接上一篇的DRBD的系統(tǒng)環(huán)境及安裝配置繼續(xù)....
一、Hearbeat配置
1、安裝heartbeat
12 | # yum install epel-release -y# yum --enablerepo=epel install heartbeat -y |
2、設(shè)置heartbeat配置文件
(node1)
編輯ha.cf,添加下面配置:
12345678 | # vi /etc/ha.d/ha.cflogfile /var/log/ha-loglogfacility local0keepalive 2deadtime 5ucast eth0 192.168.0.192 # 指定對方網(wǎng)卡及IPauto_failback offnode drbd1.corp.com drbd2.corp.com |
(node2)
編輯ha.cf,添加下面配置:
12345678 | # vi /etc/ha.d/ha.cflogfile /var/log/ha-loglogfacility local0keepalive 2deadtime 5ucast eth0 192.168.0.191auto_failback offnode drbd1.corp.com drbd2.corp.com |
3、編輯雙機(jī)互聯(lián)驗證文件authkeys,添加以下內(nèi)容:(node1,node2)
123 | # vi /etc/ha.d/authkeysauth 11 crc |
給驗證文件600權(quán)限
1 | # chmod 600 /etc/ha.d/authkeys |
4、編輯集群資源文件:(node1,node2)
12 | # vi /etc/ha.d/haresourcesdrbd1.corp.com IPaddr::192.168.0.190/24/eth0 drbddisk::r0 Filesystem::/dev/drbd0::/store::ext4 killnfsd |
注:該文件內(nèi)IPaddr,Filesystem等腳本存放路徑在/etc/ha.d/resource.d/下,也可在該目錄下存放服務(wù)啟動腳本(例如:mysql,www),將相同腳本名稱添加到/etc/ha.d/haresources內(nèi)容中,從而跟隨heartbeat啟動而啟動該腳本。
IPaddr::192.168.0.190/24/eth0:用IPaddr腳本配置對外服務(wù)的浮動虛擬IP
drbddisk::r0:用drbddisk腳本實現(xiàn)DRBD主從節(jié)點資源組的掛載和卸載
Filesystem::/dev/drbd0::/store::ext4:用Filesystem腳本實現(xiàn)磁盤掛載和卸載
5、編輯腳本文件killnfsd,用來重啟NFS服務(wù):(node1,node2)
12 | # vi /etc/ha.d/resource.d/killnfsdkillall -9 nfsd; /etc/init.d/nfs restart;exit 0 |
賦予755執(zhí)行權(quán)限:
1 | # chmod 755 /etc/ha.d/resource.d/killnfsd |
二、創(chuàng)建DRBD腳本文件drbddisk:(node1,node2)
編輯drbddisk,添加下面的腳本內(nèi)容
1 | # vi /etc/ha.d/resource.d/drbddisk |
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 | #!/bin/bash## This script is inteded to be used as resource script by heartbeat## Copright 2003-2008 LINBIT Information Technologies# Philipp Reisner, Lars Ellenberg#### DEFAULTFILE="/etc/default/drbd"DRBDADM="/sbin/drbdadm" if [ -f $DEFAULTFILE ]; then . $DEFAULTFILEfi if [ "$#" -eq 2 ]; then RES="$1" CMD="$2"else RES="all" CMD="$1"fi ## EXIT CODES# since this is a "legacy heartbeat R1 resource agent" script,# exit codes actually do not matter that much as long as we conform to# http://wiki.linux-ha.org/HeartbeatResourceAgent# but it does not hurt to conform to lsb init-script exit codes,# where we can.# http://refspecs.linux-foundation.org/LSB_3.1.0/#LSB-Core-generic/LSB-Core-generic/iniscrptact.html#### drbd_set_role_from_proc_drbd(){local outif ! test -e /proc/drbd; thenROLE="Unconfigured"returnfi dev=$( $DRBDADM sh-dev $RES )minor=${dev#/dev/drbd}if [[ $minor = *[!0-9]* ]] ; then# sh-minor is only supported since drbd 8.3.1minor=$( $DRBDADM sh-minor $RES )fiif [[ -z $minor ]] || [[ $minor = *[!0-9]* ]] ; thenROLE=Unknownreturnfi if out=$(sed -ne "/^ *$minor: cs:/ { s/:/ /g; p; q; }" /proc/drbd); thenset -- $outROLE=${5%/**}: ${ROLE:=Unconfigured} # if it does not show upelseROLE=Unknownfi} case "$CMD" in start)# try several times, in case heartbeat deadtime# was smaller than drbd ping timetry=6while true; do$DRBDADM primary $RES && breaklet "--try" || exit 1 # LSB generic errorsleep 1done;; stop)# heartbeat (haresources mode) will retry failed stop# for a number of times in addition to this internal retry.try=3while true; do$DRBDADM secondary $RES && break# We used to lie here, and pretend success for anything != 11,# to avoid the reboot on failed stop recovery for "simple# config errors" and such. But that is incorrect.# Don't lie to your cluster manager.# And don't do config errors...let --try || exit 1 # LSB generic errorsleep 1done;; status)if [ "$RES" = "all" ]; then echo "A resource name is required for status inquiries." exit 10fiST=$( $DRBDADM role $RES )ROLE=${ST%/**}case $ROLE inPrimary|Secondary|Unconfigured)# expected;;*)# unexpected. whatever...# If we are unsure about the state of a resource, we need to# report it as possibly running, so heartbeat can, after failed# stop, do a recovery by reboot.# drbdsetup may fail for obscure reasons, e.g. if /var/lock/ is# suddenly readonly. So we retry by parsing /proc/drbd.drbd_set_role_from_proc_drbdesaccase $ROLE inPrimary)echo "running (Primary)"exit 0 # LSB status "service is OK";;Secondary|Unconfigured)echo "stopped ($ROLE)"exit 3 # LSB status "service is not running";;*)# NOTE the "running" in below message.# this is a "heartbeat" resource script,# the exit code is _ignored_.echo "cannot determine status, may be running ($ROLE)"exit 4 # LSB status "service status is unknown";;esac;; *)echo "Usage: drbddisk [resource] {start|stop|status}"exit 1;;esac exit 0 |
賦予755執(zhí)行權(quán)限:
1 | # chmod 755 /etc/ha.d/resource.d/drbddisk |
三、啟動HeartBeat服務(wù)
在兩個節(jié)點上啟動HeartBeat服務(wù),先啟動node1:(node1,node2)
12 | # service heartbeat start# chkconfig heartbeat on |
現(xiàn)在從其他機(jī)器能夠ping通虛IP 192.168.0.190,表示配置成功
四、配置NFS:(node1,node2)
編輯exports配置文件,添加以下配置:
12 | # vi /etc/exports/store *(rw,no_root_squash) |
重啟NFS服務(wù):
1234 | # service rpcbind restart# service nfs restart# chkconfig rpcbind on# chkconfig nfs off |
注:這里設(shè)置NFS開機(jī)不要自動運(yùn)行,因為/etc/ha.d/resource.d/killnfsd 該腳本會控制NFS的啟動。
五、測試高可用
1、正常熱備切換
在客戶端掛載NFS共享目錄
1 | # mount -t nfs 192.168.0.190:/store /tmp |
模擬將主節(jié)點node1 的heartbeat服務(wù)停止,則備節(jié)點node2會立即無縫接管;測試客戶端掛載的NFS共享讀寫正常。
此時備機(jī)node2上的DRBD狀態(tài):
123456 | # service drbd statusdrbd driver loaded OK; device status:version: 8.4.3 (api:1/proto:86-101)GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@drbd2.corp.com, 2015-05-12 21:05:41m:res cs ro ds p mounted fstype0:r0 Connected Primary/Secondary UpToDate/UpToDate C /store ext4 |
2、異常宕機(jī)切換
強(qiáng)制關(guān)機(jī),直接關(guān)閉node1電源
node2節(jié)點也會立即無縫接管,測試客戶端掛載的NFS共享讀寫正常。
此時node2上的DRBD狀態(tài):
123456 | # service drbd statusdrbd driver loaded OK; device status:version: 8.4.3 (api:1/proto:86-101)GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@drbd2.corp.com, 2015-05-12 21:05:41m:res cs ro ds p mounted fstype0:r0 Connected Primary/Unknown UpToDate/DUnknown C /store ext4 |
原文鏈接:CentOS6.5下DRBD+HeartBeat+NFS配置(二),轉(zhuǎn)載請注明來源!
聯(lián)系客服