master配置
[root@localhost ~]# yum install -y epel-release
[root@localhost ~]# yum install -y heartbeat
[root@localhost ~]# yum install -y libnet
[root@localhost ~]# yum install -y openssh-clients
[root@localhost ~]# vi /etc/hosts 增加以下内容
192.168.10.29 master
192.168.10.39 slave
[root@localhost ~]# cp /usr/share/doc/heartbeat-3.0.4/authkeys /usr/share/doc/heartbeat-3.0.4/ha.cf /usr/share/doc/heartbeat-3.0.4/haresources /etc/ha.d/
[root@localhost ~]# vi /etc/ha.d/authkeys
auth 3
3 md5 Hello!
[root@localhost ~]# chmod 600 /etc/ha.d/authkeys
[root@localhost ~]# vi /etc/ha.d/haresources
# 这里的192.168.10.111 是vip,即虚拟ip
master 192.168.10.111/24/eth0:0 nginx
[root@localhost ~]# vi /etc/ha.d/ha.cf
# 错误日志
debugfile /var/log/ha-debug
# 正常日志
logfile /var/log/ha-log
# 日志级别
logfacility local0
# 探测间隔时间,2秒
keepalive 2
# 30秒ping不通,认为冗机
deadtime 30
# 10秒ping不通,发出警告
warntime 10
# 预防对方在重启
initdead 60
# 监听端口
udpport 694
# slave的IP
ucast eth0 192.168.10.29
# 假设slave正在工作,master已正常启动,则自动切换回master
auto_failback on
# 节点
node master
node slave
# 仲裁IP
ping 192.168.10.1
respawn hacluster /usr/lib/heartbeat/ipfail
从master端拷贝配置文件到slave
[root@localhost ~]# scp /etc/ha.d/authkeys /etc/ha.d/ha.cf /etc/ha.d/haresources slave:/etc/ha.d/
[root@localhost ~]# /etc/init.d/heartbeat start
slave配置
[root@localhost ~]# yum install -y epel-release
[root@localhost ~]# yum install -y heartbeat
[root@localhost ~]# yum install -y libnet
[root@localhost ~]# yum install -y openssh-clients
[root@localhost ~]# vi /etc/hosts 增加以下内容
192.168.10.29 master
192.168.10.39 slave
[root@localhost ~]# vi /etc/ha.d/ha.cf
# 错误日志
debugfile /var/log/ha-debug
# 正常日志
logfile /var/log/ha-log
# 日志级别
logfacility local0
# 探测间隔时间,2秒
keepalive 2
# 30秒ping不通,认为冗机
deadtime 30
# 10秒ping不通,发出警告
warntime 10
# 预防对方在重启
initdead 60
# 监听端口
udpport 694
# master的IP
ucast eth0 192.168.10.39
# 假设slave正在工作,master已正常启动,则自动切换回master
auto_failback on
# 节点
node master
node slave
# 仲裁IP
ping 192.168.10.1
respawn hacluster /usr/lib/heartbeat/ipfail
[root@localhost ~]# /etc/init.d/heartbeat start
至此,HA(high available)集群配置完毕