Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use three redis as master and slave + Sentinel function

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you how to use the three redis master-slave + Sentinel function, I hope you will gain something after reading this article, let's discuss it together!

I. background note

Here, a redis cluster with one master and two slaves and three sentinel are used to build a highly available redis cluster.

Four functions of redis-sentinel:

Notification: when there is a problem with a monitored Redis instance, you can notify the system administrator and other applications through API. Monitoring: the Sentinel constantly checks whether master and slave are working properly. Automatic failover: if a master is not working properly, the Sentinel can start a failover process, upgrade one slave to master, the other slave is reconfigured to use the new master, and the application uses the new address notified by the Redis server. Configuration provider: the Sentinel serves as the authoritative source of Redis client discovery: the client connects to the address of the currently reliable master requested by the Sentinel. In the event of a failure, the sentry will report the new address. 2. Install redis master and slave

1. Install the redis environment

Latest installation package: redis-5.0.7.tar.gz

System: Linux

2. Operation steps

Step 1: download the installation package on windows to Linux locally by remote mount.

Step 2: install the compilation tool

1. Yum install gcc gcc-c++ make-y

Step 3: decompress

1. Tar zxvf redis-5.0.7.tar.gz-C / opt/

Step 4: install

1 、 cd redis-5.0.72 、 make3 、 make PREFIX=/usr/local/redis install

Step 5: create a soft connection

Ln-s / usr/local/redis/bin/* / usr/local/bin/

Step 6: start the installation script to check the port status

Cd / redis-5.0.7/utils/./install_server.sh # # start the script. Note: enter all the way to the end. Change the last file path to: / usr/local/redis/bin/redis-servernetstat-natp | grep 6379

Turn on and off redis and sentinal commands

1 、 redis-server / etc/redis/6379.conf2 、 redis-sentinel / etc/redis/sentinel-6381.conf

In addition, you can also use redis_6379 to control its switch on and off:

1. / etc/init.d/redis_6379 stop / / shutdown 3, / etc/init.d/redis_6379 restart / / restart

Three redis configurations:

1. Add the necessary parameters for master (6379.conf) configuration file

Port 6379masterauth linlin # if you fail over, both master and slave nodes should fill in the password and maintain a consistent requirepass linlin

2. Add the necessary parameters for slave1 (6380.conf) configuration file

Port 6380slaveof 10.211.55.7 6379 # ip ipmasterauth linlin # of the master redis # if you fail over, both master and slave nodes should fill in the password and maintain consistent requirepass linlin

2. Add the necessary parameters for slave2 (6381.conf) configuration file

Port 6381slaveof 10.211.55.7 6381 # ip ipmasterauth linlin # of the master redis # if you fail over, both master and slave nodes should fill in the password and maintain consistent requirepass linlin

Verify that the master and slave data are consistent

Redis-cli-h 10.211.55.7-p 6381auth linlininfo 3. Install redis Sentinel cp sentinel.conf / usr/local/redis/conf/sentinel-26379.conf # copy the Sentinel configuration file in the source code and copy three files:

Modify the file (vim / usr/local/redis/conf/sentinel-26379.conf):

Port 26379sentinel monitor mymaster 10.211.55.7 6379 2sentinel auth-pass mymaster linlin

Vim / usr/local/redis/conf/sentinel-26380.conf

Port 26380sentinel monitor mymaster 10.211.55.7 6379 2sentinel auth-pass mymaster linlin

Vim / usr/local/redis/conf/sentinel-26381.conf

Port 26381sentinel monitor mymaster 10.211.55.7 6379 2sentinel auth-pass mymaster linlin

Start three sentinal service commands:

Redis-sentinel / etc/redis/sentinel-6379.conf

Verify that the primary redis fails and whether the slave can switch over to replace the master.

4. BUG encountered in the deployment process

Master-slave cannot be switched

Make sure that the sentinel.conf configuration file is not fully copied. This file will automatically add some data after running, so that the master / slave cannot be automatically switched without deletion after the copy.

Second, make sure that the two attributes requirepass masterauth in redis.conf have both password configurations, and sentinel auth-pass mymaster (password) exists in sentinel.conf.

3. Slaveof ip port in each redis.conf configuration file to ensure that this configuration is available from the redis configuration, and ensure that the sentinel.conf

Sentinel monitor mymaster masterip + port + num (the number is generally set to 1 or 2) to ensure that the item is consistent on all three servers

4. Enter the command info to check the master and slave through the redis-cli client connection to redis for auth authentication

5. The remote client cannot connect to redis

Redis version after 3.2.x this problem must be not configured protected-mode no; bind comments read this article, I believe you have a certain understanding of "how to use three redis master and slave + Sentinel function", if you want to know more related knowledge, welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report