软件:heartbeat

准备两台机器,均是64位系统


给两台主从机器分别设置新的hostname:master 和 slave


确保两台机器的selinux和iptables都关掉


编辑主和从的/etc/hosts:

192.168.237.133 master

192.168.237.137 slave


安装扩展源:rpm -ivh epel-release-6-8_64.noarch.rpm


yum安装heartbeat: yum install -y heartbeat

yum安装libnet: yum install -y libnet


拷贝配置文件样例:

[root@master ~]# cd /usr/share/doc/heartbeat-3.0.4

[root@master heartbeat-3.0.4]# ls

apphbd.cf  authkeys  AUTHORS  ChangeLog  COPYING  COPYING.LGPL  ha.cf  haresources  README

[root@master heartbeat-3.0.4]# cp authkeys ha.cf haresources /etc/ha.d/

[root@master heartbeat-3.0.4]# cd /etc/ha.d

[root@master ha.d]# ls

authkeys  ha.cf  harc  haresources  rc.d  README.config  resource.d  shellfuncs


编辑authkeys,让两台机器在加密的情况下进行通信,确认对方是否存活:

vim authkeys

安全级别有小到大:1<3<2

auth 3

#1 crc

#2 sha1 HI!

3 md5 Hello!

修改权限:chmod 600 authkeys


编辑haresources:修改主的名字,流动IP和启动的服务资源

首先给网卡eth0添加一个虚拟ip:

[root@master ha.d]# cd /etc/sysconfig/network-scripts/

[root@master network-scripts]# cp ifcfg-eth0 ifcfg-eth0:1

[root@master network-scripts]# vim ifcfg-eth0:1

DEVICE=eth0:1

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=yes

BOOTPROTO=static

IPADDR=192.168.237.109

NETMASK=255.255.255.0

重启网卡:[root@master network-scripts]# /etc/init.d/network restart


vim haresources

master  192.168.237.109/24/eth0:1 nginx


vim ha.cf

debugfile /var/log/ha-debug

logfile /var/log/ha-log

logfacility local0

keepalive 2

deadtime 30

warntime 10

initdead 60

udpport 694

ucast eth0 192.168.237.137

auto_failback on

node master

node slave

ping 192.168.237.1

respawn hacluster /usr/lib64/heartbeat/ipfail


把配置文件拷贝到slave上去:

[root@master ha.d]# rsync -av authkeys  ha.cf haresources slave:/etc/ha.d/


在slave上只修改ha.cf

[root@slave ha.d]# vim ha.cf

ucast eth0 192.168.237.133


两台机器上准备好启动nginx服务


启动heartbeat: 先启动主,再启动从