部署方案二(推薦):corosync+pacemaker
利用ansible自動安裝corosync和pacemaker
注:關於ansible的具體使用可參見“ansible實現自動化自動化運維”
安裝ansible(使用最新版的rpm包安裝)
yum --nogpgcheck localinstall ansible-1.5.4-1.el6.noarch.rpm
配置ansible的主機列表
vi /etc/ansible/hosts [hanodes] node1.lamp.com node2.lamp.com
在ansible控制端準備安裝所需的文件
mkdir -pv /root/autoinstall_corosync/conf # 內含文件有: authkeys # corosync所需的密鑰文件,可通過corosync-keygen命令生成 corosync.conf # corosync的主配置文件 # corosync.conf配置文件 # Please read the corosync.conf.5 manual page compatibility: whitetank totem { version: 2 secauth: on threads: 0 interface { ringnumber: 0 bindnetaddr: 172.16.0.0 # 配置主機網卡所在的網路地址 mcastaddr: 226.0.25.10 # 配置多播地址,防止心跳信息在局域網內混亂傳播 mcastport: 5405 # 配置多播地址 ttl: 1 } } logging { # 日誌相關的配置 fileline: off to_stderr: no to_logfile: yes # logfile和syslog方式二選一即可 to_syslog: no logfile: /var/log/cluster/corosync.log debug: off timestamp: on logger_subsys { subsys: AMF debug: off } } amf { mode: disabled } service { # 定義一個服務,用以加載pacemaker插件 ver: 0 name: pacemaker } aisexec { # 定義corosync的工作用戶 user: root group: root }
mkdir -pv /root/autoinstall_corosync/packages # 內含程序包有: crmsh-1.2.6-4.el6.x86_64.rpm:crmsh配置接口的程序包 pssh-2.3.1-2.el6.x86_64.rpm:併發ssh程序包,crmsh安裝所依賴的包
配置corosync安裝劇本(corosync.yaml)
vi /root/autoinstall_corosync/corosync.yaml - hosts: hanodes remote_user: root vars: crmsh: crmsh-1.2.6-4.el6.x86_64.rpm pssh: pssh-2.3.1-2.el6.x86_64.rpm tasks: - name: corosync installing yum: name=corosync state=present - name: pacemaker installing yum: name=pacemaker state=present - name: pcs installing yum: name=pcs state=present - name: crmsh rpm packages copy: src=/root/autoinstall_corosync/packages/` crmsh ` dest=/tmp/` crmsh ` - name: pssh rpm packages copy: src=/root/autoinstall_corosync/packages/` pssh ` dest=/tmp/` pssh ` - name: crmsh installing command: yum -y reinstall /tmp/` crmsh ` /tmp/` pssh ` - name: authkey configure file copy: src=/root/autoinstall_corosync/conf/authkey dest=/etc/corosync/authkey - name: authkey mode 400 file: path=/etc/corosync/authkey mode=400 notify: - restart corosync - name: corosync.conf configure file copy: src=/root/autoinstall_corosync/conf/corosync.conf dest=/etc/corosync/corosync.conf tags: - conf notify: - restart corosync - name: ensure the corosync service startup on boot service: name=corosync state=started enabled=yes handlers: - name: restart corosync service: name=corosync state=restarted
執行一鍵安裝
ansible-playbook corosync.yaml
crmsh配置接口
crm # 進入crm命令行配置接口 configure # 進入configure模式 property stonith-enabled=false # 因爲在實驗環境中無stonith設備 property no-quorum-policy=ignore # 在實驗的雙節點環境中,配置no-quorum-policy爲ignore可避免手動測試某節點下線導致整個集羣不可用 rsc_defaults resource-stickiness=100 # 設置默認資源黏性值爲100 verify # 驗證配置是否正確 commit # 提交配置 primitive webip ocf:heartbeat:IPaddr params ip=172.16.25.51 op monitor interval=30s timeout=20s on-fail=restart # 創建資源webip,使用的RA是IPaddr,同時定義監控,檢測失敗則重啓資源 primitive webstore ocf:heartbeat:Filesystem params device="172.16.251.163:/www/phpwind.com" directory="/var/www/html" fstype="nfs" op monitor interval=20s timeout=40s op start timeout=60s op stop timeout=60s on-fail=restart # 創建資源webstore,使用的RA是Filesystem primitive webserver lsb:httpd op monitor interval=30s timeout=40s on-fail=restart # 創建資源webserver,使用的RA是httpd verify commit show # 顯示配置結果 show xml # 以xml文件格式顯示詳細配置信息 edit # 可直接編輯配置文件,修改內容 group webservice webip webstore webserver # 配置資源組webservice verify commit order webip_before_webstore_before_webserver infinity: webip webstore webserver # 定義順序約束,定義在前面的先確保運行 location webip_prefer_node1 webip inf: node1.lamp.com # 定義位置約束,使得webservice更傾向於運行於node1.lamp.com節點上 # 其它操作 ra # 切換至ra模式 list ocf heartbeat # 查看某類別(ocf heartbeat)下的所有資源代理RA meta ocf:heartbeat:Filesystem # 查看某一具體資源代理RA的可用屬性,查找哪些是必須屬性 configure # 切換至configure模式 colocation webip_with_webstore_with_webserver inf: webserver webstore webip # 定義排列約束,即各資源都運行在同一個主機上的傾向,這與定義資源組效果相同;定義在最後的資源所在的主機決定排列約束內全部資源所運行的主機 monitor webserver 20s:40s # 單獨定義監控資源webserver,間隔時間爲20s,超時時間爲40s resource # 進入resource模式 cleanup webservice # 清理資源運行過程中的錯誤狀態信息 stop webip # 停止資源 crm status # 顯示集羣狀態信息 crm configure show # 顯示集羣配置信息 crm node standby node1.lamp.com # 手動將node1由主節點配置爲從節點,使資源轉移發生 crm node online node1.lamp.com # 手動使node1重新上線
pcs配置接口
# 注:配置後即刻生效,無需手動commit提交 pcs property set stonith-enabled=false # 設置參數屬性 pcs property set no-quorum-policy=ignore pcs property set default-resource-stickiness=100 pcs resurce create webip ocf:heartbeat:IPaddr ip=172.16.25.51 op monitor interval=30s timeout=20s# 創建資源webip pcs resource create webstore ocf:heartbeat:Filesystem device="172.16.251.163:/www/phpwind.com" directory="/var/www/html" fstype="nfs" op monitor interval=20s timeout=40s op start timeout=60s op stop timeout=60s on-fail=restart # 創建資源webstore pcs resource create webserver lsb:httpd op monitor interval=30s timeout=20s on-fail=restart # 創建資源webserver pcs resource group add webservice webip webstore webserver # 配置資源組webservice pcs constraint order webip then webstore # 定義順序約束,只能定義兩兩的順序關係 pcs constraint order webstore then webserver pcs constraint location webservice prefers node1.lamp.com=500 # 定義位置約束 pcs status # 查看集羣狀態 # 其它操作: pcs resource list ocf:heartbeat # 查看某類別(ocf heartbeat)下的所有資源代理RA pcs resource describe ocf:heartbeat:Filesystem # 查看某一具體資源代理RA的可用屬性,查找哪些是必須屬性 pcs resource group remove webservice webserver # 刪除資源組webservice中的webserver資源 pcs resource ungroup webservice # 只刪除資源組webservice,並不刪除組內的資源 pcs constraint show # 顯示全部約束規則 pcs constraint order show # 顯示指定(如order)的約束規則 pcs constraint colocation add webstore with webip # 定義排列約束,與資源組效果相同,二者選其一即可 pcs constraint order set webip webstore webserver # 定義順序約束,可一次指定多個資源 pcs config # 查看當前集羣的配置
上一篇:corosync+pacemaker實現高可用(HA)集羣(一)