当前位置:网站首页>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.
边栏推荐
- 【2022国赛模拟】多边形——计算几何、二分答案、倍增
- The so-called consumer Internet only matches and connects industry information, and does not change the industry itself
- C语言练习题_1
- Difference and the difference between array and array structure and linked list
- [software test] the most complete interview questions and answers. I'm familiar with the full text. If I don't win the offer, I'll lose
- C language exercises_ one
- MES管理系统的应用和好处有哪些
- Software testing -- common assertions of JMeter interface testing
- Have fun | latest progress of "spacecraft program" activities
- 进程管理基础
猜你喜欢
Cloud Mail .NET Edition
3 -- Xintang nuc980 kernel supports JFFS2, JFFS2 file system production, kernel mount JFFS2, uboot network port settings, and uboot supports TFTP
1 -- Xintang nuc980 nuc980 porting uboot, starting from external mx25l
How to write test cases for test coupons?
软件测试——Jmeter接口测试之常用断言
Google Earth Engine(GEE)——Landsat 全球土地调查 1975年数据集
数字滚动增加效果
Station B's June ranking list - feigua data up main growth ranking list (BiliBili platform) is released!
MySQL is an optimization artifact to improve the efficiency of massive data query
The panel floating with the mouse in unity can adapt to the size of text content
随机推荐
Hash table and full comments
服装企业部署MES管理系统的五个原因
Redis入门完整教程:客户端常见异常
Electrical engineering and automation
普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
6-6 vulnerability exploitation SSH security defense
Compress JS code with terser
1 -- Xintang nuc980 nuc980 porting uboot, starting from external mx25l
[node learning notes] the chokidar module realizes file monitoring
C # / vb. Net supprime le filigrane d'un document word
NuScenes数据集关于Radar数据的统计
Have fun | latest progress of "spacecraft program" activities
Redis入门完整教程:复制拓扑
左程云 递归+动态规划
MySQL
慧通编程入门课程 - 2A闯关
Redis入門完整教程:問題定比特與優化
Code line breaking problem of untiy text box
Ali yunyili: how does yunyuansheng solve the problem of reducing costs and improving efficiency?
【Node学习笔记】chokidar模块实现文件监听