標籤:ha corosync pacemaker heartbeat 高可用 雙機叢集
OS: RHEL 6.5 64bit
corosync: 1.4.7 --yum方式安裝
pacemaker: 1.1.2 --作為corosync依賴包自動安裝
pacemaker是heartbeat發展到3.0獨立出來的產物,紅帽6.0系列上,使用yum安裝corosync,預設會安裝pacemaker作為CRM。
pacemaker常用組態工具:crmsh pcs
crmsh需要獨立安裝rpm包
主要設定檔:
/etc/corosync/corosync.conf/etc/crm/crm.conf
實驗主機:A B
資源 RA提供方(crm->ra->classes;crm->ra->info XXX)webip ocf:heartbeat:Ipaddr2webfs ocf:heartbeat:Filesystemwebdb lsb:mysqldapache ocf:heartbeat:apache(params比較多)
定義資源:
crm->configure->group/primitive
primitive apache ocf:heartbeat:apache params configfile="/usr/local/apache2/conf/httpd.conf" httpd="/usr/local/apache2/bin/httpd" port="80" statusurl="http://127.0.0.1/server-status" op monitor timeout=20s interval=10s op start timeout=40s op stop timeout=60s op status timeout=30s
定義約束:
crm->configure->colocation/order/其他
order start_order Mandatory: webfs:start webdb:start apache:start關鍵字 ID kind或者分數:[資源ID:選項]..
展示配置:
crm->configure->show/show xml
編輯設定檔:
crm->configure->edit
註:配置完成請先執行verify命令,再執行commit
standby/online:
crm->node->standby [node名,預設為本地節點] /online
監控:
crm->status
crm_mon
重要的地方:
1.請在一台主機上啟動和停止本地和其他節點(ssh互信方式)的corosync服務!否則有可能出現腦裂的情況。(在實驗中,在A節點進行先啟後停corosync服務再啟操作後,出現了與B節點資源爭用的情況;而在B節點上通過SSH啟動A節點服務,則沒有出現資源爭用,原因不明。)
2.雙機情況下應配置票數不足時叢集策略,如:
crm->configure->property no-quorum-policy=ignore
否則資源將無法切換
有趣的地方:
本次實驗中,我使用了共用檔案系統/share下的目錄www作為web伺服器虛擬位址的DocumentRoot:
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "/share/www/" ServerName www.test.kc ServerAlias test.kc ErrorLog "logs/test.kc-error_log" CustomLog "logs/test.kc-access_log" common</VirtualHost>
在實驗過程對主機伺服器多次啟停的操作過程中,多次出現了資源apache無法正常啟動,並標註為unmanaged,而其他資源能夠成功切換的情況:
Online: [ ha-test1 ha-test2 ]webip (ocf::heartbeat:IPaddr2): Started ha-test2webfs (ocf::heartbeat:Filesystem): Started ha-test2webdb (lsb:mysqld): Started ha-test2apache (lsb:apache2): FAILED ha-test1 (unmanaged)Failed actions: apache_stop_0 on ha-test1 ‘unknown error‘ (1): call=611, status=complete, last-rc-change=‘Sun Jan 1 17:51:51 2017‘, queued=0ms, exec=51ms apache_stop_0 on ha-test1 ‘unknown error‘ (1): call=611, status=complete, last-rc-change=‘Sun Jan 1 17:51:51 2017‘, queued=0ms, exec=51ms
接下來怎麼做呢?
首先執行service corosync stop,會一直提示unload,猜想原因是因為共用檔案系統掛載在A節點,而apache服務運行在B節點,B節點上執行apache服務的stop操作,會因為找不到設定檔中配置的共用檔案儲存體路徑而報錯,無法完成stop操作:
Syntax error on line 66 of /usr/local/apache2/conf/httpd.conf:DocumentRoot must be a directory
於是我只能想到用殺進程的方式來強制停止corosync了:
ps -ef | grep corosync | grep -v grep |awk ‘{print $2}‘ | xargs kill -9
後來我一想,既然找不到該路徑,導致關不掉apache,那我給他mkdir一個本地的目錄讓他找好了,在A/B主機上執行:
mkdir /share/www
再次啟動雙機的corosync服務時,多次啟停操作,apache資源都成功切過去了,再沒有出現上面的情況。
不知道算不算解決了問題,歡迎指正。
corosync+pacemaker實驗記錄