Redis+sentinel cluster installation and configuration _redis

Source: Internet
Author: User
Tags failover lua redis cluster

1. Introduction to the Environment

Cluster Machine Redis Service Sentinel (Sentinel) node Describe

Virtual machine: 192.168.20.105 installation Redis service, Port 6379 installation Sentinel service, Port 26379 master node

Virtual machine: 192.168.20.29 installation Redis service, Port 6379 installation Sentinel service, port 26379 from node

Virtual machine: 192.168.20.108 installation Redis service, Port 6379 installation Sentinel service, port 26379 from node

namely: 3 Redis Service, three Sentinel service, 192.168.20.105 as the main node, implementation according to the article introduced configuration good master-slave relationship.

2. Related Start command

The CD to/usr/redis/bin directory can perform the following commands:

redis-server/usr/redis/etc/redis.conf# Start Redis Service

./redis-sentinel/usr/redis/etc/sentinel.conf# Start Sentinel Sentinel Service

./redis-cli-p 6379-a 123456# Open the native Redis client connection, and then execute the commands such as set, get, keys, and so on

Ps-ef|grep redis# View Redis status

3. configuration file

Virtual machine: 192.168.20.105

redis.conf configuration file:

[plain]  View plain  copy daemonize yes# background start    pidfile  "/var/run/redis.pid"     port 6379   timeout 0   tcp-keepalive 0   Loglevel notice    logfile  ""    databases 16   save 900 1   save  300 10   save 60 10000   stop-writes-on-bgsave-error yes   rdbcompression yes   rdbchecksum yes   dbfilename  "Dump.rdb"    dir   "/usr/redis/data"    masterauth  "123456" #如果做故障切换, regardless of the master and subordinate node to fill in the password and to keep the same    slave-serve-stale-data yes   slave-read-only yes   repl-disable-tcp-nodelay  no   slave-priority 98   requirepass  "123456" #当前redis密码    appendonly  yes   # appendfsync always   appendfsync everysec   #  Appendfsync no   no-appendfsync-on-rewrite no   auto-aof-rewrite-percentage 100    auto-aof-rewrite-min-size 64mb   lua-time-limit 5000   slowlog-log-slower-than 10000   slowlog-max-len 128   notify-keyspace-events  ""    hash-max-ziplist-entries 512   hash-max-ziplist-value 64   list-max-ziplist-entries 512   list-max-ziplist-value 64   set-max-intset-entries  512   zset-max-ziplist-entries 128   zset-max-ziplist-value 64   activerehashing yes   client-output-buffer-limit normal 0 0 0   client-output-buffer-limit slave 256mb 64mb 60   client-output-buffer-limit  pubsub 32mb 8mb 60   hz 10   Aof-rewrite-incremental-fsync yes    # generated by config rewrite   sentinel.conf configuration file:

[plain]  View Plain  copy port 26379   sentinel monitor mymaster  192.168.20.105 6379 2#2 indicates that if two nodes in the Sentinel cluster detect the failure of the Redis primary node to switch, the single sentinel node is not valid (oneself test discovery)    sentinel down-after-milliseconds mymaster 3000# If MyMaster is not responding in 3s, it is considered MyMaster downtime    sentinel failover-timeout mymaster 10000# If 10 seconds later, Mysater still not alive, then start failover   Sentinel  auth-pass mymaster 123456#redis Master node password    sentinel config-epoch mymaster  89   daemonize yes   dir  "/usr/redis/bin" #指定工作目录    sentinel  Known-slave mymaster 192.168.20.29 6379#sentinel Auto-generated    Sentinel known-slave  mymaster 192.168.20.108 6379#sentinel Auto-generated    sentinel known-sentinel  Mymaster 192.168.20.108 26379 695a7bf69bf7c0bdacb3a01ea262319cfca85de9#sentinel Auto-generated        # generated by config rewrite      sentinel known-sentinel mymaster  192.168.20.29 26379 b1fba42ff8b363b2aea5c52e5dfa2c1ae52869e9#sentinel Auto-generated   

Virtual machine: 192.168.20.29

redis.conf configuration file:

[plain]  View plain  copy daemonize yes   pidfile  "/var/run/redis.pid"    port 6379   timeout 0   tcp-keepalive 0   loglevel notice    logfile  ""    databases 16   save 900 1   save 300  10   save 60 10000   stop-writes-on-bgsave-error yes   rdbcompression yes   rdbchecksum yes   dbfilename  "Dump.rdb"    dir   "/usr/redis/data"    masterauth  "123456" #主节点密码    Slave-serve-stale-data yes    slave-read-only yes   repl-disable-tcp-nodelay no   slave-priority  98   requirepass  "123456"    appendonly yes   # appendfsync  always   appendfsync everysec   # appendfsync no   no-appendfsync-on-rewrite no   auto-aof-rewrite-percentage 100   auto-aof-rewrite-min-size  64mb   lua-time-limit 5000   slowlog-log-slower-than 10000   slowlog-max-len 128   notify-keyspace-events  ""    hash-max-ziplist-entries  512   hash-max-ziplist-value 64   list-max-ziplist-entries 512   list-max-ziplist-value 64   set-max-intset-entries 512   zset-max-ziplist-entries  128   zset-max-ziplist-value 64   activerehashing yes   client-output-buffer-limit normal 0 0 0   Client-output-buffer-limit slave  256mb 64mb 60   client-output-buffer-limit pubsub 32mb 8mb 60    hz 10   aof-rewrite-incremental-fsync yes   # generated by  config rewrite &nBsp    slaveof 192.168.20.105 6379# Configure the master node information    sentinel.conf profile (basically the same as the primary node, please note the comparison):
[plain]  View Plain  copy port 26379   sentinel monitor mymaster  192.168.20.105 6379 2   sentinel down-after-milliseconds mymaster 3000    sentinel failover-timeout mymaster 10000   Sentinel auth-pass mymaster  123456   sentinel config-epoch mymaster 89   daemonize yes    dir  "/usr/redis/bin"    sentinel known-slave mymaster 192.168.20.108  6379   sentinel known-slave mymaster 192.168.20.29 6379   sentinel  Known-sentinel mymaster 192.168.20.108 26379 695a7bf69bf7c0bdacb3a01ea262319cfca85de9       # generated by config rewrite      Sentinel  known-sentinel mymaster 192.168.20.105 26379  a8d94fbe0f1120278136c84a612ea84d57d2501c  

Virtual machine: 192.168.20.108

redis.conf configuration file:

[plain]  View plain  copy daemonize yes   pidfile  "/var/run/redis.pid"    port 6379   timeout 0   tcp-keepalive 0   loglevel notice    logfile  ""    databases 16   save 900 1   save 300  10   save 60 10000   stop-writes-on-bgsave-error yes   rdbcompression yes   rdbchecksum yes   dbfilename  "Dump.rdb"    dir   "/usr/redis/data"    masterauth  "123456"    slave-serve-stale-data yes    slave-read-only yes   repl-disable-tcp-nodelay no   slave-priority 100    requirepass  "123456"    appendonly yes   # appendfsync always    appendfsync everysec   # appendfsync no   No-appendfsync-on-rewrite no   auto-aof-rewrite-percentage 100   AUTO-AOF-REWRITE-MIN-SIZE 64MB    lua-time-limit 5000   slowlog-log-slower-than 10000   Slowlog-max-len  128   notify-keyspace-events  ""    hash-max-ziplist-entries 512   hash-max-ziplist-value 64   list-max-ziplist-entries 512   List-max-ziplist-value  64   set-max-intset-entries 512   zset-max-ziplist-entries 128   zset-max-ziplist-value 64   activerehashing yes   client-output-buffer-limit  normal 0 0 0   client-output-buffer-limit slave 256mb 64mb 60    client-output-buffer-limit pubsub 32mb 8mb 60   hz 10    aof-rewrite-incremental-fsync yes   # generated by config rewrite      slaveof 192.168.20.105 6379   sentinel.conf profile (basically the same as the primary node, please note the comparison):

[plain]  View Plain  copy port 26379   sentinel monitor mymaster  192.168.20.105 6379 2   sentinel down-after-milliseconds mymaster 3000    sentinel failover-timeout mymaster 10000   Sentinel auth-pass mymaster  123456   sentinel config-epoch mymaster 89   daemonize yes    dir  "/usr/redis/bin"    sentinel known-slave mymaster 192.168.20.108  6379   sentinel known-slave mymaster 192.168.20.29 6379   sentinel  known-sentinel mymaster 192.168.20.105 26379 a8d94fbe0f1120278136c84a612ea84d57d2501c       # generated by config rewrite      Sentinel  known-sentinel mymaster 192.168.20.29 26379 b1fba42ff8b363b2aea5c52e5dfa2c1ae52869e9   

4.sentinel support Cluster (nonsense)

Even if some of the sentinel process is down, it is still possible to make the main standby switch of the Redis cluster;
If there is only one sentinel process, if the process runs wrong, or if the network is blocked, then the primary standby switching of the Redis cluster will not be realized (single point problem);
If you have more than one Sentinel,redis client can easily connect to any of the Sentinel to get information about the Redis cluster. 5. Supplementary notes

The above configuration file except added the annotation place, the other place basically all is redis automatically generates, just pay attention to the point that adds annotation.

There may be problems with failover during configuration, most likely because the master node password is not configured in the primary node configuration file because the Sentinel does not automatically add a new master node password to the master node configuration file.

Redis current replication is asynchronous, only to ensure final consistency, rather than strong consistency (master and subordinate database updates or Piontes, after the). If the consistency requires high application, the current or read and write are in the main library.

If you want to say it clearly Sentinel realize Redis switching principle that is: Sentinel Heartbeat detects the main node after the exception, through the change redis.conf configuration file to achieve Redis between master and slave node failover.

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.