标签:redis keepalived
keepalived配置文件 主从配置一样,需要修改优先级
global_defs { router_id REDIS05 } vrrp_instance VI_5 { state BACKUP interface bond0 virtual_router_id 85 priority 150 authentication { auth_type PASS auth_pass redis10 } advert_int 2 virtual_ipaddress { 1.1.1.1 } notify_master /data/scripts/redis_master.sh notify_backup /data/scripts/redis_backup.sh notify_fault /data/scripts/redis_fault.sh notify_stop /data/scripts/redis_stop.sh }
四个redis脚本的内容
[root@BJ-M5-GXH-REDIS-20-12 scripts]# cat redis_backup.sh #!/bin/bash REDISCLI="/data/server/redis/bin/redis-cli" LOGFILE="/data/logs/redis/keepalived-redis-state.log" echo "[backup]" >> $LOGFILE date >> $LOGFILE echo "Being slave...." >> $LOGFILE 2>&1 #sleep 25 echo "Run SLAVEOF cmd ..." >> $LOGFILE $REDISCLI -p 6359 SLAVEOF 1.1.1.1 6359 >> $LOGFILE 2>&1 [root@BJ-M5-GXH-REDIS-20-12 scripts]# cat redis_fault.sh #!/bin/bash LOGFILE="/data/logs/redis/keepalived-redis-state.log" echo "[fault]" >> $LOGFILE date >> $LOGFILE [root@BJ-M5-GXH-REDIS-20-12 scripts]# cat redis_master.sh #!/bin/bash REDISCLI="/data/server/redis/bin/redis-cli" LOGFILE="/data/logs/redis/keepalived-redis-state.log" echo "[master]" >> $LOGFILE date >> $LOGFILE echo "Being master...." >> $LOGFILE 2>&1 echo "Run SLAVEOF NO ONE cmd ..." >> $LOGFILE $REDISCLI -p 6359 SLAVEOF NO ONE >> $LOGFILE 2>&1 [root@BJ-M5-GXH-REDIS-20-12 scripts]# cat redis_stop.sh #!/bin/bash LOGFILE="/data/logs/redis/keepalived-redis-state.log" echo "[stop]" >> $LOGFILE date >> $LOGFILE
附带一个备份脚本
#!/bin/bash #global dir variables dir="/data/server/redis/data/" backup_dir="/data/backups/redis/" #global backup file name file_name="redis-jzpush01-6359-dump.rdb" #section backup time section=`date +%y%m%d%H` #execute backup /data/server/redis/bin/redis-cli -p 6359 BGSAVE /bin/cp -f $dir/$file_name $backup_dir/$file_name.${section} /usr/bin/find $backup_dir -type f -ctime +2 | xargs -n 1 rm -f
标签:redis keepalived
原文地址:http://kkkkkk.blog.51cto.com/468162/1618524