升级keepalived与配置
1、分别将keepalived解压到主备机的/home/rzrk目录下
2、分别修改主备机的配置文件/home/rzrk/keepalived/conf/keepalived.conf
注意:interface eth0 写本机的网卡名称 如主备机网卡名分别为eth0 eth1 则track_interface{eth0 eth1}最好这样写。 nopreempt只在主机上写(一定要在主机上写,备机不能写)
通常如果master服务死掉后backup会变成master,但是当master服务又好了的时候 master此时会抢占VIP,这样就会发生两次切换对业务繁忙的网站来说是不好的。所以我们要在配置文件加入 nopreempt 非抢占,但是这个参数只能用于state 为backup,故我们在用的时候最好master 和backup的state都设置成backup 让其通过priority来竞争
虚拟Ip两台机器都一样 和服务器相同网段
分别修改主备机配置文件:
3、脚本添加执行权限(主备机都要做)
chmod +x /home/server/monitor/notify.sh
4、分别修改主备机的配置文件/home/server/monitor/notify.sh(记录主备脚本)
1 #!/bin/bash 2 # 3 4 HOSTSTATUSFILE=/home/rzrk/keepalived/conf/host.status 5 CHECKLOGFILE=/home/rzrk/server/userdata/log/check.log 6 LOGDB='/usr/bin/python /home/rzrk/server/pyScripts/logdb.py' 7 HOSTNAME=`/bin/hostname` 8 9 #enable master_backup mode 1, else 0 10 master_backup=1 11 12 DATETIME=`date "+%Y-%m-%d %T"` 13 if [ "$master_backup" != "1" ] 14 then 15 #only one master 16 echo "do nothing" 17 echo "master" > $HOSTSTATUSFILE 18 19 else 20 echo $1 > $HOSTSTATUSFILE 21 case "$1" in 22 master|backup|fault) 23 SHOWMSG="host:$HOSTNAME enter [ $1 ] status" 24 echo $1 > $HOSTSTATUSFILE 25 echo $DATETIME $SHOWMSG 26 echo $DATETIME $SHOWMSG >> $CHECKLOGFILE 27 $LOGDB "$DATETIME" 1 "$SHOWMSG" 28 29 ;; 30 *) 31 echo "unknow param, " $1 32 ;; 33 esac 34 fi
5、拷贝启动脚本
cp /home/rzrk/keepalived/keepalived /etc/init.d
6、分别启动keepalived
/etc/init.d/keepalived start
7.检查主备机
cat /home/rzrk/keepalived/conf/host.status