In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article to share with you is about Redis three kinds of cluster mode is what, Xiaobian think quite practical, so share to everyone to learn, I hope you can read this article after some harvest, not much to say, follow Xiaobian to see it.
Three cluster models
Redis has three clustering patterns, of which master-slave is the most common pattern.
Sentinel mode is evolved to compensate for the complexity of active/standby switching after host downtime in a master-slave replication cluster. As the name suggests, sentries are used for monitoring. Their main role is to monitor the master-slave cluster, automatically switch between the master and the backup, and complete the cluster failover.
Cluster mode is the cluster mode provided by redis officially. It uses Sharding technology, which not only realizes high availability, read-write separation, but also realizes real distributed storage.
I. Master-slave copy
redis master-slave replication
1, reids master-slave mode
2, redis replication principle
Redis replication is divided into two parts: operation synchronization (SYNC) and command propagation (command propagate)
Synchronization (SYNC) is used to update the state of the slave server to be consistent with the master server. Vernacular interpretation is that the slave server actively obtains the data of the master server. Keep data consistent. Specifically, after receiving the SYNC command, the master server generates an RDB snapshot file and sends it to the slave server.
Command propagate is used to propagate commands to keep slave servers consistent with master server status after master server data is modified and master server is inconsistent. The vernacular interpretation is that after the master server receives the client's command to modify the data, the database data changes, and the command is cached, and then the cache command is sent to the slave server, and the slave server achieves the consistency of the master-slave data by loading the cache command. This is called command propagation.
Why do you need two replication operations of synchronization and command propagation: When there is only synchronization operation, then when the slave server sends SYNC command to the master server, the master server will still receive the command from the client to modify the data state when generating RDB snapshot files. If this part of data cannot be communicated to the slave server, then the phenomenon of inconsistent master-slave data will occur. At this time, command propagation occurs. After the master server receives the SYNC command from the slave server, it generates an RDB snapshot file. At the same time, it caches the commands received during this period, and then uses the command propagation operation to send them to the slave server. to achieve consistency in master-slave data.
3, redis master-slave replication principle
The above describes the two operations of redis replication, and redis master-slave replication is formally based on synchronization and command propagation. The following two diagrams illustrate the flow of redis replication:
4, redis master-slave copy advantages and disadvantages
Advantages:
1. Realize read-write separation, improve availability, and solve single fault 2. During master-slave replication, master and slave are non-blocking modes and are still available.
Disadvantages:
1. During the downtime of master, it is necessary to manually switch the host, and some data cannot be synchronized with the slave server in time, resulting in data inconsistency (manual intervention is required).
2. After slave downtime, after multiple slaves recover, a large number of SYNC synchronization will cause master IO pressure to multiply (you can manually avoid startup time)
3. Online expansion is more complicated.
Summary:
The advantage of redis master-slave replication is mainly improved availability. Disadvantages
II. Sentinel mode
Sentinel Sentinel Introduction
Sentinel is essentially a Redis instance running in special mode, but the initialization process and work are different from ordinary Redis, and essentially a separate process.
Sentinel Sentinel is Redis's highly available solution: a Sentinel system consisting of one or more Sentinel instances can monitor any number of master servers, as well as all slave servers subordinate to those master servers, and automatically switch slave servers to master when the master server goes offline.
The Sentinel System
A Sentinel system monitors a master-slave cluster, where server1 is the Redis master and servers 2/3/4 are the Redis slaves. The master-slave agreement is achieved by using the master-slave copy above. The Sentinel system monitors the entire master-slave cluster.
2. Sentinel failover
When the Sentinel system detects that the Server1 primary server is down, it terminates replication of servers 2/3/4.
At the same time, Sentinel upgraded server2 to the primary server, and server3/4 replicated from the new primary server. Wait for server1 to come online again.
The Sentinel system can also actively demote a master server to a slave server and promote a slave server to a master server.
2.1 Sentinel monitoring process
Sentinel monitors cluster processes:
The command Sentinel sends a command to bring the redis server back up and running. Publish Subscriptions When the state of the primary server changes, Sentinel Sentry passes through
Publish-subscribe mode notifies other slave servers.
2.2 Sentinel failover
Sentinel failover:
Sentinel instances in the Sentinel system send PING commands like clusters every 1s.
2. If an instance in the cluster takes longer than down-after-milliseconds to reply to a Sentinel instance, the instance will send a PING command and the Sentinel instance will be subjectively offline.
3. When will you objectively go offline? Other instances in the Sentinel system are required to confirm that the instance supervisor in the cluster is offline.
If the master master server is marked as subjective offline, the Sentinel process monitoring the master in the Sentinel system needs to confirm once per second whether the Master has entered the supervisor offline state
When there are enough Sentinel instances (depending on configuration) to confirm that the Master has entered a supervisor downline, the Master is marked as an objective downline.
3. Advantages and disadvantages of Sentinel
Advantages:
1. Sentinel mode is based on master-slave replication, so sentinel has the advantages of master-slave replication. 2. Sentinel has master-slave switchover and failover, so cluster has higher availability.
Disadvantages:
1. Redis is difficult to support online expansion, which is more complicated.
Summary:
Sentinel is mainly used to monitor redis master-slave clusters, which improves the availability of redis master-slave clusters.
III. Cluster mode
redis cluster
1、reids cluster
Redis Cluster is a server Sharding technology, and version 3.0 of Redis is officially available.
Sentinel has basically achieved high availability, but each machine stores the same content, which is a waste of memory, so Redis Cluster implements distributed storage. Each machine node stores different content.
2. Redis Cluster data fragmentation principle
Redis data fragmentation uses hash slots. Redis cluster has 16384 hash slots. Each Key is checked by CRC16 and modulo 16384 to determine which slot to place.
When accessing redis key, redis will get a result according to CRC16 algorithm, and then calculate the remainder of the result and 16384, and use this value to obtain data corresponding to the corresponding node.
At this point, the application client actually only needs to connect to any one of the nodes, and then each node in the Redis Cluster stores the slot information of other nodes. In this way, when the access key calculates the slot, it obtains the node information from the configuration by saving the slot information, and then obtains the data from the corresponding node.
3. Redis Cluster replication principle
A master-slave replication model is introduced into the redis-cluster cluster. A master node corresponds to one or more slave nodes. When the master node goes down, the slave node will be enabled. When other master nodes ping a master node A, if more than half of the master nodes communicate with A for a timeout, master node A is considered to be down. If both master node A and its slave node A1 go down, the cluster will no longer be able to provide service.
4. Advantages and disadvantages of redis Cluster
Advantages:
1. Distributed storage is realized and memory is saved.
The above is what the three cluster modes of Redis are. Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.