Heartbeat 3.0.x 编译安装(CentOS6)

Heartbeat 是一个高可用集群工具,CentOS 包含了该组件,可以直接Yum 进行安装,对于如何编译安装,在参考了其它文章后,进行了错误整理,将过程记录下来,提供给需要的朋友。
系统环境 CentOS 6.2   X64
HA-01  192.168.0.2 (node1)
HA-02  192.168.0.3 (node2)
Virtual IP  192.168.0.1 (虚拟服务器IP)

1.最小化(mininal )安装系统,完成后安装gcc编译器及依赖的软件包

yum install gcc gcc-c++ autoconf automake libtool glib2-devel libxml2-devel bzip2-devel e2fsprogs-devel libxslt-devel libtool-ltdl-devel make wget docbook-dtds docbook-style-xsl

2. 添加 Haclient 组和 Hacluster 账户

groupadd haclient
useradd -g haclient hacluster -M -s /sbin/nologin

3.安装Cluster-Glue
官方下载地址 http://hg.linux-ha.org/glue

tar zxf Reusable-Cluster-Components-glue--1.0.8.tar.gz
cd Reusable-Cluster-Components-glue--c69dc6ace936
./autogen.sh
./configure --prefix=/usr/local/heartbeat --sysconfdir=/etc/heartbeat libdir=/usr/local/heartbeat/lib64 LIBS='/lib64/libuuid.so.1'
make && make install

* 32位环境需要将配置参数中的lib64 更改为 lib
* 安装过程中会从 sourceforge 下载一些文件,如果速度慢,需要检查网络是否畅通,以及 docbook-dtds docbook-style-xsl 两个rpm包是否安装

4.安装Resource Agents
官方下载地址 https://github.com/ClusterLabs/resource-agents

tar zxf ClusterLabs-resource-agents-v3.9.2-0-ge261943.tar.gz
cd ClusterLabs-resource-agents-b735277
./autogen.sh
./configure --prefix=/usr/local/heartbeat --sysconfdir=/etc/heartbeat libdir=/usr/local/heartbeat/lib64 CFLAGS=-I/usr/local/heartbeat/include LDFLAGS=-L/usr/local/heartbeat/lib64 LIBS='/lib64/libuuid.so.1'

ln -s /usr/local/heartbeat/lib64/* /lib64/
//建立一个软连接,避免编译时找不到所需要的包
make && make install

* 32位环境需要将配置参数中的lib64 更改为 lib

5.安装Heartbeat
官方下载地址 http://hg.linux-ha.org

 

tar jxf Heartbeat-3-0-7e3a82377fa8.tar.bz2
cd Heartbeat-3-0-7e3a82377fa8
./bootstrap
./configure --prefix=/usr/local/heartbeat --sysconfdir=/etc/heartbeat CFLAGS=-I/usr/local/heartbeat/include LDFLAGS=-L/usr/local/heartbeat/lib64 LIBS='/lib64/libuuid.so.1'
vi /usr/local/heartbeat/include/heartbeat/glue_config.h
// 删除 glue_config.h 最后一行定义的配置文件路径,避免编译时产生的路径重复定义错误,Shift+g 跳到末行,dd删除
// define HA_HBCONF_DIR "/usr/local/heartbeat/etc/ha.d/" :wq保存完成.
make && make install

将配置文件复制到 /etc/heartbeat/ 下,并使用sed 修改路径

cp doc/ha.cf /etc/heartbeat/ha.d/
cp doc/haresources /etc/heartbeat/ha.d/
cp doc/authkeys /etc/heartbeat/ha.d/
chkconfig --add heartbeat
chkconfig heartbeat on
chmod 600 /etc/heartbeat/ha.d/authkeys

sed -i 's#/usr/lib/ocf#/usr/local/heartbeat/usr/lib/ocf#g' /etc/heartbeat/ha.d/shellfuncs
sed -i 's#/usr/lib/ocf#/usr/local/heartbeat/usr/lib/ocf#g' /etc/heartbeat/ha.d/resource.d/hto-mapfuncs
sed -i 's#/usr/lib/ocf#/usr/local/heartbeat/usr/lib/ocf#g' /usr/local/heartbeat/usr/lib/ocf/lib/heartbeat/ocf-shellfuncs

建立Resource-Agent 的脚本软连接,避免Heartbeat 找不到路径而无法工作

ln -s /usr/local/heartbeat/usr/lib/ocf /usr/lib/ocf

系统服务可以通过 service heartbeat start/stop 来启动停止

6. 进行配置(只简单说明下提供参考)
# vi /etc/heartbeat/ha.d/ha.cf
编辑Heartbeat 检测参数配置文件,以下文件作为参考

debugfile /var/log/ha-debug   
# 用于记录heartbeat的调试信息

logfile /var/log/ha-log       
# 用于记录heartbeat的日志信息

logfacility     local0

keepalive 2         
# 设置心跳间隔

deadtime 30              
# 在30秒后宣布节点死亡

warntime 10              
# 在日志中发出“late heartbeat“警告之前等待的时间,单位为秒

initdead 120             
# 网络启动时间

udpport	 694       
# 广播/单播通讯使用的udp端口

#baud   19200
#serial  /dev/ttyS0      
# 使用串口heartbeat

bcast   eth0             
# 使用网卡heartbeat,并在eth0接口上使用广播heartbeat

auto_failback on         
# 当主节点从故障中恢复时,将自动切换到主节点

watchdog /dev/watchdog   
# 该指令是用于设置看门狗定时器,如果节点一分钟内都没有心跳,那么节点将重新启动

node HA-01
node HA-02         
# 集群中机器的主机名,与“uname –n”的输出相同。

ping 192.168.0.254
# ping 网关或路由器来检测链路正常

respawn hacluster /usr/local/heartbeat/lib64/heartbeat/ipfail
# respawn调用/usr/lib/heartbeat/ipfail来主动进行切换

apiauth ipfail gid=haclient uid=hacluster   
# 设置启动ipfail的用户和组

编辑资源文件
vi /etc/heartbeat/ha.d/haresources

HA-01 192.168.0.1 mysqld

#机器名 虚拟服务器IP  系统服务

* 在启动的时候,节点HA-01启用192.168.0.1 的虚拟IP地址,对外提供服务,同时也启动 mysqld 服务,当关闭的时候, heartbeat停止mysqld 服务,然后取消ip地址. 这里的主机用是用命令 uname -n 获取到的一致,资源文件支持很多种配置方法,请参考其它说明文档

配置验证密钥
vi /etc/heartbeat/ha.d/authkeys

auth 1		//认证序号1
1 md5 password  //序号1 采用MD5 后面是密钥

* 规则说明 auth 后面填写序号,可任意填写,但第二行开头必须为序号名,然后为验证方式,支持三种( crc md5 sha1 )方式验证,最后面是自定义密钥

chmod 600 /etc/heartbeat/ha.d/authkeys
//文件权限更改为600

使用同样的方式,对另一台 HA-02 进行配置,这里不再叙述

正常工作时,使用 ifconfig 查看网络连接信息,可看到Heartbeat 在 eth0 接口上新添加了一个虚拟IP地址
当节点出现故障,本机会尝试关闭服务和虚拟IP, 同时另一台机器检测到故障会添加相同的虚拟IP地址,来对外提供服务,实现业务的不中断

[root@HA-01 opt]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:EB:E3:5E
          inet addr:192.168.0.2  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feeb:e35e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:21944 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8325 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2564223 (2.4 MiB)  TX bytes:1670947 (1.5 MiB)

eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:EB:E3:5E
          inet addr:192.168.0.1  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

 

作者: Su

等待完善