實驗環境:
admin1.tuchao.com 192.168.18.100 ansible管理節點
admin2.tuchao.com 192.168.18.101 叢集節點一
admin3.tuchao.com 192.168.18.199 叢集節點二
安裝: yum install corosync pacemaker -y
複制配置檔案
cp corosync.conf.example corosync.conf
vim corosync.conf
編輯配置檔案:
compatibility: whitetank
是否相容0.8版本的corosync
totem {
定義叢集之間心跳資訊傳遞層
version: 2 ----版本号
secauth: on ---是否啟用安全認證
threads: 0 ---啟用多少個線程處理心跳資訊傳遞,0為自動。
interface {
ringnumber: 0 --封包循環次數
bindnetaddr: 192.168.18.0 --綁定的網絡位址
mcastaddr: 226.94.1.2 --多點傳播位址
mcastport: 5405 ---多點傳播端口
ttl: 1
}
}
logging {
fileline: off
to_stderr: no --心跳資訊是否輸出到螢幕
to_logfile: yes
to_syslog: no ---是否發送給/var/log/messages
logfile: /var/log/cluster/corosync.log
debug: off --是否開啟調試
timestamp: on --是否開啟目前系統時間的時間戳。
logger_subsys {
subsys: AMF --定義openais規範
debug: off
amf {
mode: disabled
service { 定義pacemaker為corosync的插件。
ver: 0
name: pacemaker
aisexec {
user:root
group:root
生成安全認證檔案,這個指令需要取1024位随機數,我們可以另起一個終端重裝一個軟體來産生随機數。
corosync-keygen
安裝資料總管的配置接口程式:
crmsh-1.2.6-4.el6.i686.rpm
pssh-2.3.1-2.el6.i686.rpm
關閉NetworkManager,并開機禁用此服務。
/etc/init.d/NetworkManager stop
chkconfig NetworkManager off
啟動服務:
service corosync start
CRM指令的使用:
crm status //顯示叢集狀态資訊
crm_mon
crm_verify -L //顯示配置檔案是否有文法錯誤
crm 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 resource help
At this level resources may be managed.
All (or almost all) commands are implemented with the CRM tools
such as `crm_resource(8)`.
status,show,list show status of resources --顯示資源狀态資訊
start start a resource --啟動一個資源
stop stop a resource --停止一個資源
restart restart a resource
promote promote a master-slave resource --喚醒一個主從資源
demote demote a master-slave resource --降級一個主從資源
manage put a resource into managed mode --将資源加入可管理模式
unmanage put a resource into unmanaged mode --非管理模式
migrate,move migrate a resource to another node --資源遷移
unmigrate,unmove unmigrate a resource to another node
param manage a parameter of a resource --管理資源參數
secret manage sensitive parameters --管理敏感參數
meta manage a meta attribute --管理資源的源資料屬性
utilization manage a utilization attribute
failcount manage failcounts --管理資源的錯誤次數
cleanup cleanup resource status --清除資源狀态
refresh refresh CIB from the LRM status --重新整理Cib
reprobe probe for resources not started by the CRM 探測沒有啟動的資源
trace start RA tracing
untrace stop RA tracing
end,cd,up go back one level
quit,bye,exit exit the program
crm node help
Node management and status commands.
status show nodes' status as XML --顯示節點狀态
show,list show node
standby put node into standby --設定目前節點為備用節點
online set node online --設定目前節點為線上節點
maintenance put node into maintenance mode
ready put node into ready mode
fence fence node
clearstate Clear node state
delete delete node
attribute manage attributes
utilization manage utilization attributes
status-attr manage status attributes
help,? show help (help topics for list of topics)
end,cd,up go back one level
quit,bye,exit exit the program
crm configure property stonith-enabled=false --關閉stonith裝置
crm ra help
classes list classes and providers --列出提供的RA類型
list list RA for a class (and provider) --顯示某個RA類型所提供的資源代理
meta show meta data for a RA --顯示一個RA的基本資訊
定義一個IP資源:
crm configure
primitive webip ocf:IPaddr params ip=192.168.18.200
定義完後可以用show檢視
<a href="http://s3.51cto.com/wyfs02/M00/3E/F6/wKiom1PIVmKwSDIEAAJPhUpOQ88761.jpg" target="_blank"></a>
沒錯誤的話,之後可以使用commit送出。
檢視狀态:
crm status
<a href="http://s3.51cto.com/wyfs02/M02/3E/F6/wKioL1PIWQnxSUKrAAI8r8VpnT8337.jpg" target="_blank"></a>
crm resource status
<a href="http://s3.51cto.com/wyfs02/M02/3E/F6/wKiom1PIWBGA3UL6AAExozv3sSY882.jpg" target="_blank"></a>
停止資源:
crm resource stop webip
啟動資源:
crm resource start webip
将目前節點設為備用,這時候資源就會轉移到節點二。
crm node standby
我們把httpd加入到可管理資源:
crm configure primitive webserver lsb:httpd
<a href="http://s3.51cto.com/wyfs02/M02/3E/F8/wKioL1PIYDbjpD1UAAQ9VQcnF4g479.jpg" target="_blank"></a>
定義資源組:
crm configure group webservice webip webserver
定義位置限制:
crm configure location webservice_prefer_node2 webservice 500: admin3.tuchao.com
verify
commit
<a href="http://s3.51cto.com/wyfs02/M01/3F/0C/wKioL1PIhjCwjfg1AAJJRT1PZ8o089.jpg" target="_blank"></a>
定義順序限制:
crm
configure
order webserver_after_webip mandatory: webip webserver
order 名稱 mandatory: webip webserver 注:這裡的mandatory表示無限大的值(強制)
把優先啟動的資源寫在前面。
show xml
<constraints>
<rsc_location id="webservice_prefer_node2" rsc="webservice" score="500" node="admin3.tuchao.com"/>
<rsc_order id="webip_before_webserver" score="INFINITY" first="webip" then="webserver"/>
</constraints>
定義組合限制:
colocation webip_with_webserver inf: webip webserver
<rsc_colocation id="webip_with_webserver" score="INFINITY" rsc="webip" with-rsc="webserver"/>
這裡的with-rsc="webserver"是指已webserver為準,如果webip啟動成功,webserver啟動失敗,那webip也會失效的。
定義一個檔案系統資源:
primitive webstore ocf:Filesystem params device='192.168.18.160:/webdata' directory='/var/www/html' fstype='nfs' op start timeout=60 op stop timeout=60
将資源加入到webservice組。
edit
<a href="http://s3.51cto.com/wyfs02/M01/3F/3C/wKiom1PIv_TRfllBAAMQzCsvk98342.jpg" target="_blank"></a>
show
<a href="http://s3.51cto.com/wyfs02/M01/3F/3C/wKioL1PIwcDy9G1LAALj4b8GzDo297.jpg" target="_blank"></a>
配置組合限制
colocation webip_before_webstore inf: webip webstore
colocation webstore_webserver inf: webstore webserver
<a href="http://s3.51cto.com/wyfs02/M00/3F/49/wKioL1PIx9Ghk__iAAOMKwzE0NI996.jpg" target="_blank"></a>
這樣配置就基本完成了,你會發現當你使用crm node standby把目前節點設定為備用後,另一個節點就會繼承資源繼續提供服務。
資源監控:
預設情況下,叢集并不會檢查資源的健康狀态,如果要實作此功能,需要專門為資源定義monitor功能,資源操作可定義的屬性有:
id:資源操作ID,必須唯一。
name:資源操作的動作,可用動作有minitor、start、和stop。
執行資源的監控操作使用mintor:
interval:資源操作的時間間隔,預設為0,即不執行操作。
timeout:确定某動作作為失敗的逾時時長。
on-fail:正在執行的動作失敗時要采取的動作。
可用值如下:
ignore:忽略
block:忽略
stop:停止資源
restart:重新開機資源,也有可能會在其他節點上啟動。
frence:将此節點關閉
standby:将其所在的節點轉換為standby模式
enabled:是否啟用,true,false。
有問題歡迎與我交流QQ1183710107
本文轉自qw87112 51CTO部落格,原文連結:http://blog.51cto.com/tchuairen/1439759