歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> 使用CRM方式管理heartbeat

使用CRM方式管理heartbeat

日期:2017/3/1 12:21:21   编辑:關於Linux

Heartbeat 是一個基於Linux開源的,被廣泛使用的高可用集群系統。主要包括心跳服務和資源接管兩個高可用集群組件。其資源管理方式可以使用基於haresource文件方式進行管理,也可以通過基於CIB方式進行管理。基於CIB方式其集群資源采用了xml格式來保存其資源配置信息。可以把基於haresouce文件管理的資源轉換為基於CIB方式管理。其最大的優勢是通過CIB方式管理使得集群的管理更方便和易於監控。本文主要描述crm方式命令行管理heartbeat。
有關heartbeat相關參考:
HeartBeat 集群組件概述
Linux 下安裝及配置heartbeat
Linux基於heartbeat配置httpd高可用服務

一、相關配置文件描述

###節點信息
# more /etc/hosts
127.0.0.1 localhost.localdomain localhost

#public ip
192.168.21.10 orasrv1.xlk.com orasrv1
192.168.21.13 orasrv2.xlk.com orasrv2

#private ip
192.168.144.128 orasrv1-priv.xlk.com orasrv1-priv
192.168.144.129 orasrv2-priv.xlk.com orasrv2-priv

###配置文件信息
# cat /etc/ha.d/ha.cf        ###ha.cf文件
logfile /var/log/ha-log
keepalive       2
deadtime        15
warntime        30 
initdead        60 
udpport         694
bcast           eth0
auto_failback   off
node orasrv1.xlk.com
node orasrv2.xlk.com
ping 192.168.21.254
respawn hacluster  /usr/lib64/heartbeat/ipfail
crm respawn ###此項用於定義開啟crm方式,或者說是pacemaker(heartbeat V3後)

#CRM與Resources並不兼容,如果ha.cf中定義了CRM,HA服務不會去讀取/etc/ha.d/haresources配置文件
#在日志文件中會看到這樣的提示:This file is not used because crm is enabled

# cat /etc/ha.d/authkeys ###authkeys文件
auth 1
1 md5 74a6a503b5bec9373b22bb630608df41

# more /etc/ha.d/haresources  ###資源文件
orasrv1.xlk.com IPaddr::192.168.21.1 httpd

###使用ha_propagate同步配置文件,注意,不包含haresource文件
###ha_propagate使用的基於等效ssh下scp命令方式,同時連接到節點上使用chkconfig開啟heartbeat自啟動
[root@orasrv1 heartbeat]# /usr/lib64/heartbeat/ha_propagate

二、啟動heartbeat服務

# service heartbeat start                 ###節點1
# ssh orasrv2 'service heartbeat start'   ###節點2
# netstat -nltp|grep 5560                 ###查看mgmtd端口
tcp        0      0 0.0.0.0:5560                0.0.0.0:*                   LISTEN      4128/mgmtd          
# ssh orasrv2 'netstat -nltp|grep 5560'
tcp        0      0 0.0.0.0:5560                0.0.0.0:*                   LISTEN      3434/mgmtd    

###查看heartbeat相關進程
# ps -AHfww | grep heartbeat |grep -v grep
root       5564      1  0 Nov11 ?        00:00:40   heartbeat: master control process
nobody     5567   5564  0 Nov11 ?        00:00:04     heartbeat: FIFO reader        
nobody     5568   5564  0 Nov11 ?        00:00:09     heartbeat: write: bcast eth0  
nobody     5569   5564  0 Nov11 ?        00:00:03     heartbeat: read: bcast eth0   
nobody     5570   5564  0 Nov11 ?        00:00:07     heartbeat: write: ping 192.168.21.254
nobody     5571   5564  0 Nov11 ?        00:00:02     heartbeat: read: ping 192.168.21.254
496        5575   5564  0 Nov11 ?        00:00:04     /usr/lib64/heartbeat/ccm
496        5576   5564  0 Nov11 ?        00:00:07     /usr/lib64/heartbeat/cib
nobody     5577   5564  0 Nov11 ?        00:00:03     /usr/lib64/heartbeat/lrmd -r
nobody     5578   5564  0 Nov11 ?        00:00:04     /usr/lib64/heartbeat/stonithd
496        5579   5564  0 Nov11 ?        00:00:02     /usr/lib64/heartbeat/attrd
496        5580   5564  0 Nov11 ?        00:00:03     /usr/lib64/heartbeat/crmd
496        8978   5580  0 08:55 ?        00:00:00       /usr/lib64/heartbeat/tengine
496        8979   5580  0 08:55 ?        00:00:00       /usr/lib64/heartbeat/pengine
root       5581   5564  0 Nov11 ?        00:00:03     /usr/lib64/heartbeat/mgmtd -v

###下面可以查看到了自動生成的cib.xml文件,此文件不含具體資源信息
# cd /var/lib/heartbeat/crm
# ls -hltr
total 16K
-rw------- 2 hacluster haclient 484 Nov 11 16:54 cib.xml.last
-rw------- 2 hacluster haclient 484 Nov 11 16:54 cib.xml
-rw-r--r-- 2 hacluster haclient  32 Nov 11 16:54 cib.xml.sig.last
-rw-r--r-- 2 hacluster haclient  32 Nov 11 16:54 cib.xml.sig

# ifconfig |grep eth0:0
# ssh orasrv2 'ifconfig |grep eth0:0 -A2'  ###此時vip在第二個節點
eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:F1:2E:E4  
          inet addr:192.168.21.1  Bcast:192.168.21.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

三、使用crm相關命令管理集群

crm相關命令行工具,通常位於/usr/sbin
所有的命令均可以通過


--help 方式來獲取幫助 crm_verify --校驗集群配置文件 crm_uuid --查看節點的uuid crm_standby --操作節點的備用屬性以確定資源是否可在此節點上運行 crm_resource --資源管理工具 crm_mon --集群健康狀態監控 crm_master --管理主/從屬資源的自選設置,以在給定節點上提升 crm_failcount --管理記錄每個資源的故障計數的計數器。 crm_diff --識別對群集配置所做的更改,並將增補程序應用到配置文件 crm_attribute --允許查詢、修改和刪除節點屬性和群集選項。 crmadmin --控制群集資源管理器 crm_sh --crm命令提示符下的工具集 cibadmin --提供對群集配置的直接訪問 # crm_verify -x /var/lib/heartbeat/crm/cib.xml ###校驗配置文件 # crm_uuid ###查看節點uuid 512505ec-63f0-4a51-be40-58ba0e2f613d # ssh orasrv2 crm_uuid 6ae0f853-b98c-470b-9ce9-4cd0077179ee # crm_resource --list ###查看資源,當前無任何資源 NO resources configured # crm_mon -1 ###集群狀態監控,當前2節點在線 ============ Last updated: Wed Nov 11 17:14:18 2015 Current DC: orasrv2.xlk.com (6ae0f853-b98c-470b-9ce9-4cd0077179ee) 2 Nodes configured. 0 Resources configured. ============ Node: orasrv2.xlk.com (6ae0f853-b98c-470b-9ce9-4cd0077179ee): online Node: orasrv1.xlk.com (512505ec-63f0-4a51-be40-58ba0e2f613d): online haresources文件資源轉到到CIB xml ###使用haresources2cib.py將haresource文件內容轉換到CIB xml文件 # /usr/lib64/heartbeat/haresources2cib.py cib.xml or cib.xml.sig exist in /var/lib/heartbeat/crm/ please remove them before generating new cib.xml # mkdir /var/lib/heartbeat/crm/old # mv /var/lib/heartbeat/crm/cib* /var/lib/heartbeat/crm/old # /usr/lib64/heartbeat/haresources2cib.py # ls /var/lib/heartbeat/crm/ cib.xml old ###重啟2節點 # service heartbeat restart ###節點1 # ssh orasrv2 'service heartbeat restart' ###節點2 # crm_resource --list ###查看所有資源,有一組資源 Resource Group: group_1 IPaddr_192_168_21_1 (ocf::heartbeat:IPaddr) httpd_2 (lsb:httpd) [root@orasrv1 ~]# crm_resource -Q -r IPaddr_192_168_21_1 ###查詢指定資源 Resource Group: group_1 IPaddr_192_168_21_1 (ocf::heartbeat:IPaddr) httpd_2 (lsb:httpd) [root@orasrv1 ~]# crm_resource -QW -r IPaddr_192_168_21_1 ###查詢資源所在的節點 orasrv1.xlk.com # crmadmin --version HA Version 2.1.4, CRM Version 2.0 (CIB feature set 2.0) node: aa909246edb386137b986c5773344b98c6969999 [root@orasrv1 ~]# crmadmin --nodes ###查詢節點成員名 normal node: orasrv2.xlk.com (6ae0f853-b98c-470b-9ce9-4cd0077179ee) normal node: orasrv1.xlk.com (512505ec-63f0-4a51-be40-58ba0e2f613d) # crm_sh /usr/sbin/crm_sh:31: DeprecationWarning: The popen2 module is deprecated. Use the subprocess module. from popen2 import Popen3 crm # help Usage: crm (nodes|config|resources) crm # nodes crm nodes # help Usage: nodes (status|list) crm nodes # list crm nodes # config --無法切換到config路徑下 crm nodes # help Usage: nodes (status|list) crm nodes # resources --同樣無法切換到config路徑下 crm nodes # help Usage: nodes (status|list) ###驗證httpd服務,從下面的查詢可以看出,當前的服務在第2個節點 # curl http://192.168.21.1/ orasrv1.xlk.com ###更多命令的詳細描述,請參考: http://www.novell.com/zh-cn/documentation/sle_ha/book_sleha/data/cha_ha_management.html

四、切換測試

[root@orasrv1 crm]# crm_standby -v true
[root@orasrv1 crm]# curl http://192.168.21.1/
orasrv2.xlk.com

###也可以通過指定節點的方式進行切換
###假定節點2為主,則可以在節點1上執行一下命令將其切換為備
# crm_standby -v true -U orasrv2.xlk.com  

五、小結

1、在heartbeat v2之後的版本,可以將haresources方式管理的資源轉化為基於CIB方式進行管理
2、使用CRM(CIB)管理,需要配置ha.cf,添加crm respawn
3、CRM與haresources方式並不兼容,即二者選其一
4、可以使用crm相關命令對集群進行相關配置,監控,切換等管理
5、使用CRM管理方式,也可以基於圖形化界面進行管理,本文略

Copyright © Linux教程網 All Rights Reserved