当前位置:网站首页>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.
边栏推荐
- 从零安装Redis
- Pioneer of Web3: virtual human
- Safety delivery engineer
- Compress JS code with terser
- 3 -- Xintang nuc980 kernel supports JFFS2, JFFS2 file system production, kernel mount JFFS2, uboot network port settings, and uboot supports TFTP
- Unity custom webgl packaging template
- Leetcode:minimum_depth_of_binary_tree解决问题的方法
- [Mori city] random talk on GIS data (II)
- 换个姿势做运维!GOPS 2022 · 深圳站精彩内容抢先看!
- 1 -- Xintang nuc980 nuc980 porting uboot, starting from external mx25l
猜你喜欢

实施MES管理系统时,哪些管理点是需要注意的

Read fast RCNN in one article

测试优惠券要怎么写测试用例?

Summary of basic debugging steps of S120 driver

AWS学习笔记(一)

用全连接+softmax对图片的feature进行分类

Linear list --- circular linked list

Fundamentals of process management

1 -- Xintang nuc980 nuc980 porting uboot, starting from external mx25l

How to write test cases for test coupons?
随机推荐
普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
MetaForce原力元宇宙佛萨奇2.0智能合约系统开发(源码部署)
Lombok makes the pit of ⽤ @data and @builder at the same time
惯导标定国内外研究现状小结(删减版)
换个姿势做运维!GOPS 2022 · 深圳站精彩内容抢先看!
一文读懂Faster RCNN
Oracle中日期的使用方法实例
The 8 element positioning methods of selenium that you have to know are simple and practical
普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
Classify the features of pictures with full connection +softmax
Kysl Haikang camera 8247 H9 ISAPI test
The so-called consumer Internet only matches and connects industry information, and does not change the industry itself
Web3's need for law
Unity custom webgl packaging template
CSDN summer camp course project analysis
Common fitting models and application methods of PCL
Mmdetection3d loads millimeter wave radar data
Leetcode:minimum_ depth_ of_ binary_ Tree solutions
Linear list --- circular linked list
代码调试core-踩内存