主从:1. 关闭防火墙,关闭SELINUX 2. 将主从IP 地址写入 /etc/hosts 里面
安装 heartbeat : yum list | grep heartbeat
(没有安装扩展源:
centos5
32位
epel
源下载地址: www.lishiming.net/data/attachment/forum/epel-release-5-4_32.noarch.rpm
64位下载地址: www.lishiming.net/data/attachment/forum/epel-release-5-4_64.noarch.rpm
centos6
32位epel yum源下载地址:
www.lishiming.net/data/attachment/forum/
epel-release-6-8_32.noarch.rpm
64位下载地址:
www.lishiming.net/data/attachment/forum/
epel-release-6-8_64.noarch.rpm
) rpm -ivh ...rpm
#安装 heartbeat:yum install -y heartbeat
#安装 libnet:yum -y install libnet
主:
# cd /usr/share/doc/heartbeat...
# cp authkeys ha.cf haresources /etc/ha.d/
# cd /etc/ha.d/ ; vim authkeys
auth 3
3 md5 Hello!
# chmod 600 authkeys
# vim haresources
/nodel 10.0.0.170..... 修改为 主服务器主机名 虚拟IP(VIP:192.168.11.110/24/eth0:0) 启动资源( nginx 服务)
# vim ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2 # 2s 发一次警告
deadtime 30 #死掉
warntime 10 #发警告到 logfile
initdead 120 #预留时间
udpport 694 #心跳端口
ucast eth0 192.168.11.20 # 另一台机子
auto_failback on #当从服务器启动,主重新激活时,从服务器自动放弃
node master
node slave
ping 192.168.11.1 #路由器或者交换机的IP
respawn hacluster /usr/lib/heartbeat/ipfail # 以 hacluster 用户启动 /usr/lib/heartbeat/ipfail 脚本,用来检测对方网络是否联通,当对方机子死掉的时候, respawn 自动激活机子
从:
# scp authkeys ha.cf haresources slave:/etc/ha.d/
# vim ha.cf
修改其中的 ucast eth0 为 192.168.11.160
主从:
# 分别安装 yum -y install nginx
启动: /etc/init.d/heartbeat start (注:先启动主,再启动从)
# ip add 查看 VIP(192.168.11.110)
主: echo "1111111master" > /usr/share/nginx/html/index.html
从: echo "1111111slave" > /usr/share/nginx/html/index.html
主:关闭 icmp :iptables -A INPUT -p icmp -j DROP
tail -f /var/log/ha-log
此时 看到主死掉,从激活。访问页面 已经显示 slave
打开 icmp :iptables -D INPUT -p icmp -j DROP
或者:
/etc/init.d/heartbeat stop
此时 看到主死掉,从激活。访问页面 已经显示 slave