Set up the Redis primary/secondary cluster + sentinel mode architecture to realize high availability of Redis

This is the 15th day of my participation in the More text Challenge. For more details, see more text Challenge

Like is the best encouragement to create!

The environment that

Master (master): 10.28.207.98:6379 Slave (slave): 10.28.207.103:6380 10.28.207.221:6381 10.28.207.221 10.28.207.98:26379 10.28.207.103:26380:26381Copy the code

Deploying the Redis active node (10.28.207.98:6379)

First copy the Redis installation package and TCL installation package to the server to be installed

  1. Install TCL (Redis dependencies)
CD /data/Software tar -xzvf tcl8.6.1-src.tar.gz CD tcl8.6.1/ Unix /./configure make make installCopy the code
  1. Install redis
CD /data/Software/ tar-zxvf redis-4.0.0.tar. gz CD redis-4.0.10/ make make test make PREFIX=/data/redis-4.0.10-6379 installCopy the code
  1. Create the Redis log directory and log files
Mkdir/data/logs/redis - 4.0.10-6379 touch/data/redis - 4.0.10-6379 / logs/redis. LogCopy the code
  1. Copy the redis.conf configuration file to the redis installation directory
Conf /data/redis-4.0.10-6379/bin/Copy the code
  1. Modify the primary Redis profile
Vim /data/redis-4.0.10-6379/bin/redis.conf 5.1, comment out bind #bind 127.0.0.1 5.2, change the primary redis port to 6379 port 6379 5.3, change the protected mode Protect-mode yes 5.4 Change the daemon mode daemonize yes 5.5 Add master password requirepass dataadmin 5.6 and slave password masterauth dataadmin Change the redis log output directory to logfile "/data/redis-4.0.10-6379/logs/redis.log min-slaves-max-lag 10Copy the code
  1. Start the main redis – 6379
CD/data/bin/redis - 4.0.10-6379 /. / redis - for server/redis. ConfCopy the code
  1. View the Redis startup logs
tail -100f .. /logs/redis.logCopy the code
  1. Log in to the primary redis-6379(note: the redis server already has a password configured on the step 5 configuration file, and the other secondary servers also need a password, the password is dataadmin)
/redis-cli -h 10.28.207.98 -p 6379 auth dataadminCopy the code
  1. Test whether redis is available (get name)
set name data
get name
Copy the code
  1. Close the redis – 6379
./redis-cli -p 6379
auth dataadmin
shutdown
Copy the code

Deploy Redis slave nodes (10.28.207.103:6380 and 10.28.207.221:6381) on 158 and 159, respectively.

  1. Copy the primary redis directory from server 10.28.207.98 to server 103 and 221

  2. Modified 103 from the Redis profile

Vim /data/redis-4.0.10-6380/bin/redis.conf 2.1, change the redis port to 6380 port 6380 2.2, change the redis log output directory logfile "/data/redis-4.0.10-6380/logs/redis.log" 2.3 add slaveof 10.28.207.98 6379Copy the code
  1. Modify 221 from the redis profile
Vim /data/redis-4.0.10-6381/bin/redis.conf 3.1 change the redis port to port 6381 6381 3.2 Change the redis log output directory logfile "/data/redis-4.0.10-6381/logs/redis.logCopy the code
  1. Log in the main redis – 6379
/redis-cli -h 10.28.207.98 -p 6379 auth dataadmin Starting and logging in to the secondary server is not much different from that of the primary server. You only need to change the corresponding server IP address and port numberCopy the code
  1. View the primary Redis information
Info Replication If information similar to the following is displayed, the configuration is successful. Connected_slaves :2 # = 10.28.207.103 slave0: IP and port = 6380, state = online, offset = 408296595, lag = 1 = 10.28.207.221 slave1: IP and port = 6381, state = online, offset = 408296595, lag = 1Copy the code
  1. Test whether the primary Redis is available
/redis-cli -h 10.28.207.98 -p 6379 auth dataadmin set phone 123456./redis-cli -h 10.28.207.98 -p 6379 auth dataadmin set phone 123456 /redis-cli -h 10.28.207.103 -p 6380 auth dataadmin get phone 6.3 logging in to redis-6381 /redis-cli -h 10.28.207.221 -p 6381 auth dataadmin Get phone./redis-cli -h 10.28.207.221 -p 6381 auth dataadmin Get phoneCopy the code

If you set the phone value on the primary Redis, and then obtain the value from the server, the redis master/slave deployment is successful and available!

Deploy three Sentinels

  1. Copy the sentinel.conf configuration file to the primary redis-6379 directory
CD /data/Software/redis-4.0.10/ cp sentinel.conf /data/redis-4.0.10-6379/bin/Copy the code
  1. Create the sentinel.log log file
Touch/data/redis - 4.0.10-6379 / logs/sentinel. LogCopy the code
  1. Modify the Sentinel configuration file
Vim/data/redis - 4.0.10-6379 / bin/sentinel. ConfCopy the code
  • Clear the contents and replace them with the following configuration
Daemonize yes # protected-mode no #bind 127.0.0.1 to receive requests from this IP address # Mymaster 10.28.207.98 6379 2 # Mymaster is not responding within 3s Think mymaster down sentinel down - after - milliseconds mymaster # 3000 if, after 10 seconds mysater still didn't start to come over, Failover sentinel failover mymaster 10000 # Up to 1 slave server synchronizes sentinel PARALLel-syncs Mymaster 1 # Sentinel log logfile to the new master server simultaneously "/data/redis-4.0.10-6379/logs/sentinel.log" /data/redis-4.0.10-6379/logs/sentinel.log Sentinel Auth-pass mymaster dataAdmin # EndCopy the code
  1. Copy the 10.28.207.98 sentinle.conf configuration file to /data/redis-4.0.10-6380/bin on servers 103 and 221

  2. Create the sentinel.log log file on 103

Touch/data/redis - 4.0.10-6380 / logs/sentinel. LogCopy the code
  1. Modify the sentinel configuration file sentinel.conf on 103
Vim /data/redis-4.0.10-6380/bin/sentinel.conf 6.1 Change the port of Sentinel to 26380 port 26380 6.2 Change the log output directory logfile of Sentinel "/ data/redis - 4.0.10-6380 / logs/sentinel. Log"Copy the code
  1. Create the sentinel.log log file in 221
Touch/data/redis - 4.0.10-6381 / logs/sentinel. LogCopy the code
  1. Modify the sentinel configuration file sentinel.conf on 221
Vim /data/redis-4.0.10-6381/bin/sentinel.conf 8.1 change the port of Sentinel to 26381 port 26381 8.2 change the output directory of Sentinel logs to logfile "/ data/redis - 4.0.10-6381 / logs/sentinel. Log"Copy the code

Start and test the three Sentinels

  1. Start Sentinel-26379 on 98
CD /data/redis-4.0.10-6379/bin/./redis-server./ sentinel-conf --sentinel tail-100f.. /logs/sentinel.logCopy the code

2. Activate Sentinel-26380 on 103

CD /data/redis-4.0.10-6380/bin/./redis-server./sentinel.conf --sentinel tail-100f.. /logs/sentinel.logCopy the code
  1. Activate Sentinel-26381 on 221
CD /data/redis-4.0.10-6381/bin/./redis-server./ sentinel-conf --sentinel tail-100f.. /logs/sentinel.logCopy the code
  1. Log on to Sentinel-26379 on 98 to see what other sentinels are detected
/ redis-cli-h 10.28.207.98-p 26379 Sentinel Sentinels MymasterCopy the code

If the remaining two sentries of the configuration are displayed, the configuration is successful