源码编译安装Heartbeat
一、Heartbeat介绍官方站点:http://linux-ha.org/wiki/Main_Page
Heartbeat可以资源(VIP地址及程序服务)从一台有故障的服务器快速的转移到另一台正常的服务器提供服务,heartbeat和keepalived相似,heartbeat可以实现failover功能,但不能实现对后端的健康检查。
二、简要规划
系统环境
系统
OEL6.6
系统位数
x86_64
内核版本
3.8.13-44.1.1.el6uek.x86_64
软件环境
Heartbeat
Heartbeat 3.0.6
Cluster Glue 1.0.12
Resource Agents 3.9.6
Heartbeat下载地址
http://linux-ha.org/wiki/Download
wget http://hg.linux-ha.org/heartbeat-STABLE_3_0/archive/958e11be8686.tar.bz2
wget http://hg.linux-ha.org/glue/archive/0a7add1d9996.tar.bz2
wget https://github.com/ClusterLabs/resource-agents/archive/v3.9.6.tar.gz
系统规划
主机名
IP
db-1-1
192.168.192.21 管理IP
10.0.100.21 心跳IP
192.168.192.100 VIP
db-1-2
192.168.192.22 管理IP
10.0.100.22 心跳IP
192.168.192.100 VIP
基本配置
# cat/etc/hosts
127.0.0.1 localhostlocalhost.localdomain
192.168.192.21 db-1-1
10.0.100.21 priv-1-1
192.168.192.22 db-1-2
10.0.100.22 priv-1-2
192.168.192.100 vip
EOF
--配置服务器间主机路由
#db-1-1:
route add -host 10.0.100.22 dev eth1
#db-1-2:
route add -host 10.0.100.21 dev eth1
--时间同步
crontab -l
*/5 * * * * `which ntpdate` pool.ntp.org >/dev/null 2>&1
三、编译安装
--依赖包安装(提前检查好):
yum -y install autoconf automake gcc-c++ asciidoc libxslt-devel libtool libtool-ltdl-devel libxml2 libxml2-devel bzip2-devel glib2-devel mercurial *openssl* net-snmp OpenIPMI flex bison e2fsprogs-devel --源码编译安装:
下载地址:http://linux-ha.org/wiki/Download
--Heartbeat 3.0.6:
# wget http://hg.linux-ha.org/heartbeat-STABLE_3_0/archive/958e11be8686.tar.bz2
--Cluster Glue 1.0.12:
# wget http://hg.linux-ha.org/glue/archive/0a7add1d9996.tar.bz2
--Resource Agents 3.9.6:
# wget https://github.com/ClusterLabs/resource-agents/archive/v3.9.6.tar.gz --用户组及用户配置
# groupadd haclient
# useradd -g haclient hacluster 编译Cluster Glue
# tar -jxvf cluster-clue-1.0.12.tar.bz2
# cd Reusable-Cluster-Components-glue--0a7add1d9996/
# ./autogen.sh
# 注:32位系统 LIBS='/lib/libuuid.so.1'
# ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --with-daemon-user=hacluster --with-daemon-group=haclient --enable-fatal-warnings=no LIBS='/lib64/libuuid.so.1'
# make && make install --卸载
# make uninstall && make clean
编译Resource Agents
# tar -zxvf resource-agents-3.9.6.tar.gz
# cd resource-agents-3.9.6
# ./autogen.sh
# ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --with-daemon-user=hacluster --with-daemon-group=haclient --enable-fatal-warnings=no LIBS='/lib64/libuuid.so.1'
# make && make install --卸载
# make uninstall && make clean
编译Heartbeat
# tar -jxvf heartbeat-3.0.6.tar.bz2
# cd Heartbeat-3-0-958e11be8686/
# ./bootstrap
# export CFLAGS="$CFLAGS -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib"
# ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --with-daemon-user=hacluster --with-daemon-group=haclient --enable-fatal-warnings=no LIBS='/lib64/libuuid.so.1'
# make && make install --卸载
# make uninstall && make clean
--heartbeat路径检查
# whereis heartbeat
heartbeat: /usr/lib64/heartbeat /usr/include/heartbeat /usr/libexec/heartbeat /usr/share/heartbeat /usr/share/man/man8/heartbeat.8
四、Heartbeat配置
# cp doc/{ha.cf,haresources,authkeys} /etc/ha.d/
# chmod 600 /etc/ha.d/authkeys
Heartbeat的配置主要涉 ha.cf、haresources、authkeys 三个文件:
ha.cf:主配置文件;
haresource:用来配置要让Heartbeat托管的服务;
authkey:用来指定Heartbeat的认证方式。
主备节点两端的三个配置文件(ha.cf authkeys haresources)完全相同
1)、配置ha.cf文件
# cp /etc/ha.d/ha.cf /etc/ha.d/ha.cf.bak
# > /etc/ha.d/ha.cf
# vi /etc/ha.d/ha.cf
#log configure
#用于记录heartbeat的调试信息
debugfile /var/log/ha-debug
#用于记录heartbeat的日志信息
logfile /var/log/ha-log
#设置heartbeat的日志,这里用的是系统日志
logfacility local1
#options configure
#设定心跳(监测)时间时间为2秒
keepalive 2
#指定若备用节点在30秒内未收到主节点心跳信号,则接管主服务器资源
deadtime 30
#指定心跳延迟告警时间为10秒(最好在2~10秒之间),,10秒内备节点不能接收主节点心跳信号,即往日志写入警告日志,但不会切换服务
warntime 10
#系统启动或重启后预留的忽略时间段,取值至少为deadtime的两倍
initdead 120
##########################
#广播/单播通讯使用的Udp端口
#udpport694
#使用网卡eth1发送心跳检测(Linux)
#bcast eth1
#采用网卡eth1的udp单播来组织心跳,后面跟的IP地址为双机对方IP地址
#ucast eth1 10.0.100.22
##########################
#bcasteth1
#采用网卡eth1的Udp多播来组织心跳,一般在备用节点不止一台时使用。Bcast、ucast和mcast分别代表广播、单播和多播,是组织心跳的的方式,任选其一
mcast eth1 225.0.0.100 694 1 0
#node configure
#定义当主节点恢复后,是否将服务自动切回(DB建议为off,测试阶段设置为on)
auto_failback on
#可选配置,通过Heartbeat监控系统运行状态
#watchdog /dev/watchdo
#主节点名称(主节点主机名),与uname -n显示一致
node db-1-1
#备用节点名称
node db-1-2
crm no
#通过ping网关检测心跳是否正常,仅用来测试网络
#ping 10.0.100.1
#指定和heartbeat一起启动、关闭的进程,可选
#respawn hacluster /usr/local/heartbeat/libexec/heartbeat/ipfail
#设置启动IPfail的用户和组
#apiauth ipfail gid=haclient uid=hacluster 注:
① watchdog /dev/watchdog: 可选配置,通过Heartbeat监控系统运行状态。该特性需在内核中载入"softdog"内核模块,用来生成实际的设备文件,如系统中没有该模块,需进行指定,重新编译内核。编译完成输入 "insmod softdog"加载模块,然后输入"grep misc/proc/devices",输入"cat /proc/misc |grep watchdog",最后生成设备文件:"mknod /dev/watchdog c 10 130" 即可使用
② espawn hacluster /usr/lib/heartbeat/ipfail: 可选配置,指定和heartbeat一起启动、关闭的进程。这些进程一般是和heartbeat集成的插件,遇到故障可自动重启。IPfail进程用于检测和处理网络故障,需配合ping语句指定ping node检测网络连通性;hacluster表示启动IPfail进程的用户。
2)、配置authkeys,心跳密钥验证文件
# cp /etc/ha.d/authkeys /etc/ha.d/authkeys.bak
# > /etc/ha.d/authkeys
# vi /etc/ha.d/authkeys
#注:auth后填序号,可任意填写
auth 1
#开头必须为序号名,然后为验证方式,支持三种( crc md5 sha1 )方式验证,最后面是自定义密钥
1 sha1 ccb6d8d12a7c207d7somb6618556d62e4831dfab 3)、配置haresources
# cp /etc/ha.d/haresources /etc/ha.d/haresources.bak
# > /etc/ha.d/haresources
# vi /etc/ha.d/haresources
#db-1-1 #预定的主机节点名称,与相应主机$uname -n的结果一致。需保证drbd.conf和ha.cf中节点的名字一致。备机此处写db-1-2。
#IPaddr::192.168.192.100/24/eth0 #规划的VIP。
db-1-1 IPaddr::192.168.192.100/24/eth0
######################
##@说明信息:
##@drbddisk::dbdata_r0
页:
[1]