HA配置

主T800 eth0 192.168.2.32
备T600 eth1 192.168.2.33
安装nginx

yum install -y nginx

关闭主备的防火墙iptables、selinux

iptables -F ; service iptables save
setenforce 0
vim /etc/sysconfig/selinux
SELINUX=disabled

修改两台机的hosts文件

cat >> /etc/hosts << “EOF”
192.168.2.32 T800
192.168.2.33 T600
EOF

安装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 3
3 md5 hello!
EOF
cat >> /etc/ha.d/haresources << “EOF”
T800 192.168.2.132/24/eth0:0 nginx
EOF
cat > /etc/ha.d/ha.cf << “EOF”
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.2.33
auto_failback on
node T800
node T600
ping 192.168.2.1
respawn hacluster /usr/lib64/heartbeat/ipfail
EOF

备机配置

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 3
3 md5 hello!
EOF
cat >> /etc/ha.d/haresources << “EOF”

T800 192.168.2.132/24/eth1:0 nginx
EOF
cat > /etc/ha.d/ha.cf << “EOF”

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.2.32
auto_failback on
node T800
node T600
ping 192.168.2.1
respawn hacluster /usr/lib64/heartbeat/ipfail
EOF

也可以用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
主上故意禁ping

iptables -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 #对方的ip
auto_failback on #如果备启动了,当主恢复备自动放弃
node T800
node T600
ping 192.168.2.1 #仲裁者 网关或者交换机
respawn hacluster /usr/lib64/heartbeat/ipfail #检测网络联通信

posted @ 2018-04-04 15:39  俊偉  阅读(381)  评论(0编辑  收藏  举报
回顶部