当前位置:网站首页>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.
边栏推荐
- Leetcode:minimum_ depth_ of_ binary_ Tree solutions
- What are the applications and benefits of MES management system
- MySQL
- Introduction to ins/gps integrated navigation type
- 服装企业部署MES管理系统的五个原因
- Unity webgl adaptive web page size
- The so-called consumer Internet only matches and connects industry information, and does not change the industry itself
- INS/GPS组合导航类型简介
- PCL 常用拟合模型及使用方法
- Convert widerperson dataset to Yolo format
猜你喜欢
Pioneer of Web3: virtual human
Remember the problem analysis of oom caused by a Jap query
Increase 900w+ playback in 1 month! Summarize 2 new trends of top flow qiafan in station B
Django database (SQLite) basic introductory tutorial
[Mori city] random talk on GIS data (II)
Redis入门完整教程:客户端案例分析
Station B's June ranking list - feigua data up main growth ranking list (BiliBili platform) is released!
unity 自定义webgl打包模板
MMDetection3D加载毫米波雷达数据
Hash table and full comments
随机推荐
Argo workflows source code analysis
The 8 element positioning methods of selenium that you have to know are simple and practical
【2022国赛模拟】多边形——计算几何、二分答案、倍增
运维管理系统有哪些特色
fasterxml ToStringSerializerBase报错
Pioneer of Web3: virtual human
AWS学习笔记(一)
MATLB|具有储能的经济调度及机会约束和鲁棒优化
一本揭秘字节万台节点ClickHouse背后技术实现的白皮书来了!
QT常见概念-1
MES管理系统的应用和好处有哪些
Contribution of Writing Series
Wireshark installation
Application analysis of face recognition
LeetCode 77:组合
Cloud Mail . NET Edition
从零安装Redis
Five reasons for clothing enterprises to deploy MES management system
Andrews - multimedia programming
Redis入门完整教程:客户端管理