阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

使用CRM方式管理Heartbeat

112次阅读
没有评论

共计 6925 个字符,预计需要花费 18 分钟才能阅读完成。

Heartbeat 是一个基于 Linux 开源的,被广泛使用的高可用集群系统。主要包括心跳服务和资源接管两个高可用集群组件。其资源管理方式可以使用基于 haresource 文件方式进行管理,也可以通过基于 CIB 方式进行管理。基于 CIB 方式其集群资源采用了 xml 格式来保存其资源配置信息。可以把基于 haresouce 文件管理的资源转换为基于 CIB 方式管理。其最大的优势是通过 CIB 方式管理使得集群的管理更方便和易于监控。本文主要描述 crm 方式命令行管理 heartbeat。

一、相关配置文件描述
### 节点信息
# 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
所有的命令均可以通过 <command> –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
  <node id=”6ae0f853-b98c-470b-9ce9-4cd0077179ee” uname=”orasrv2.xlk.com” type=”normal”/>
  <node id=”512505ec-63f0-4a51-be40-58ba0e2f613d” uname=”orasrv1.xlk.com” type=”normal”/>

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 管理方式,也可以基于图形化界面进行管理,本文略

基于 Heartbeat V1 实现 Web 服务双机热备 http://www.linuxidc.com/Linux/2014-04/100635.htm

Heartbeat 实现 Web 服务的高可用群集 http://www.linuxidc.com/Linux/2014-04/99503.htm

Heartbeat+LVS+Ldirectord 高可用负载均衡解决方案 http://www.linuxidc.com/Linux/2014-04/99502.htm

DRBD+Heartbeat+NFS 高可用性配置笔记 http://www.linuxidc.com/Linux/2014-04/99501.htm

Heartbeat 基于 CRM 使用 NFS 对 MySQL 高可用 http://www.linuxidc.com/Linux/2014-03/98674.htm

Heartbeat 高可用 httpd 基于 Resources 简单配置 http://www.linuxidc.com/Linux/2014-03/98672.htm

CentOS 6 高可用服务 Heartbeat v3 安装以及配置  http://www.linuxidc.com/Linux/2015-04/116153.htm

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-11/125209.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计6925字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中