keepalived configuration file Master-slave configuration, need to modify the priority
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 }
Contents of four Redis scripts
[[email protected] scripts]# cat redis_backup.sh #!/bin/bash rediscli= "/data/server/redis/bin/redis-cli" logfile= "/data/logs/redis/ Keepalived-redis-state.log " echo " [Backup] " >> $LOGFILEdate >> $LOGFILEecho "Being slave ..." >> $ logfile 2>&1#sleep 25echo "run slaveof cmd  ..." >> $ logfile$rediscli -p 6359 slaveof 1.1.1.1 6359 >> $LOGFILE 2>&1[[email protected] scripts]# cat redis_fault.sh#!/bin/bashlogfile= "/data/ Logs/redis/keepalived-redis-state.log "echo " [Fault] " >> $LOGFILEdate >> $ logfile[[email protected] scripts]# cat redis_master.sh #!/bin/bash &nbSp Rediscli= "/data/server/redis/bin/redis-cli" logfile= "/data/logs/redis/keepalived-redis-state.log" echo "[Master]" >> $LOGFILEdate >> $LOGFILEecho "Being master ..." >> $LOGFILE 2>&1echo "Run slaveof no one cmd  >> $LOGFILE $rediscli -p 6359 slaveof no one >> $LOGFILE 2>&1[[email protected] Scripts]# cat redis_stop.sh #!/bin/bashlogfile= "/data/logs/redis/keepalived-redis-state.log" echo "[Stop]" >> $LOGFILEdate >> $LOGFILE
Comes with a backup script
#!/bin/bash#global dir variablesdir= "/data/server/redis/data/" backup_dir= "/data/backups/redis/" #global backup file Namefile_name= "Redis-jzpush01-6359-dump.rdb" #section backup timesection= ' 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
Heepalived+redis to do dual machine hot standby