In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Does Redis Sentinel implement highly available configurations? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
1. Create a redis-sentinel_26379.conf. The main contents are as follows:
# basic configuration port 26379daemonize yeslogfile "/ var/log/redis/sentinel_26379.log" protected-mode nodir / var/lib/redis-cluster/sentinel# check configuration sentinel monitor mymaster 127.0.0.1 6379 1 (pointing to master server or port) # sentinel auth-pass mymaster passwdsentinel parallel-syncs mymaster 1sentinel down-after-milliseconds mymaster 5000sentinel failover-timeout mymaster 18000
2. Create a redis-sentinel_26380.conf. The main contents are as follows:
# basic configuration port 26380daemonize yeslogfile "/ var/log/redis/sentinel_26380.log" protected-mode nodir / var/lib/redis-cluster/sentinel# check configuration sentinel monitor mymaster 127.0.0.1 6379 1 (pointing to master server or port) # sentinel auth-pass mymaster passwdsentinel parallel-syncs mymaster 1sentinel down-after-milliseconds mymaster 5000sentinel failover-timeout mymaster 18000
The meaning of the parameter declaration for sentinel monitor is as follows:
Sentinel monitor [master-group-name] [ip] [port] [quorum]
The first line tells Redis to monitor a master called mymaster, whose address is 127.0.0.1, port 6379, and quorum 2. Each parameter is easy to understand, but quorum needs to explain:
1. Quorum is the number that Sentinel needs to negotiate to agree whether master is reachable. In order to really mark slave as a failure, and ultimately whether a failover process needs to be started.
2. In any case, quorum is only used to detect faults. In order to actually perform the failover, the Sentinel needs to elect the leader and authorize it. This only happens in most Sentinel process elections.
Other options are usually in this form:
Other options are usually in this form: sentinel [option_name] [master_name] [option_value]
1. Down-after-milliseconds-an instance is unreachable (unable to ping or has an error), and Sentinel begins to think that it is the number of milliseconds of down.
2. Parallel-syncs-sets the number of slave that can be reconfigured to use the new master at the same time after failover. The lower the number, the more time it takes to fail over, but if slaves is configured to serve old data, you may not want all slave to resynchronize master at the same time. Because master-slave replication is non-blocking for slave, there is a short delay when you stop loading bulk data from master. Make sure that only one slave at a time is unreachable by setting the option to 1.
3. There is no difference between the creation of redis-master-6379.conf,master configuration and the default file, and the main contents are as follows:
Daemonize yesprotected-mode noport 6379#requirepass "passwd" # masterauth "passwd"
4. Create a redis-slave-6380.conf. The main contents are as follows:
Protected-mode noport 6380daemonize yes#requirepass "passwd" # masterauth "passwd" slaveof 127.0.0.1 6379
5. Then it can be started.
Cd / usr/sbin/# start master redisredis-server / etc/redis-cluster/redis-master-6379.conf# start slave redisredis-server / etc/redis-cluster/redis-slave-6380.conf# start redis-sentinelredis-sentinel / etc/redis-cluster/redis-sentinel_26379.confredis-sentinel / etc/redis-cluster/redis-sentinel_26380.conf
We can view the response log in the / var/log/redis/sentinel_26379.log directory.
6. Spring boot integrates redis-sentinel
Comment out the configuration of the stand-alone.
# spring.redis.host=127.0.0.1# Redis server connection port # spring.redis.port=6379
Increase highly available configuration
# Sentinel listening redis server name spring.redis.sentinel.master=mymaster# Sentinel configuration list spring.redis.sentinel.nodes=127.0.0.1:26379127.0.0.1:26380
The code can be used directly in RedisUtils, such as:
@ Autowiredprivate RedisTemplate redisTemplate
Later, the controller can directly use the method defined by RedisUtils.
Finally, test it.
After reading the above, have you mastered the method of Redis Sentinel to achieve high availability configuration? If you want to learn more skills or want to know more about it, you are 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
You cannot increase the size of an existing system tablespace data file by changing its size attribu
© 2024 shulou.com SLNews company. All rights reserved.