Redis High-availability installation notes under CentOS

Source: Internet
Author: User
Tags stop script

(WJW) Redis High-Availability installation notes[x] Introduction to the installation environment:

Master:t1
Slave:t2
vip:192.168.68.45

[x] Installing Redis (master,slave)

Note: modifications to the Flushall before installing Redis

Find src/redis.c files, put

' {"Flushdb", flushdbcommand,1, "W", 0,null,0,0,0,0,0}, '   {"Flushall", flushallcommand,1, "W", 0,null,0,0,0,0,0}, `

Modified to:

' {' Xflushdb ', flushdbcommand,1, ' W ', 0,null,0,0,0,0,0}, '   {' Xflushall ', flushallcommand,1, ' W ', 0,null,0,0,0,0,0 },`
vi/etc/sysctl.conf Add a line: ' Vm.overcommit_memory=1 ' Mkdir/opt/redismkdir/opt/redis/logmkdir/opt/redis/dbtar zxvf. REDIS-2.8.17.TAR.GZCD redis-2.8.17make Prefix=/opt/redis Install
[x] Redis startup script (Master,slave):/opt/redis/bin/startredis.sh
#!/bin/bashbasedir= ' dirname $ ' echo ' Redis BASE DIR: $basedir ' CD $basedirnohup./redis-server./redis.conf >/dev/ Null 2>&1 &
[x] redis Stop script (master,slave):/opt/redis/bin/stopredis.sh
#!/bin/shbasedir= ' dirname $ ' echo ' Redis BASE DIR: $basedir ' CD $basedir./redis-cli-h localhost-a 123456 shutdown
[x] Redis configuration file (master,slave):/opt/redis/bin/redis.conf
#requirepass 123456pidfile/opt/redis/bin/redis.pidlogfile/opt/redis/log/redis.logdir/opt/redis/db/daemonize Yesport 6379timeout 300loglevel warningdatabases 16maxmemory 1g# do not snapshot #save 1#save y 10#save Es#dbfilename dump.rdb# using aofappendonly yesappendfsync everysec
[x] Install keepalived (master,slave):
#wget Http://www.keepalived.org/software/keepalived-1.2.13.tar.gztar zxvf keepalived-1.2.13.tar.gzcd. Keepalived-1.2.13./configuremake make installcp/usr/local/etc/rc.d/init.d/keepalived/etc/rc.d/init.d/cp/usr/ local/etc/sysconfig/keepalived/etc/sysconfig/cp/usr/local/sbin/keepalived/usr/sbin/mkdir/etc/keepalivedcp/usr/ Local/etc/keepalived/keepalived.conf/etc/keepalived/chkconfig--add keepalived#chkconfig--level keepalived on# Service keepalived Start
[x] notify_* explanation
Keepalived is called when the state is converted: when it enters the master state, it calls Notify_master when it enters the backup state and calls Notify_backup when an abnormal condition is found (track_script,track_ Interface failed) Enter fault status call Notify_fault call Notify_stop when keepalived program terminates
[x] Create the following configuration file on master:

vim /etc/keepalived/keepalived.conf

! Configuration File for Keepalivedglobal_defs {notification_email {[email protected]} Notification_email_ From [email protected] smtp_server localhost smtp_connect_timeout router_id lvs_redis}vrrp_script Chk_redis {Script "/etc/keepalived/scripts/redis_check.sh" # # #监控脚本 interval 2 # # #监控时间}VR Rp_instance vi_1 {nopreempt # # #不抢占 to prevent brain fissure state MASTER #备的是BACKUP interface Br0 virtual_router_id 5    1 priority #备的是90 Advert_int 1 Authentication {auth_type PASS auth_pass Redis} virtual_ipaddress {192.168.68.45} track_script {Chk_redis # # #执行上面定义的chk_redi    s} notify_master/etc/keepalived/scripts/redis_master.sh notify_backup/etc/keepalived/scripts/redis_backup.sh Notify_fault/etc/keepalived/scripts/redis_fault.sh notify_stop/etc/keepalived/scripts/redis_stop.sh}
[x] Create the following configuration file on slave:

vim /etc/keepalived/keepalived.conf

! Configuration File for Keepalivedglobal_defs {notification_email {[email protected]} Notification_email_ From [email protected] smtp_server localhost smtp_connect_timeout router_id lvs_redis}vrrp_script Chk_redis {Script "/etc/keepalived/scripts/redis_check.sh" # # #监控脚本 interval 2 # # #监控时间}VR Rp_instance vi_1 {nopreempt # # #不抢占 to prevent brain fissure state BACKUP #备的是BACKUP interface Br0 virtual_router_id 5    1 priority #备的是90 Advert_int 1 Authentication {auth_type PASS auth_pass Redis}     virtual_ipaddress {192.168.68.45} track_script {Chk_redis # # #执行上面定义的chk_redis    } notify_master/etc/keepalived/scripts/redis_master.sh notify_backup/etc/keepalived/scripts/redis_backup.sh Notify_fault/etc/keepalived/scripts/redis_fault.sh notify_stop/etc/keepalived/scripts/redis_stop.sh}
[x] Create a script to monitor Redis on master and slave:

mkdir /etc/keepalived/scripts/
vi /etc/keepalived/scripts/redis_check.sh

#!/bin/bashc_date= ' DATE + ' [%y-%m-%d%h:%m:%s] "' alive= '/opt/redis/bin/redis-cli PING ' if [" $ALIVE "= =" PONG "]; Then  echo "${c_date} $ALIVE"  exit 0else  echo "${c_date} $ALIVE"  exit 1fi
[x] Create the following script in master and slave notify_faultAnd notify_stop

vim /etc/keepalived/scripts/redis_fault.sh

#!/bin/bashc_date= ' DATE + ' [%y-%m-%d%h:%m:%s] "' Logfile=/var/log/keepalived-redis-state.logecho" ${C_DATE} [Fault] " >> $LOGFILE

vim /etc/keepalived/scripts/redis_stop.sh

#!/bin/bashc_date= ' DATE + ' [%y-%m-%d%h:%m:%s] ' Logfile=/var/log/keepalived-redis-state.logecho ' ${C_DATE} [Stop] " >> $LOGFILE
[x] created on master notity_masterAnd notify_backupScript:

vim /etc/keepalived/scripts/redis_master.sh

#!/bin/bashc_date= ' DATE + ' [%y-%m-%d%h:%m:%s] "' rediscli="/opt/redis/bin/redis-cli "logfile="/var/log/ Keepalived-redis-state.log "echo" ${c_date} [Master] ">> $LOGFILE # when keepalived is configured as preemptive, open the following comment #echo" Being Master: ">> $LOGFILE 2>&1#echo" Run slaveof cmd ... ">> $LOGFILE # $REDISCLI slaveof T2 6379 >> $LOGFILE  2>&1#sleep #延迟10秒以后待数据同步完成后再取消同步状态echo "Run slaveof NO one cmd ..." >> $LOGFILE $rediscli SLA veof NO one >> $LOGFILE 2>&1

vim /etc/keepalived/scripts/redis_backup.sh

#!/bin/bashc_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 # When keepalived is configured as preemptive, open the comment below #echo "Being slave ">> $LOGFILE 2>&1#sleep #延迟15秒待数据被对方同步完成之后再切换主从角色echo" Run slaveof cmd ... ">> $LOGFILE $redisc LI slaveof T2 6379 >> $LOGFILE  2>&1
[x] created on slave notity_masterAnd notify_backupScript:

vim /etc/keepalived/scripts/redis_master.sh

#!/bin/bashc_date= ' DATE + ' [%y-%m-%d%h:%m:%s] "' rediscli="/opt/redis/bin/redis-cli "logfile="/var/log/ Keepalived-redis-state.log "echo" ${c_date} [Master] ">> $LOGFILE # when keepalived is configured as preemptive, open the following comment #echo" Being Master: ">> $LOGFILE 2>&1#echo" Run slaveof cmd ... ">> $LOGFILE # $REDISCLI slaveof T1 6379 >> $LOGFILE  2>&1#sleep #延迟10秒以后待数据同步完成后再取消同步状态echo "Run slaveof NO one cmd ..." >> $LOGFILE $rediscli SLA veof NO one >> $LOGFILE 2>&1

vim /etc/keepalived/scripts/redis_backup.sh

#!/bin/bashc_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 # When keepalived is configured as preemptive, open the comment below #echo "Being slave ">> $LOGFILE 2>&1#sleep #延迟15秒待数据被对方同步完成之后再切换主从角色echo" Run slaveof cmd ... ">> $LOGFILE $redisc LI slaveof T1 6379 >> $LOGFILE  2>&1
[x] on Master and slave, add executable permissions to the monitoring script:

chmod +x /etc/keepalived/scripts/*.sh

[x] Start step:
    1. To start Redis on master
      /opt/redis/bin/startRedis.sh

    2. Start Redis on the slave
      /opt/redis/bin/startRedis.sh

    3. Start the keepalived on master
      service keepalived start

    4. Start the keepalived on the slave
      service keepalived start

Redis High-availability installation notes under CentOS

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.