vim /etc/keepalived/scripts/redis_backup.sh
#!/bin/bash C_DATE=`date +"[%Y-%m-%d %H:%M:%S]"` REDISCLI="/opt/redis/bin/redis-cli" LOGFILE="/var/log/keepalived-redis-state.log" echo "${C_DATE} [backup]" >> $LOGFILE #当keepalived配置为"抢占式"时,打开下面注释 #echo "Being slave...." >> $LOGFILE 2>&1 #sleep 15 #延迟15秒待数据被对方同步完成之后再切换主从角色 echo "Run SLAVEOF cmd ..." >> $LOGFILE $REDISCLI SLAVEOF T1 6379 >> $LOGFILE 2>&1 [x] 在Master和Slave上,给监控脚本都加上可执行权限:chmod +x /etc/keepalived/scripts/*.sh
[x] 启动步骤:
启动Master上的Redis
/opt/redis/bin/startRedis.sh
启动Slave上的Redis
/opt/redis/bin/startRedis.sh
启动Master上的Keepalived
service keepalived start
启动Slave上的Keepalived
service keepalived start
下面关于Redis的文章您也可能喜欢,不妨参考下:
Ubuntu 14.04下Redis安装及简单测试