Redis 3.0.7 Sentinel-based high-availability installation and configuration

Source: Internet
Author: User
Tags failover

Must be high availability in the production scenario, or the problem will cause the service to stop. Here is a description of the high availability of the Sentinel features of Redis and, of course, the cluster capabilities provided by Redis.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7C/B0/wKioL1bWWbSz9bo5AAA2GOYNda8314.jpg "title=" Qq20160302110852.jpg "alt=" Wkiol1bwwbsz9bo5aaa2goynda8314.jpg "/>


Installation of 1.Redis

wget http://download.redis.io/releases/redis-3.0.7.tar.gztar zxf redis-3.0.7.tar.gzcd redis-3.0.7makecd srcmkdir-p/  Usr/local/redis3.0.7/{sbin,data,conf}scp-r mkreleasehdr.sh Redis-benchmark redis-check-aof redis-check-dump Redis-cli Redis-sentinel redis-server LOCALHOST:/USR/LOCAL/REDIS3.0.7/SBINCP. /redis.conf/usr/local/redis3.0.7/conf/echo ' path= $PATH:/usr/local/redis3.0.7/sbin ' >>/etc/profilesource/ Etc/profile

Configuration of 2.Redis

Vim/usr/local/redis3.0.7/conf/redis.conf

(The configuration of DB1, theconfiguration of DB2 only need to add a line slaveof 192.168.2.241 6379)

#是否以服务方式开启daemonize  nopidfile /var/run/redis.pid# Port port 6379tcp-backlog 511timeout  0tcp-keepalive 0# log alert level loglevel notice# log file path logfile  "" #数据库数量databases  16# Log refresh policy (master disabled) save 900 1# Description 1 changes in 900 seconds, save the dataset automatically once save 300 10save 60  10000stop-writes-on-bgsave-error yes# whether to compress Rdbcompression yes#rdb if it is stored as an RDB check rdbchecksum yes# Data file name dbfilename dump.rdb# data file path dir /usr/local/redis3.0.7/dataslave-serve-stale-data yes# From the server read-only slave-read-only yes# specifies the password authentication required to connect to the primary database, and the main library does not have to be set #masterauth#masterauthrepl-diskless-sync  norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100## Enable incremental (master disabled) appendonly no# Delta log file name, default value is appendonly.aofappendfilename  "appendonly.aof" #设置对   The frequency at which the appendonly.aof  files are synchronized #always  indicates that each write operation is synchronized,everysec  means that the write is accumulated and synchronized once per second. #no表示等操作系统进行数据缓存同步到磁盘, all synchronous,everysec  means that the write operation is tired # product, synchronized once per second APPENDFSYNC EVERYSECNO-APPENDFSYNC-ON-REWRite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated  Yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold  0notify-keyspace-events  "" hash-max-ziplist-entries 512hash-max-ziplist-value  64list-max-ziplist-entries 512list-max-ziplist-value 64set-max-intset-entries  512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes  3000activerehashing yesclient-output-buffer-limit normal 0 0  0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub  32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes# maximum available memory #maxmemory 2mb# configured as slave server # slaveof 192.168.2.250 6379# Client Connection access password # requirepass foobared# limits the number of simultaneous clients, preventing excessive client memory exhaustion. If enough memory is available, do not set the # #maxclients 10000

Configuration of 3.Sentinel

Vim/usr/local/redis3.0.7/conf/sentinel.conf
Port 26379sentinel Monitor Master 192.168.2.241 6379 2sentinel down-after-milliseconds Master 5000sentinel Failover-timeout Master 900000#sentinel can-failover Master Yessentinel Parallel-syncs Master * Generated by CONFIG Rewri Tedir "/usr/local/redis3.0.7/conf" #sentinel client-reconfig-script master/usr/local/redis3.0.7/sbin/vip.sh

4. Start Redis-server and Redis-sentinel

Start Redis-server and Redis-sentinel separately on DB1,DB2,DB3

/usr/local/redis3.0.7/sbin/redis-server/usr/local/redis3.0.7/conf/redis.conf/usr/local/redis3.0.7/sbin/ Redis-sentinel/usr/local/redis3.0.7/conf/sentinel.conf

This time has been done Redis master-slave replication and failover, our client connection needs to be modified, so it involves VIP issues, the client as long as the VIP connection, the current VIP solution has

    1. Set with Redis-sentinel's Sentinel Client-reconfig-script parameter

    2. Using Keepalived for VIP transfer

    3. Use Consul for service registration


A. Use the parameters of the Redis-sentinel to configure the VIP

Join in the sentinel.conf of DB1,DB2

Sentinel Client-reconfig-script master1/usr/local/redis3.0.7/sbin/vip.sh

Then create the script/usr/local/redis3.0.7/sbin/vip.sh

#!/bin/bashmaster_ip=$6local_ip= ' 192.168.2.241 ' #从库修改为192.168.2.242vip= ' 192.168.2.250 ' netmask= ' interface= ' Eth0 ' if [${master_ip} = ${local_ip}];        THEN/SBIN/IP addr Add ${vip}/${netmask} Dev ${interface}/sbin/arping-q-C 3-a ${VIP}-I ${interface} Exit 0else/sbin/ip addr del ${vip}/${netmask} dev ${interface} exit 0fiexit 1

You need to manually add a VIP when the cluster starts

/SBIN/IP addr Add 192.168.2.250/24 dev eth0

Use the above script when you need to be aware that your network card is eth0, otherwise the VIP can not use the situation


B. Using keepalived for VIP switching

wget Http://www.keepalived.org/software/keepalived-1.2.19.tar.gztar zxf KEEPALIVED-1.2.19.TAR.GZCD Keepalived-1.2.19./configure--prefix=/usr/local/keepalived1.2.19--disable-fwmarkmake && make Installln-s/ Usr/local/keepalived1.2.19/sbin/keepalived/usr/sbin/ln-s/usr/local/keepalived1.2.19/etc/sysconfig/keepalived/ Etc/sysconfig/ln-s/usr/local/keepalived1.2.19/etc/keepalived//etc/keepalivedln-s/usr/local/keepalived1.2.19/ etc/rc.d/init.d/keepalived/etc/init.d/

keepalived configuration file for DB1

! configuration file for keepalived     global_defs {         notification_email {           [email protected]        }         notification_email_from [email protected]         smtp_server 127.0.0.1        smtp_connect _timeout 10        router_id keepalivedha_1      }     vrrp_script chk_redis_role {          script  "/usr/local/redis3.0.7/sbin/redis-cli info |  Grep role:master >/dev/null 2>&1 "          interval 1         timeout 2          fall 2         rise 1     }      vrrp_sync_group VG_1 {          group {             VI_1          }     }      vrrp_instance vi_1 {         state backup          interface eth0           #use_vmac  keepalived          #vmac_xmit_base          smtp_alert          virtual_router_id 20        priority 100          advert_int 1         authentication {              auth_type PASS              auth_pass password          }         virtual_ipaddress  {             192.168.2.250     }         track_script {              chk_redis_role          }     }

DB2 configuration file, just copy the above files and modify the parameters below.

Priority 98

#注意一下interface eth0 look at your machine's NIC interface


C. Registering with Consul Services

Reference: http://dgd2010.blog.51cto.com/1539422/1745314


The above three methods can be seen above:

The script is the same as the keepalived, but the script is relatively lightweight, the first boot hassle, the configuration simple, and relies on Redis-sentinel

Keepalived simple to start, easy to debug

Consul is suitable for large-scale scenarios, and the cloud environment does not have redundant IP this situation


The above also applies to 2 server scenarios, or 3 servers are not available. Only need to change

Sentinel Monitor Master 192.168.2.241 6379 1

Change the face value to 1

This article is from "Maple Night" blog, please be sure to keep this source http://fengwan.blog.51cto.com/508652/1746731

Redis 3.0.7 Sentinel-based high-availability installation and configuration

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.