In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
What is the principle of redis master-slave replication? In order to let you know more about the master-slave copy of redis, the editor summarizes the following contents. Let's look down together.
The replication function of redis is to support data synchronization between multiple databases. One is the master database (master) and the other is the slave database (slave). When the write operation occurs, the master database can automatically synchronize the data to the slave database, while the slave database is generally read-only and receives the data synchronized from the master database. A master database can have multiple slave databases, while a slave database can only have one master database.
Through the master-slave replication function of redis, the read and write separation of the database can be well realized, and the load capacity of the server can be improved. The master server is mainly responsible for the write operation, and the slave server is mainly responsible for the read operation.
The process of master-slave replication:
1: when a slave database is started, a sync command is sent to the master database
2: after receiving the sync command, the master database starts to save the snapshot in the background (perform the rdb operation), and caches the commands received during the save
3: when the snapshot is complete, redis sends the snapshot file and all cached commands to the slave database.
4: upon receipt from the database, the snapshot file is loaded and the cached commands received are executed.
Note: the previous version of redis2.8: when the master slave database is synchronized, the above operations will be reperformed when the database is disconnected and reconnected due to network reasons, and the continuation of breakpoints is not supported. Resuming upload from breakpoint is supported after redis2.8.
Note: starting with Redis 2.8, in order to ensure the security of the data, you can configure min-slaves-to-write so that a master node can only perform write operations if there are at least N slave nodes. The slave node ping the master node at a frequency of once per second, and the master node records the last time each slave server sent ping to it. Users can configure to specify the maximum network latency min-slaves-max-lag and the minimum number of slave servers required to perform write operations
Min-slaves-to-write min-slaves-to-write 3 min-slaves-max-lag 10
If there are at least min-slaves-to-write slave servers, and all of them have latency values less than min-slaves-max-lag seconds, then the master server will perform the write operation requested by the client. As long as one condition is not met, the write operation is not performed, and the primary server returns an error to the client requesting the write operation.
Second, the deployment of master-slave replication:
Redis master-slave structure supports one master and multiple slaves.
Master node: 192.168.1.170
Slave node: 192.168.1.171
Note: the configuration of all slave nodes is the same
Method 1: manually modify the configuration file
You only need to modify the slaveof attribute in the configuration file of the redis in the slave node.
Slaveof 192.168.1.170 6379
Start the redis on the 170master node and view the info information of redis (execute the info command)
Start 171Slave redis above the node
View info information of redis
Mode 2: dynamic setting
To connect to the slave server via redis-cli, execute the following command.
Third, the problems that should be paid attention to in master-slave replication:
① if you use master-slave replication, make sure that your master is enabled for persistence, or that it does not restart automatically after pawning. Slave is a full backup of master, so if master is restarted with an empty dataset, slave will also be wiped out.
When ② configures the redis replication function, if the master database sets the password, it needs to set the password of the master database through the masterauth parameter in the configuration file of the slave data, so that the slave database will automatically use the auth command to authenticate when connecting to the master database. It is equivalent to doing a password-free login.
After reading the above, do you have a general understanding of the principle of redis master-slave replication? If you want to know more, welcome to 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.