HeartBeat 基于Resources简单配置
实验环境:RedHat5.8 i386
为使实验顺利,请关闭防火墙与selinux
软件包:下载地址:Fedoraproject.org/pub/epel/5/i386/repoview/letter_h.group.html
heartbeat - Heartbeat subsystem for High-Availability Linux
heartbeat-devel - Heartbeat development package
heartbeat-gui - Provides a gui interface to manage heartbeat clusters
heartbeat-ldirectord - Monitor daemon for maintaining high availability resources, 为ipvs高可用提供规则自动生成及后端realserver健康状态检查的组件;
heartbeat-pils - Provides a general plugin and interface loading library
heartbeat-stonith - Provides an interface to Shoot The Other Node In The Head
perl-MailTools-1.77-1.el5.noarch.rpm
libnet-1.1.4-3.el5.i386.rpm
1、名称解析必需用/etc/hosts,节点名称必须与uname -n命令结果保持一致;
# vim /etc/hosts
2、ssh互信通信
node1
# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
# ssh-copy-id -i ./.ssh/id_rsa.pub root@192.168.100.8
# ssh 192.168.100.8
node2
# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
# ssh-copy-id -i ./.ssh/id_rsa.pub root@192.168.100.7
# ssh 192.168.100.7
3、各节点时间要同步
# hwclock -w
当然上面这是在实验环境使用,在生产环境配置ntp服务就可以了
4、安装软件包
# ls
rw-r--r-- 1 root root 1637238 Mar 20 08:56 heartbeat-2.1.4-9.el5.i386.rpm
-rw-r--r-- 1 root root 230890 Mar 20 08:56 heartbeat-gui-2.1.4-9.el5.i386.rpm
-rw-r--r-- 1 root root 92070 Mar 20 08:56 heartbeat-pils-2.1.4-10.el5.i386.rpm
-rw-r--r-- 1 root root 179199 Mar 20 08:56 heartbeat-stonith-2.1.4-10.el5.i386.rpm
-rw-r--r-- 1 root root 56817 Mar 20 08:56 libnet-1.1.4-3.el5.i386.rpm
-rw-r--r-- 1 root root 92071 Mar 20 08:56 perl-MailTools-1.77-1.el5.noarch.rpm
# yum --nogpgcheck localinstall *.rpm -y
注:这一步可以自动解决依赖关系,前提是你的本地yum源己配置好了
5、启动服务
# yum install httpd -y
httpd必须关闭且开机不能自动启动
node1
# echo "<h1>node1.neo.com</h1>" >/var/www/html/index.html
# chkconfig httpd off
node2
# chkconfig httpd off
# echo "<h1>node2.neo.com</h1>" >/var/www/html/index.html
这里面要三个配置文件:
1、密钥文件;
2、heartbeat服务的配置文件ha.cf
3、资源管理配置文件haresources
# cp /usr/share/doc/heartbeat-2.1.4/{authkeys,ha.cf,haresources} /etc/ha.d/
# chmod 600 authkeys
# vim authkeys 添加两行
auth 1
1 md5 d41d8cd98f00b204e9800998ecf8427e
注:后面一串是用md5sum生成的随机数,用户自己随意定义都成,但格式需一致
# vim ha.cf
logfile /var/log/heartbeat.log
logfacility local0
keepalive 1
bcast eth0
node node1.neo.com
node node2.neo.com
ping 192.168.100.2
# vim haresources
node1.neo.com IPaddr::192.168.100.5/24/eth0 httpd
# scp -p authkeys haresources ha.cf 192.168.100.8:/etc/ha.d/
# service heartbeat start
# ssh 192.168.100.8 'service heartbeat start'
注:这里最好是使用主节点远程启动从节点,关闭时先关闭从节点再关闭主节点
查看日志状态:/var/log/message
故障测试:
# cd /usr/lib/heartbeat
# ./hb_standby
此脚本是heartbeat自带的一个故障测试文件
# ifconfig eth0可以看到在node2上有个接口eth0:0
推荐阅读:
Linux 高可用(HA)集群之heartbeat基于crm进行资源管理详解
Heartbeat+httpd+NFS 实现高可用的Web服务器
LVS+heartbeat+ldirectord高可用负载均衡集群解决方案