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

Operation method of one master and one standby configuration in Redis sentinel mode

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Redis sentinel mode one main and one standby configuration operation method, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need this can learn, I hope you can gain something.

1. Copy the local Redis file, copy a copy (default installation path: C:\Program Files\Redis), name it with port, Redis_master_6379, Redis_slave_6380, because there is a 6379, so directly add 6380 folder and various configuration startup files under C:\Program Files\Redis\Reids_more directory

2. Configure master-slave settings first:

6379 is the host computer, without modification;

6380 folder, configure the redis.windows.config file:

#Start port

port 6380

#Belongs to a slave with IP 127.0.0.1 and port 6379

slaveof 127.0.0.1 6379

3. Configure detection sentries

A new sentinel detection file, sentinel.conf, needs to be added to both folders

6379 folder sentinel.conf:

#Port on which the current Sentinel service is running

port 26379

#Sentinel listening on the main server, the last 2 indicates the number of votes, 1 machine thinks it can not connect to port 127.0.0.1: 6379 to switch

sentinel monitor mymaster 127.0.0.1 6379 1

#To configure the master authentication password, otherwise the monitoring will not work

sentinel auth-pass mymaster Test@123

#mymaster does not respond in 3s, mymaster is considered down

sentinel down-after-milliseconds mymaster 3000

#If after 10 seconds,mysater still does not start, then start failover

sentinel failover-timeout mymaster 10000

#When performing a failover, up to 3 slaves synchronize to the new master simultaneously

sentinel parallel-syncs mymaster 3

The sentinel.conf file in the 6380 folder is basically the same as above. You only need to modify the port on which the corresponding Sentinel service runs. Modify 6380 to port 26380.

4. Configure login password and authentication password

Configuration is required in both folders:

Configure in redis.windows.config file:

#Login Password

requirepass Test@123

#Authentication password

masterauth Test@123

5. Configure startup files

New Redis startup script: startRedisServer.bat

@echo offredis-server.exe redis.windows.conf@pause

Added Redis-Sentinel startup script: startRedisSentinel.bat

@echo offredis-server.exe sentinel.conf --sentinel@pause

Then configure windows startup files in C:\Program Files\Redis\Reids_more directory:

Configure startrRedis6379.cmd, the same for others!

@echo offcd Redis6379startRedisServer.bat

Configuration startrRedisSentinel26379.cmd, the same for others!

@echo offcd Redis6379startRedisSentinel.batat

6, now you can test, first start tomcat, and then store a certain amount of value in the cache

Then start from top to bottom, 6379 is the host machine, 6380 is the standby machine. If there are multiple standby computers, you need to wait a little while during startup, otherwise two slave computers will compare cards when synchronizing cache with the host computer at the same time. After startup, there will be 4 consoles, two of which are redis and two of which are sentries, with ports 6379, 6380, 26379 and 26380 respectively.

Common commands:

Open redis working window: redis-cli -p 6379

Password authentication: auth Test@123

See details: info replication

Service shutdown: shutdown

View cache details:

Host condition:

Slave status:

Downtime testing is possible at this point:

a. Enter port 6380, close the service, and find that there is no impact on the host. Restart port 6380 redis or slave. Restart for a while and start synchronizing the host cache.

b. Enter port 6379, close the service, and find that ports 6380 and 6381 report errors. After a few seconds, the sentries will find this situation and start switching hosts. Select one slave from multiple slaves to become a host, and then modify the configuration file. The original host will add a slaveof IP port, and then all sentries will start monitoring the ip and port of the new host. After restarting the 6379 service, they will find that 6379 has become a slave, and the host is now 6381. Use redis-cli to check cache and find cache still in service

7. Deploy Redis cluster into project

Add redis.properties file, centrally configure redis address port and sentinel address port information.

Introduce a configuration file into the spring-redis.xml file, and then configure the address and port of the sentinel.

8. Project Testing

First turn off the redis service provided by the system, then turn on the redis service of the master-slave machine in sequence, then turn on the sentinel monitoring service, open the file under alarm, and find that the cache is normal, then forcibly turn off the port 6379 service, watch the sentinel console, and find that the host switches to 6381 normally, and then check the redis cache, and find that it is normal. Open another file on the page, and find that it can be added to redis normally. Start 6379 again, and find that the port has become a slave machine. Xml file data can be updated normally from 6381 host, test result is normal

Note:

1. Due to the master-slave relationship of Redis configuration, one master and two or more slaves are required. Only one computer can be used locally, so configure multiple ports locally to achieve the test effect of multiple servers.

2. All operations are performed when the local Redis service is closed. Right click on My Computer-Manage and you can view the computer's service startup status, otherwise the master startup will fail due to port consistency.

3. Be sure to configure the master authentication password in the sentinel.conf file: sentinel auth-pass mymasterTest@123, otherwise the sentinel will fail to accurately detect the situation after the host is down, resulting in automatic host switching failure.

4. In sentinel mode, there is no absolute master and slave except when it is configured for the first time. After host A goes down, slave B will be promoted to host B, and A will only become slave A after restarting. If all redis stopped at this time, it can be found that in the configuration file of each part of Redis, the monitored port changes from the port of host A to the port of host B, that is to say, the configuration file of each part will change with the change of host. The main changes are the configured slave address and port (slaveof IP port in redis.windows.config) and the master address and port (sentinel monitor mymaster IP port quorun in sentinel.conf)

Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.

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

Internet Technology

Wechat

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

12
Report