Heepalived+redis to do dual machine hot standby

Source: Internet
Author: User

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&nbsp ..."  >> $ 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&nbsp  >>  $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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.