当前位置:网站首页>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.
边栏推荐
猜你喜欢
Pioneer of Web3: virtual human
C#/VB. Net to delete watermarks in word documents
C language exercises_ one
运维管理系统有哪些特色
Redis入门完整教程:复制配置
Django数据库(SQlite)基本入门使用教程
The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
MySQL --- 常用函数 - 字符串函数
Digital scrolling increases effect
Read fast RCNN in one article
随机推荐
测试优惠券要怎么写测试用例?
Leetcode:minimum_depth_of_binary_tree解决问题的方法
MySQL --- 常用函数 - 字符串函数
Fundamentals of process management
Huitong programming introductory course - 2A breakthrough
MetaForce原力元宇宙佛萨奇2.0智能合约系统开发(源码部署)
QPushButton-》函数精解
Metaforce force meta universe fossage 2.0 smart contract system development (source code deployment)
C#/VB.NET 删除Word文檔中的水印
4 -- Xintang nuc980 mount initramfs NFS file system
AWS学习笔记(一)
MES管理系统的应用和好处有哪些
Contribution of Writing Series
所谓的消费互联网仅仅只是做行业信息的撮合和对接,并不改变产业本身
Django数据库(SQlite)基本入门使用教程
Software testing -- common assertions of JMeter interface testing
安全巡检的工作
Leetcode:minimum_ depth_ of_ binary_ Tree solutions
Digital scrolling increases effect
Introduction to ins/gps integrated navigation type