当前位置:网站首页>Redis getting started complete tutorial: replication configuration
Redis getting started complete tutorial: replication configuration
2022-07-07 02:49:00 【Gu Ge academic】
6.1.1 Create replication
Participating in replication Redis The instance is divided into primary nodes (master) And slave nodes (slave). Default
Under the circumstances ,Redis Are all primary nodes . Each slave can only have one master , The master node can
Having multiple slave nodes at the same time . The replicated data flow is unidirectional , Can only be copied from master node to slave node
spot . There are three ways to configure replication :
1) Add... To the configuration file slaveof{masterHost}{masterPort} along with Redis Starter
effect .
2) stay redis-server Add after starting command --slaveof{masterHost}{masterPort} raw
effect .
3) Direct use command :slaveof{masterHost}{masterPort} take effect .
in summary ,slaveof When the command is used , It can be configured dynamically at run time , You can also write in advance
To the configuration file . For example, the two local boot ports are 6379 and 6380 Of Redis node , stay
127.0.0.1:6380 Execute the following command :
127.0.0.1:6380>slaveof 127.0.0.1 6379
slaveof Configuration is initiated from the node , At this time 6379 Master node ,6380 As a slave
spot . After the replication relationship is established, execute the following command to test :
127.0.0.1:6379>set hello redis
OK
127.0.0.1:6379>get hello
"redis"
127.0.0.1:6380>get hello
"redis"
From the running results, we can see that replication has worked , For the master node 6379 Any modification of
Synchronize to slave nodes 6380 in , The replication process is shown in the figure 6-1 Shown .

slaveof Itself is an asynchronous command , perform slaveof On command , After the node only saves the master node information
return , Subsequent replication processes are executed asynchronously within the node , See details later 6-3 Replication principle is small
section . After the master-slave node replication is successfully established , have access to info replication Command to view replication related
state , As shown below .
1) Master node 6379 Copy status information :
127.0.0.1:6379>info replication
# Replication
role:master
connected_slaves:1
slave0:ip=127.0.0.1,port=6379,state=online,offset=43,lag=0
....
2) From the node 6380 Copy status information :
127.0.0.1:6380>info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6380
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0
...
6.1.2 Disconnect replication
slaveof Commands can not only create replication , It can also be executed from the slave node slaveof no one To break
Open the replication relationship with the master node . For example, in 6380 Execution on node slaveof no one To break the replication , Such as
chart 6-2 Shown .

Disconnect the replication main process :
1) Break the replication relationship with the master node .
2) From node to master node .
Disconnecting replication from a node does not discard the original data , Just can no longer get the number on the primary node
According to the change .
adopt slaveof The command can also realize the main operation , The so-called master switch refers to the transfer of the current slave node to the master node
The replication of a node switches to another master node . perform slaveof{newMasterIp}
{newMasterPort} Command is enough , For example, put 6380 Nodes are copied from the original 6379 The node becomes complex
system 6381 node , Pictured 6-3 Shown .
The main operation flow is as follows :
1) Break the replication relationship with the old master node .
2) Establish a replication relationship with the new master node .
3) Delete all current data from the node .
4) Copy the new master node .
Operation and maintenance tips
After switching the master node, the slave node will clear all previous data , Be careful when online manual operation slaveof Wrong
Execute on the wrong node or point to the wrong master node .
6.1.3 Security
For nodes with important data , The master node will be set requirepass Parameter for password
verification , At this time, all client access must use auth The command performs verification . Slave node and master node
The replication connection is completed through a specially identified client , Therefore, you need to configure the slave node
masterauth The parameter is consistent with the password of the master node , In this way, the slave node can be correctly connected to the master node
Node and initiate the replication process .
6.1.4 read-only
By default , Use from node slave-read-only=yes Configured to read only mode . Due to reply
The system can only be from master node to slave node , For any modification of the slave node, the master node is not aware , modify
The slave node will cause inconsistency between the master and slave data . Therefore, it is recommended not to modify the read-only mode of the slave node on the line .
6.1.5 Transmission delay
Master and slave nodes are generally deployed on different machines , Network latency during replication becomes a consideration
problem ,Redis For us repl-disable-tcp-nodelay Parameter is used to control whether to turn off
TCP_NODELAY, Off by default , The explanation is as follows :
· When closed , The command data generated by the master node will be sent to the slave node in time regardless of the size
spot , In this way, the delay between master and slave will be reduced , But it increases the consumption of network bandwidth . Applicable between master and slave
A good network environment , Just like the rack or the same machine room .
· When opened , The master node will merge smaller TCP Packets to save bandwidth . Default send
The time interval depends on Linux The kernel of , The general default is 40 millisecond . This configuration saves bandwidth, but
Increase the delay between master and slave . It is suitable for the scenarios with complex master-slave network environment or tight bandwidth , Such as cross machine
Room deployment .
Operation and maintenance tips
When deploying master-slave nodes, network latency should be considered 、 Bandwidth usage 、 Disaster prevention level and other factors , Such as
When low delay is required , It is recommended to deploy and shut down in the same rack or machine room repl-disable-tcp-nodelay; Such as
If high disaster tolerance is considered , It can be deployed and opened across computer rooms in the same city repl-disable-tcp-nodelay.
边栏推荐
- Oracle中日期的使用方法实例
- MetaForce原力元宇宙佛萨奇2.0智能合约系统开发(源码部署)
- The 8 element positioning methods of selenium that you have to know are simple and practical
- MES管理系统的应用和好处有哪些
- Redis入门完整教程:RDB持久化
- 实施MES管理系统时,哪些管理点是需要注意的
- 左程云 递归+动态规划
- 惯导标定国内外研究现状小结(删减版)
- Increase 900w+ playback in 1 month! Summarize 2 new trends of top flow qiafan in station B
- Code debugging core step memory
猜你喜欢
随机推荐
1 -- Xintang nuc980 nuc980 porting uboot, starting from external mx25l
Qt蓝牙:QBluetoothDeviceInfo
PSINS中19维组合导航模块sinsgps详解(时间同步部分)
【2022国赛模拟】多边形——计算几何、二分答案、倍增
Argo workflows source code analysis
STM32 project -- Topic sharing (part)
Cloud Mail . NET Edition
MySQL提升大量数据查询效率的优化神器
测试优惠券要怎么写测试用例?
Redis入门完整教程:问题定位与优化
Unity webgl adaptive web page size
MySQL - common functions - string functions
6-6漏洞利用-SSH安全防御
Classify the features of pictures with full connection +softmax
Convert widerperson dataset to Yolo format
Lombok makes the pit of ⽤ @data and @builder at the same time
你不可不知道的Selenium 8种元素定位方法,简单且实用
Derivative, partial derivative, directional derivative
KYSL 海康摄像头 8247 h9 isapi测试
软件测试——Jmeter接口测试之常用断言









