HeartBeat 基于Resources简单配置
实验环境:redhat5.8 i386
为使实验顺利,请关闭防火墙与selinux
软件包: 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.rpm1、名称解析必需用/etc/hosts,节点名称必须与uname -n命令结果保持一致;
# vim /etc/hosts2、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.8node2 # 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.73、各节点时间要同步 # 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 -yhttpd必须关闭且开机不能自动启动
node1# echo "<h1>node1.neo.com</h1>" >/var/www/html/index.html # chkconfig httpd offnode2# 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实验共享存储自动挂载:# service 192.168.100.8 'service heartbeat stop' # service heartbeat stop新建一台虚拟机启动nfs服务# mkdir /web/htdocs -p # echo "<h1>FS.neo.com</h1>" >/web/htdocs/index.html # service nfs start # vim /etc/exports /web/htdocs 192.168.100.0/24(ro)# service iptables stop # getenforce 0 # vim /etc/ha.d/haresourcesnode1.neo.com IPaddr::192.168.100.5/24/eth0 Filesystem::192.168.100.9:/web/htdocs::/var/www/html::nfs httpd注:此处为一行
# scp /etc/ha.d/haresources 192.168.100.8:/etc/ha.d/ # service heartbeat start # ssh 192.168.100.8 'service heartbeat start'