主T800 eth0 192.168.2.32
备T600 eth1 192.168.2.33安装nginxyum install -y nginx
关闭主备的防火墙iptables、selinux
iptables -F ; service iptables savesetenforce 0vim /etc/sysconfig/selinuxSELINUX=disabled
修改两台机的hosts文件
cat >> /etc/hosts << “EOF”192.168.2.32 T800192.168.2.33 T600EOF
安装heartbeat、libnet
yum install -y heartbeat libnet
拷贝配置文件主机配置
cd /usr/share/doc/heartbeat-3.0.4/cp authkeys ha.cf haresources /etc/ha.d/chmod 600 /etc/ha.d/authkeys
cat >> /etc/ha.d/authkeys << “EOF”auth 33 md5 hello!EOFcat >> /etc/ha.d/haresources << “EOF”T800 192.168.2.132/24/eth0:0 nginxEOF
cat > /etc/ha.d/ha.cf << “EOF”debugfile /var/log/ha-debuglogfile /var/log/ha-loglogfacility local0keepalive 2deadtime 30warntime 10initdead 60udpport 694ucast eth0 192.168.2.33auto_failback onnode T800node T600ping 192.168.2.1respawn hacluster /usr/lib64/heartbeat/ipfailEOF
备机配置
cd /usr/share/doc/heartbeat-3.0.4/cp authkeys ha.cf haresources /etc/ha.d/chmod 600 /etc/ha.d/authkeys
cat >> /etc/ha.d/authkeys << “EOF”auth 33 md5 hello!EOF
cat >> /etc/ha.d/haresources << “EOF”T800 192.168.2.132/24/eth1:0 nginxEOF
cat > /etc/ha.d/ha.cf << “EOF”debugfile /var/log/ha-debuglogfile /var/log/ha-loglogfacility local0keepalive 2deadtime 30warntime 10initdead 60udpport 694ucast eth1 192.168.2.32auto_failback onnode T800node T600ping 192.168.2.1respawn hacluster /usr/lib64/heartbeat/ipfailEOF
也可以用scp从主机拷贝到备机
scp authkeys haresources ha.cf T600:/etc/ha.d/
开启服务注意先后顺序先主后备
/etc/init.d/heartbeat start
区分两台主机名
echo T800 > /usr/share/nginx/html/index.html
测试
curl 192.168.2.132
测试
ifconfig
看是否有 eth0:0
ps aux |grep nginx
看是否有nginx进程
测试1
主上故意禁pingiptables -I INPUT -p icmp -j DROP
测试2
主上停止heartbeat服务
service heartbeat stop
测试脑裂
主和从上都down掉eth0网卡
ifdown eth0
配置说明
debugfile /var/log/ha-debug #排障日志
logfile /var/log/ha-log #日志logfacility local0 #日志的级别keepalive 2 #多久去探测一次对面是否存活 2秒deadtime 30 #30秒没反应,就认为挂掉了warntime 10 #等待时间10秒initdead 60 #防止对方服务器在重启 预留60秒udpport 694 #心跳线通信端口ucast eth0 192.168.2.33 #对方的ipauto_failback on #如果备启动了,当主恢复备自动放弃node T800node T600ping 192.168.2.1 #仲裁者 网关或者交换机respawn hacluster /usr/lib64/heartbeat/ipfail #检测网络联通信