redis: two principals and two subordinates

Keywords: Linux Redis yum vim firewall

  1. Monitoring: Sentinel constantly checks whether your master and slave servers are functioning properly.
  2. Notification: Sentinel can send notifications to administrators or other applications through the API when a Redis server being monitored has problems.
    1. Automatic failover: When a primary server does not work properly, Sentinel starts an automatic failover operation, which upgrades one of the failed primary servers from a slave server to a new master server, and changes the other slave servers of the failed primary server to replicate a new master service. Server; When the client tries to connect to the failed primary server, the cluster will also return the address of the new primary server to the client, so that the cluster can use the new primary server instead of the failed server.

Next we prepare two machines, ip is
192.168.124.148
192.168.124.82

Installation environment and tools required
mkdir  -p  /data/server
cd /data/server
yum -y install wget vim tcl gcc make
Download redis installation package

wget http://download.redis.io/releases/redis-3.2.10.tar.gz
tar -zxvf redis-3.2.10.tar.gz
 After decompression, move the previously installed package to the / usr/local/src directory
cd redis-3.2.10
 Compile source files
make
cd src
make install
 Test it: make test
 (If there are no redis-server files in the / usr/local/bin/folder, copy them from / data/server/redis-3.2.10/src/. Command: CP redis-server redis-cli redis-sentinel redis-benchmark redis-check-aof redis-check-rdb/usr/local/bin/)

Create multi-instance folders to store configuration files for different instances

cd /data/server

mkdir cluster

cd cluster

mkdir 6379 6380 We created two folders here 6379 is the main 6380 from

``` Copy Configuration File 148 This machine is Big Brother doesn't need Sentinels, so don't copy it.

cp /data/server/redis-3.2.10/redis.conf /data/server/cluster/6379
cp /data/server/redis-3.2.10/redis.conf /data/server/cluster/6380
cp /data/server/redis-3.2.10/sentinel.conf /data/server/cluster/6380

+++++++++++++++++++++++++++++++++++++Above configuration another machine synchronization
//Configuration 192.168.124.148 machines
cd /data/server/cluster/6379
![](https://s1.51cto.com/images/blog/201908/14/a24649461adf06ec1d0a972a2bb02d44.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

//According to the configuration as shown in the figure (Individuals have removed both comments and blank lines)

![](https://s1.51cto.com/images/blog/201908/14/731e75c1d61e4120e982a81fc5a6e3ff.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

cd /data/server/server/cluster/6380
![](https://s1.51cto.com/images/blog/201908/14/b2c9ebd0cde555037e67f0f937a8793c.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

//According to the configuration as shown in the figure (Individuals have removed both comments and blank lines)
![](https://s1.51cto.com/images/blog/201908/14/c0377362876d5a71bf39d432d303bf9f.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

//Configure Sentinels

![](https://s1.51cto.com/images/blog/201908/14/9af26c844c006ab9a2b51e7a45c1600e.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

3 The configuration files for each sentry are the same (Big Brother can have no sentry)
![](https://s1.51cto.com/images/blog/201908/14/82241e03c89d2d73109c65613d530871.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

//Configuration 192.168.124.82 Machine
cd /data/server/cluster/6379

![](https://s1.51cto.com/images/blog/201908/14/a24649461adf06ec1d0a972a2bb02d44.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

//According to the configuration as shown in Figure (Individual removed comments and empty lines) (standby master configuration)
![](https://s1.51cto.com/images/blog/201908/14/c8d54eeb1631f7acedd9412c66ada133.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

//Configure Sentinels
cd /data/server/server/cluster/6379
![](https://s1.51cto.com/images/blog/201908/14/c87073ded66fa7d0a5f921113b78e53a.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

![](https://s1.51cto.com/images/blog/201908/14/82241e03c89d2d73109c65613d530871.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

cd /data/server/cluster/6380
![](https://s1.51cto.com/images/blog/201908/14/b2c9ebd0cde555037e67f0f937a8793c.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

//According to the configuration as shown in the figure (Individuals have removed both comments and blank lines)

![](https://s1.51cto.com/images/blog/201908/14/c0377362876d5a71bf39d432d303bf9f.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

//Configuration of Sentinels
cd /data/server/server/cluster/6379

![](https://s1.51cto.com/images/blog/201908/14/c87073ded66fa7d0a5f921113b78e53a.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

++++++++++++++++++++

//Next we open redis and sentry

192.168.124.148
redis-server /data/server/cluster/6379/redis.conf
redis-server /data/server/cluster/6380/redis.conf
redis-sentinel /data/server/cluster/6380/sentinel.conf

![](https://s1.51cto.com/images/blog/201908/14/0fe45d8178ee6ee8523304708945a228.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

192.168.124.82
redis-server /data/server/cluster/6379/redis.conf
redis-server /data/server/cluster/6380/redis.conf
redis-sentinel /data/server/cluster/6379/sentinel.conf
redis-sentinel /data/server/cluster/6380/sentinel.conf

![](https://s1.51cto.com/images/blog/201908/14/a1069739b53f682b477f5f904a4df346.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

//Close the firewall
systemctl stop firewalld
setenforce 0

//Next, let's do a test.
//Looking at the two machines, did the service start?
ps aux | grep redis
//Look at the connection again.
![](https://s1.51cto.com/images/blog/201908/14/c09eb69b5e642e0ae4f9eb4f8cd38fc3.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
//Write redis in environmental variables first.
![](https://s1.51cto.com/images/blog/201908/14/77fb2621a87f2591aa0aea346a885457.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

source /etc/profile  Reread the configuration file

redis-cli -h 192.168.124.148 -p 6379
![](https://s1.51cto.com/images/blog/201908/14/366a6a839aaff4c638f2d1c40736fd3e.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

//We killed the boss.
![](https://s1.51cto.com/images/blog/201908/14/c150fc1ce9467923152c4a465c1a75c5.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

//Check out another standby owner
![](https://s1.51cto.com/images/blog/201908/14/f3f5930dadbaf5b45ba38bd211649fba.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

//We found that we are ready to take the lead.

//Now the boss
//Kill the reserve owner and you'll find that the boss is in power again.
//So the master will only switch between the two.
//That's two masters and two subordinates.

Posted by jrottman on Tue, 13 Aug 2019 20:49:55 -0700