master
eth0 192.168.31.250
eth1 192.168.125.128
back
eth0 192.168.31.114
eth1 192.168.125.131
下面操作1-5都是在两个机器上操作
1. hostname 设置好,分别为david 和 david1
2. 关闭防火墙 iptables -F;
关闭selinux: setenforce 0
3. vi /etc/hosts // 增加内容如下:
192.168.31.250 david
192.168.31.114 david1
4. 安装epel扩展源:
rpm -ivh ‘http://www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm‘
5. 两个机器都安装heartbeat / libnet
yum install -y heartbeat* libnet nginx
6. 主上(aming)配置
cd /usr/share/doc/heartbeat-3.0.4/
cp authkeys ha.cf haresources /etc/ha.d/
cd /etc/ha.d
vi authkeys //加入或更改为auth 3
auth 3
3 md5 Hello!
chmod 600 authkeys
vi haresources //加入
aming 192.168.31.245/24/eth0:0 nginx 浮动ip
vi 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 eth1 192.168.125.131 /从节点上的eth1 ip 也叫作心跳ip
auto_failback on
node aming
node aming1
ping 192.168.125.2 /网关
respawn hacluster /usr/lib/heartbeat/ipfail
7. 把主上的三个配置拷贝到从上:
cd /etc/ha.d/
scp authkeys ha.cf haresources aming1:/etc/ha.d/
8. 到从上(david1) 编辑ha.cf
vi /etc/ha.d/ha.cf //只需要更改一个地方
ucast eth1 192.168.125.131改为 ucast eth1 192.168.125.128
9. 启动heartbeat :
先主,后从
service heartbeat start
10. 检查测试
ifconfig 看是否有 eth0:0
ps aux |grep nginx 看是否有nginx进程
11. 测试1
主上故意禁ping
iptables -I INPUT -p icmp -j DROP
12. 测试2
主上停止heartbeat服务
service heartbeat stop
13. 测试脑裂
主和从上都down掉eth1网卡
ifdown eth1
本文出自 “david0512” 博客,请务必保留此出处http://gjr0512.blog.51cto.com/6518687/1729176
原文:http://gjr0512.blog.51cto.com/6518687/1729176