In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
1. Introduction of Sentinel
Having coquetted a brief introduction and application scenario of Redis before, I tried his Sentinel mode today.
Sentinel is the high availability (HA) solution of Redis. A Sentinel system consisting of one or more Sentinel instances can monitor any number of master servers and all slave servers under these master servers.
When the monitored master server goes offline, a slave server under the offline master server is automatically upgraded to a new master server, and then the new master server continues to process command requests instead of the offline master server.
The sentinel (Sentinel) mechanism provided by Redis automatically monitors the running status of the redis after starting the master/slave through the sentinel mode. The basic principle is: heartbeat mechanism + voting decision.
Monitoring (Monitoring): Sentinel will constantly check whether your master server and slave server are working properly.
Reminder (Notification): when there is a problem with a monitored Redis server, Sentinel can send notifications to administrators or other applications through API.
Automatic failover (Automatic failover): when a master server does not work properly, Sentinel starts an automatic failover operation, which upgrades one of the slaves of the failed master server to a new master server
And let the other slave server of the failed master server copy the new master server; when the client tries to connect to the failed master server, the cluster will return the address of the new master server to the client, so that the cluster can use the new master server instead of the failed server.
2. Redis Sentinel building
Two sentinels, one master redis,2 and one slave redis were used in the test.
Copy 5 redis.windows.conf files and rename them as follows (developers can rename them according to their own development habits):
Master.6379.conf configuration:
Port 6379
# set connection password
Requirepass grs
# connection password
Masterauth grs
Slave.6380.conf configuration:
Port 6380
Requirepass grs
Masterauth grs
Dbfilename dump6380.rdb
# configure master
Slaveof 127.0.0.1 6379
Slave.6381.conf configuration:
Port 6381
Requirepass grs
Masterauth grs
Dbfilename dump6381.rdb
# configure master
Slaveof 127.0.0.1 6379
Sentinel.63791.conf configuration (add the following after emptying the original configuration file) (the other one is the same, only the following port needs to be modified):
Port 63791
# the sentinel of the master master,2 will not be valid until the election is successful. The master-1 here is the name, which needs to be consistent during integration. You can change it here at will.
Sentinel monitor master-1 127.0.0.1 6379 2
# determine the on-hook time of the master master (milliseconds). If the timeout does not return correct information, it will be marked as sdown status.
Sentinel down-after-milliseconds master-1 5000
# if sentinel fails to complete the failover operation within the configuration value (that is, master/slave automatically switches over in case of failure), this failover is considered to have failed.
Sentinel failover-timeout master-1 18000
# identity authentication
Sentinel auth-pass master-1 grs
The # option specifies the maximum number of slaves that can synchronize the new master server at the same time when performing a failover. The smaller the number, the longer it takes to complete the failover.
Sentinel parallel-syncs master-1 1
There are three problems to pay attention to.
First, if you connect through redis-cli-h 127.0.0.1-p 6379, there is no need to change the configuration file, which is configured as bind 127.0.0.1 by default (only 127.0.0.1 connection access is allowed)
If you connect through redis-cli-h 192.168.180.78-p 6379, you need to change the configuration file: bind 127.0.0.1 192.168.180.78 (only 127.0.0.1 and 192.168.180.78 are allowed) or comment out bind 127.0.0.1 (allow all remote access)
Second, masterauth is the requirepass of the master server to which you want to connect. If there is a master server and two slave servers in a redis cluster, when the master server dies, the sentinel Sentinel will randomly select a slave server to act as the master server. In view of this mechanism, the solution is to set the requirepass and masterauth of all master and slave servers to the same.
Third, what does the last 2 at the end of sentinel monitor master-1 127.0.0.1 6379 2 mean? We know that the network is unreliable. Sometimes a sentinel will mistakenly think that a master redis is dead because of network congestion. When sentinel is clustered, the solution to this problem becomes very simple. It only requires multiple sentinel to communicate with each other to confirm whether a master is really dead. This 2 means that when two sentinel in the cluster think that master is dead, they can really think that the master is no longer available. (the sentinel in the sentinel cluster also communicates with each other through the gossip protocol.)
Start the service in the following order
1 、 redis-server master.6379.conf
2 、 redis-server slave.6380.conf
3 、 redis-server slave.6381.conf
4. Redis-server sentinel.63791.conf-sentinel (linux:redis-sentinel sentinel.63791.conf)
5. Redis-server sentinel.63792.conf-sentinel (linux:redis-sentinel sentinel.63792.conf)
View master status:
View slave status:
View sentinel status:
Verify the master-slave handoff of redis sentinel:
1. First shut down the main redis (6379) service (shutdown).
2. Check the sentry and find that the slave service with port number 6380 becomes the master service, and sentinel automatically completes the failover.
3. Start the 6379 service that has just been shutdown and look at it, and find that it becomes a slave service.
This is the end of my building and demonstration.
Follow-up stand-alone version of spring integration and use it slowly. Come back if you succeed.
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
© 2024 shulou.com SLNews company. All rights reserved.