【Redis】主从复制架构

发布时间 2023-04-18 00:48:56作者: Janzen_Q

Redis主从复制配置详解

################################# REPLICATION #################################

# Master-Replica replication. Use replicaof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
#   +------------------+      +---------------+
#   |      Master      | ---> |    Replica    |
#   | (receive writes) |      |  (exact copy) |
#   +------------------+      +---------------+
#
# 1) Redis replication is asynchronous, but you can configure a master to
#    stop accepting writes if it appears to be not connected with at least
#    a given number of replicas.
# 2) Redis replicas are able to perform a partial resynchronization with the
#    master if the replication link is lost for a relatively small amount of
#    time. You may want to configure the replication backlog size (see the next
#    sections of this file) with a sensible value depending on your needs.
# 3) Replication is automatic and does not need user intervention. After a
#    network partition replicas automatically try to reconnect to masters
#    and resynchronize with them.
#
# replicaof <masterip> <masterport>
replicaof 10.0.0.22 6379 #目标master节点的IP及端口信息,配置表示设置当前机器为slave节点,默认 注释禁用 # If the master is password protected (using the "requirepass" configuration # directive below) it is possible to tell the replica to authenticate before # starting the replication synchronization process, otherwise the master will # refuse the replica request. # # masterauth <master-password>
masterauth redis #目标master节点的连接密码

# When a replica loses its connection with the master, or when the replication # is still in progress, the replica can act in two different ways: # # 1) if replica-serve-stale-data is set to 'yes' (the default) the replica will # still reply to client requests, possibly with out of date data, or the # data set may just be empty if this is the first synchronization. # # 2) if replica-serve-stale-data is set to 'no' the replica will reply with # an error "SYNC with master in progress" to all the kind of commands # but to INFO, replicaOF, AUTH, PING, SHUTDOWN, REPLCONF, ROLE, CONFIG, # SUBSCRIBE, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBLISH, PUBSUB, # COMMAND, POST, HOST: and LATENCY. # replica-serve-stale-data yes #当slave失去与master连接或正在进行复制时,是否继续响应客户端读请求。会导致用户访问的数据未及时更新,默认:yes,建议设置为yes
#设置为no时除特定命令外任何请求返回错误"SYNC with master in progress"
# You can configure a replica instance to accept writes or not. Writing against # a replica instance may be useful to store some ephemeral data (because data # written on a replica will be easily deleted after resync with the master) but # may also cause problems if clients are writing to it because of a # misconfiguration. # # Since Redis 2.6 by default replicas are read-only. # # Note: read only replicas are not designed to be exposed to untrusted clients # on the internet. It's just a protection layer against misuse of the instance. # Still a read only replica exports by default all the administrative commands # such as CONFIG, DEBUG, and so forth. To a limited extent you can improve # security of read only replicas using 'rename-command' to shadow all the # administrative / dangerous commands. replica-read-only yes #slave节点只读 默认:yes # Replication SYNC strategy: disk or socket. # # ------------------------------------------------------- # WARNING: DISKLESS REPLICATION IS EXPERIMENTAL CURRENTLY # ------------------------------------------------------- # # New replicas and reconnecting replicas that are not able to continue the replication # process just receiving differences, need to do what is called a "full # synchronization". An RDB file is transmitted from the master to the replicas. # The transmission can happen in two different ways: # # 1) Disk-backed: The Redis master creates a new process that writes the RDB # file on disk. Later the file is transferred by the parent # process to the replicas incrementally. # 2) Diskless: The Redis master creates a new process that directly writes the # RDB file to replica sockets, without touching the disk at all. # # With disk-backed replication, while the RDB file is generated, more replicas # can be queued and served with the RDB file as soon as the current child producing # the RDB file finishes its work. With diskless replication instead once # the transfer starts, new replicas arriving will be queued and a new transfer # will start when the current one terminates. # # When diskless replication is used, the master waits a configurable amount of # time (in seconds) before starting the transfer in the hope that multiple replicas # will arrive and the transfer can be parallelized. # # With slow disks and fast (large bandwidth) networks, diskless replication # works better. repl-diskless-sync no #使用socket模式(无盘模式)进行rdb副本传输
#slave节点首次连接到master时需要进行数据全量复制,redis-server 需要将数据dump成新的rdb文件传输给slave端
# no :基于硬盘(disk-backed)master创建一个新的子进程dump生成新的rdb磁盘文件,再由主进程将rdb磁盘文件传输至slave节点上
# yes :基于socket(diskless) master创建一个新的子进程直接dump rdb数据至slave节点的网络socket,不经过磁盘和主进程操作
# 推荐基于磁盘(no)进行rdb数据传输,rdb文件创建后可同时传输给多个slave。基于socket传输(yes),slave连接至master之后需要逐个传输,建议当磁盘I/O性能较差且网络环境较好时启用
# When diskless replication is enabled, it is possible to configure the delay # the server waits in order to spawn the child that transfers the RDB via socket # to the replicas. # # This is important since once the transfer starts, it is not possible to serve # new replicas arriving, that will be queued for the next RDB transfer, so the server # waits a delay in order to let more replicas arrive. # # The delay is specified in seconds, and by default is 5 seconds. To disable # it entirely just set it to 0 seconds and the transfer will start ASAP. repl-diskless-sync-delay 5 #rdb socket传输等待时间,默认 5s
# 在等待期间连接上master的slave,会一起通过socket方式同步rdb数据,当本次数据同步开始后,master将不再接受新的slave同步请求,等待时间后新连接的slave需排队等待下一次rdb数据同步
# 因此服务器需要等待一段时间才能让更多的副本到达,建议值:30-60

# Replicas send PINGs to server in a predefined interval. It's possible to change
# this interval with the repl_ping_replica_period option. The default value is 10
# seconds.
#
repl-ping-replica-period 10  #slave向master发起ping探测间隔时间(单位s),默认:5

# The following option sets the replication timeout for:
#
# 1) Bulk transfer I/O during SYNC, from the point of view of replica.
# 2) Master timeout from the point of view of replicas (data, pings).
# 3) Replica timeout from the point of view of masters (REPLCONF ACK pings).
#
# It is important to make sure that this value is greater than the value
# specified for repl-ping-replica-period otherwise a timeout will be detected
# every time there is low traffic between the master and the replica.
#
repl-timeout 60  #复制连接超时时间,须大于 repl-ping-replica-period ,默认:60

# Disable TCP_NODELAY on the replica socket after SYNC?
#
# If you select "yes" Redis will use a smaller number of TCP packets and
# less bandwidth to send data to replicas. But this can add a delay for
# the data to appear on the replica side, up to 40 milliseconds with
# Linux kernels using a default configuration.
#
# If you select "no" the delay for data to appear on the replica side will
# be reduced but more bandwidth will be used for replication.
#
# By default we optimize for low latency, but in very high traffic conditions
# or when the master and replicas are many hops away, turning this to "yes" may
# be a good idea.
repl-disable-tcp-nodelay no  #slave发起sync请求后禁用TCP-NODELAY
# yes:Redis将合并多个报文为一个大报文,从而使用少量数据包向slave发生数据,节约网络带宽,但会造成数据传输延迟,Linux内核默认延迟将到达40毫秒
# no:不对数据报文进行合并,降低数据延迟,但将占用更高的带宽
# Set the replication backlog size. The backlog is a buffer that accumulates # replica data when replicas are disconnected for some time, so that when a replica # wants to reconnect again, often a full resync is not needed, but a partial # resync is enough, just passing the portion of data the replica missed while # disconnected. # # The bigger the replication backlog, the longer the time the replica can be # disconnected and later be able to perform a partial resynchronization. # # The backlog is only allocated once there is at least a replica connected. # repl-backlog-size 128mb #复制缓冲区内存大小,默认:1
#在slave断开连接后。缓冲区将累积复制副本数据,当slave重连后仅需要进行增量复制避免全量复制,只在有slave连接时分配此内存空间,建议适当调大此分配空间,否则将导致slave数据同步失败
# After a master has no longer connected replicas for some time, the backlog # will be freed. The following option configures the amount of seconds that # need to elapse, starting from the time the last replica disconnected, for # the backlog buffer to be freed. # # Note that replicas never free the backlog for timeout, since they may be # promoted to masters later, and should be able to correctly "partially # resynchronize" with the replicas: hence they should always accumulate backlog. # # A value of 0 means to never release the backlog. # repl-backlog-ttl 3600 #复制缓冲区有效期限,超过此期限没有slave连接,缓冲区空间将被释放 # The replica priority is an integer number published by Redis in the INFO output. # It is used by Redis Sentinel in order to select a replica to promote into a # master if the master is no longer working correctly. # # A replica with a low priority number is considered better for promotion, so # for instance if there are three replicas with priority 10, 100, 25 Sentinel will # pick the one with priority 10, that is the lowest. # # However a special priority of 0 marks the replica as not able to perform the # role of master, so a replica with priority of 0 will never be selected by # Redis Sentinel for promotion. # # By default the priority is 100. replica-priority 100 #哨兵选举master优先级,数值越小优先级越高,为0时永远不会被选举,默认:100 # It is possible for a master to stop accepting writes if there are less than # N replicas connected, having a lag less or equal than M seconds. # # The N replicas need to be in "online" state. # # The lag in seconds, that must be <= the specified value, is calculated from # the last ping received from the replica, that is usually sent every second. # # This option does not GUARANTEE that N replicas will accept the write, but # will limit the window of exposure for lost writes in case not enough replicas # are available, to the specified number of seconds. # # For example to require at least 3 replicas with a lag <= 10 seconds use: # # min-replicas-to-write 1 #允许master执行写入操作的slave最少连接数,默认:3禁用 # min-replicas-max-lag 10 #允许master执行写入操作的slave最少连接数的最大超时时限,默认:10 禁用 # # Setting one or the other to 0 disables the feature. # # By default min-replicas-to-write is set to 0 (feature disabled) and # min-replicas-max-lag is set to 10.

 

Redis 主从复制-主从架构配置

一、命令行手动启用slave节点(临时生效,无需重启服务,重启服务后配置失效,配合修改配置文件使用)

[root@Redis-Ubuntu-1804-p20:~]# redis-cli -a redis -p 6379 --no-auth-warning replicaof 10.0.0.22 6379
OK
[root@Redis-Ubuntu-1804-p20:~]# redis-cli -a redis -p 6379 --no-auth-warning config set masterauth redis
OK
[root@Redis-Ubuntu-1804-p20:~]# redis-cli -a redis -p 6379 --no-auth-warning info replication
# Replication
role:slave
master_host:10.0.0.22
master_port:6379
master_link_status:up
master_last_io_seconds_ago:10
master_sync_in_progress:0
slave_repl_offset:2240
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:15f2ce5d08cf48fae39c85d8e1c7eddc591e6019
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:2240
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2157
repl_backlog_histlen:84
[root@Redis-Ubuntu-1804-p20:~]# 

 slave节点日志

1249:S 17 Apr 2023 23:28:04.587 * Retrying with SYNC...
1249:S 17 Apr 2023 23:28:04.588 # MASTER aborted replication with an error: NOAUTH Authentication required.
1249:S 17 Apr 2023 23:28:05.591 * Connecting to MASTER 10.0.0.22:6379
1249:S 17 Apr 2023 23:28:05.592 * MASTER <-> REPLICA sync started
1249:S 17 Apr 2023 23:28:05.592 * Non blocking connect for SYNC fired the event.
1249:S 17 Apr 2023 23:28:05.593 * Master replied to PING, replication can continue...
1249:S 17 Apr 2023 23:28:05.593 * (Non critical) Master does not understand REPLCONF listening-port: -NOAUTH Authentication required.
1249:S 17 Apr 2023 23:28:05.594 * (Non critical) Master does not understand REPLCONF capa: -NOAUTH Authentication required.
1249:S 17 Apr 2023 23:28:05.594 * Partial resynchronization not possible (no cached master)
1249:S 17 Apr 2023 23:28:05.595 # Unexpected reply to PSYNC from master: -NOAUTH Authentication required.
1249:S 17 Apr 2023 23:28:05.595 * Retrying with SYNC...
1249:S 17 Apr 2023 23:28:05.595 # MASTER aborted replication with an error: NOAUTH Authentication required.
1249:S 17 Apr 2023 23:28:06.600 * Connecting to MASTER 10.0.0.22:6379
1249:S 17 Apr 2023 23:28:06.600 * MASTER <-> REPLICA sync started
1249:S 17 Apr 2023 23:28:06.601 * Non blocking connect for SYNC fired the event.
1249:S 17 Apr 2023 23:28:06.601 * Master replied to PING, replication can continue...
1249:S 17 Apr 2023 23:28:06.603 * Partial resynchronization not possible (no cached master)
1249:S 17 Apr 2023 23:28:06.618 * Full resync from master: 15f2ce5d08cf48fae39c85d8e1c7eddc591e6019:2156
1249:S 17 Apr 2023 23:28:23.221 * MASTER <-> REPLICA sync: receiving 128170688 bytes from master
1249:S 17 Apr 2023 23:28:35.955 * MASTER <-> REPLICA sync: Flushing old data
1249:S 17 Apr 2023 23:28:36.012 * MASTER <-> REPLICA sync: Loading DB in memory
1249:S 17 Apr 2023 23:28:41.853 * MASTER <-> REPLICA sync: Finished with success

  命令行停用slave

[root@Redis-Ubuntu-1804-p20:~]# redis-cli -a redis -p 6379 --no-auth-warning replicaof no one
OK
[root@Redis-Ubuntu-1804-p20:~]# 


##停用slave日志
1249:M 17 Apr 2023 23:33:45.103 # Setting secondary replication ID to 15f2ce5d08cf48fae39c85d8e1c7eddc591e6019, valid up to offset: 2619. New replication ID is 5a3fd40a3ba2667fa6ce5012d05f3697b7aa4648
1249:M 17 Apr 2023 23:33:45.104 # Connection with master lost.
1249:M 17 Apr 2023 23:33:45.104 * Caching the disconnected master state.
1249:M 17 Apr 2023 23:33:45.104 * Discarding previously cached master state.
1249:M 17 Apr 2023 23:33:45.104 * MASTER MODE enabled (user request from 'id=18 addr=127.0.0.1:40576 fd=8 name= age=0 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=36 qbuf-free=32732 obl=0 oll=0 omem=0 events=r cmd=replicaof')  

 

二、通过修改配置文件内容,重启slave节点生效(永久生效,需要重启服务生效

replicaof 10.0.0.22 6379
masterauth redis

 slave节点状态信息变化  日志

[root@Redis-Ubuntu-1804-p21:~]# redis-cli -a redis -p 6379 --no-auth-warning info replication
# Replication
role:slave
master_host:10.0.0.22
master_port:6379
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0
slave_repl_offset:560
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:15f2ce5d08cf48fae39c85d8e1c7eddc591e6019
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:560
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:560
[root@Redis-Ubuntu-1804-p21:~]# 
1165:M 17 Apr 2023 17:37:47.563 * DB loaded from disk: 2.725 seconds
1165:M 17 Apr 2023 17:37:47.564 * Ready to accept connections
1165:signal-handler (1681743723) Received SIGTERM scheduling shutdown...
1165:M 17 Apr 2023 23:02:03.597 # User requested shutdown...
1165:M 17 Apr 2023 23:02:03.597 * Saving the final RDB snapshot before exiting.
1165:M 17 Apr 2023 23:02:03.607 * DB saved on disk
1165:M 17 Apr 2023 23:02:03.607 * Removing the pid file.
1165:M 17 Apr 2023 23:02:03.607 # Redis is now ready to exit, bye bye...
2560:C 17 Apr 2023 23:02:03.635 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2560:C 17 Apr 2023 23:02:03.635 # Redis version=5.0.14, bits=64, commit=00000000, modified=0, pid=2560, just started
2560:C 17 Apr 2023 23:02:03.635 # Configuration loaded
2560:C 17 Apr 2023 23:02:03.635 * supervised by systemd, will signal readiness
2560:S 17 Apr 2023 23:02:03.650 * Running mode=standalone, port=6379.
2560:S 17 Apr 2023 23:02:03.650 # Server initialized
2560:S 17 Apr 2023 23:02:03.651 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
2560:S 17 Apr 2023 23:02:03.651 * DB loaded from disk: 0.000 seconds
2560:S 17 Apr 2023 23:02:03.651 * Ready to accept connections
2560:S 17 Apr 2023 23:02:03.651 * Connecting to MASTER 10.0.0.22:6379
2560:S 17 Apr 2023 23:02:03.651 * MASTER <-> REPLICA sync started
2560:S 17 Apr 2023 23:02:03.652 * Non blocking connect for SYNC fired the event.
2560:S 17 Apr 2023 23:02:03.653 * Master replied to PING, replication can continue...
2560:S 17 Apr 2023 23:02:03.654 * Partial resynchronization not possible (no cached master)
2560:S 17 Apr 2023 23:02:03.672 * Full resync from master: 15f2ce5d08cf48fae39c85d8e1c7eddc591e6019:0
2560:S 17 Apr 2023 23:02:19.904 * MASTER <-> REPLICA sync: receiving 128170687 bytes from master
2560:S 17 Apr 2023 23:02:32.913 * MASTER <-> REPLICA sync: Flushing old data
2560:S 17 Apr 2023 23:02:32.914 * MASTER <-> REPLICA sync: Loading DB in memory
2560:S 17 Apr 2023 23:02:38.714 * MASTER <-> REPLICA sync: Finished with success
[root@Redis-Ubuntu-1804-p21:~]# 

 Master节点前后 info replication 变化

[root@Redis-Ubuntu-1804-p22:~]# redis-cli -a redis -p 6379 --no-auth-warning info replication
# Replication
role:master
connected_slaves:0
master_replid:c0b96732e4879ff1e2e0240ff64fcd61e42e1df2
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
[root@Redis-Ubuntu-1804-p22:~]# redis-cli -a redis -p 6379 --no-auth-warning info replication
# Replication
role:master
connected_slaves:1
slave0:ip=10.0.0.21,port=6379,state=wait_bgsave,offset=0,lag=0
master_replid:15f2ce5d08cf48fae39c85d8e1c7eddc591e6019
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:0
[root@Redis-Ubuntu-1804-p22:~]# redis-cli -a redis -p 6379 --no-auth-warning info replication
# Replication
role:master
connected_slaves:1
slave0:ip=10.0.0.21,port=6379,state=online,offset=1050,lag=1
master_replid:15f2ce5d08cf48fae39c85d8e1c7eddc591e6019
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:1050
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:1050
[root@Redis-Ubuntu-1804-p22:~]#

[root@Redis-Ubuntu-1804-p22:~]# redis-cli -a redis -p 6379 --no-auth-warning info replication
# Replication
role:master
connected_slaves:2
slave0:ip=10.0.0.21,port=6379,state=online,offset=4923406,lag=1
slave1:ip=10.0.0.20,port=6379,state=online,offset=4923406,lag=1
master_replid:15f2ce5d08cf48fae39c85d8e1c7eddc591e6019
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:4923406
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:3874831
repl_backlog_histlen:1048576

 

Redis 主从架构级联模式(分担Master数据同步额外造成的负载)

 只需要将二级slave节点master配置地址指向一级slave节点即可

[root@Redis-Ubuntu-1804-p20:~]# redis-cli -a redis -p 6379 --no-auth-warning replicaof 10.0.0.21 6379
OK
[root@Redis-Ubuntu-1804-p20:~]# redis-cli -a redis -p 6379 --no-auth-warning info replication
# Replication
role:slave
master_host:10.0.0.21
master_port:6379
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0
slave_repl_offset:4924134
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:15f2ce5d08cf48fae39c85d8e1c7eddc591e6019
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:4924134
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:4923085
repl_backlog_histlen:1050

##修改配置文件,保证服务意外重启后配置不丢失
[root@Redis-Ubuntu-1804-p20:~]# sed -i 's/replicaof 10.0.0.22 6379/replicaof 10.0.0.21 6379/' /app/redis/etc/redis_6379.conf
[root@Redis-Ubuntu-1804-p20:~]# grep ^replicaof /app/redis/etc/redis_6379.conf
replicaof 10.0.0.21 6379
[root@Redis-Ubuntu-1804-p20:~]# 

2403:S 18 Apr 2023 00:29:32.886 # Connection with master lost.
2403:S 18 Apr 2023 00:29:32.887 * Caching the disconnected master state.
2403:S 18 Apr 2023 00:29:32.887 * REPLICAOF 10.0.0.21:6379 enabled (user request from 'id=4 addr=127.0.0.1:33404 fd=7 name= age=0 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=44 qbuf-free=32724 obl=0 oll=0 omem=0 events=r cmd=replicaof')
2403:S 18 Apr 2023 00:29:33.126 * Connecting to MASTER 10.0.0.21:6379
2403:S 18 Apr 2023 00:29:33.127 * MASTER <-> REPLICA sync started
2403:S 18 Apr 2023 00:29:33.127 * Non blocking connect for SYNC fired the event.
2403:S 18 Apr 2023 00:29:33.129 * Master replied to PING, replication can continue...
2403:S 18 Apr 2023 00:29:33.131 * Trying a partial resynchronization (request 15f2ce5d08cf48fae39c85d8e1c7eddc591e6019:4924107).
2403:S 18 Apr 2023 00:29:33.132 * Successful partial resynchronization with master.
2403:S 18 Apr 2023 00:29:33.132 * MASTER <-> REPLICA sync: Master accepted a Partial Resynchronization.
2403:S 18 Apr 2023 00:36:40.249 * 1 changes in 900 seconds. Saving...
2403:S 18 Apr 2023 00:36:40.260 * Background saving started by pid 2477
2477:C 18 Apr 2023 00:37:10.438 * DB saved on disk
2477:C 18 Apr 2023 00:37:10.454 * RDB: 0 MB of memory used by copy-on-write
2403:S 18 Apr 2023 00:37:10.521 * Background saving terminated with success

#一级salve节点主从状态信息
[root@Redis-Ubuntu-1804-p21:~]# redis-cli -a redis -p 6379 --no-auth-warning info replication # Replication role:slave master_host:10.0.0.22 master_port:6379 master_link_status:up master_last_io_seconds_ago:8 master_sync_in_progress:0 slave_repl_offset:4924246 slave_priority:100 slave_read_only:1 connected_slaves:1 slave0:ip=10.0.0.20,port=6379,state=online,offset=4924246,lag=1 master_replid:15f2ce5d08cf48fae39c85d8e1c7eddc591e6019 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:4924246 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:3875671 repl_backlog_histlen:1048576 [root@Redis-Ubuntu-1804-p21:~]#
#Master节点主从状态
[root@Redis-Ubuntu-1804-p22:~]# redis-cli -a redis -p 6379 --no-auth-warning info replication
# Replication
role:master
connected_slaves:1
slave0:ip=10.0.0.21,port=6379,state=online,offset=4924610,lag=0
master_replid:15f2ce5d08cf48fae39c85d8e1c7eddc591e6019
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:4924610
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:3876035
repl_backlog_histlen:1048576
[root@Redis-Ubuntu-1804-p22:~]# 

  验证数据同步情况,并验证从节点只读效果

[root@Redis-Ubuntu-1804-p22:~]# redis-cli -a redis -p 6379 --no-auth-warning set test001 value001
OK
[root@Redis-Ubuntu-1804-p22:~]# redis-cli -a redis -p 6379 --no-auth-warning get test001
"value001"
[root@Redis-Ubuntu-1804-p22:~]# 

[root@Redis-Ubuntu-1804-p21:~]# redis-cli -a redis -p 6379 --no-auth-warning get test001
"value001"
[root@Redis-Ubuntu-1804-p21:~]# redis-cli -a redis -p 6379 --no-auth-warning set test002
(error) ERR wrong number of arguments for 'set' command
[root@Redis-Ubuntu-1804-p21:~]#

[root@Redis-Ubuntu-1804-p20:~]# redis-cli -a redis -p 6379 --no-auth-warning get test001
"value001"
[root@Redis-Ubuntu-1804-p20:~]# redis-cli -a redis -p 6379 --no-auth-warning set test002
(error) ERR wrong number of arguments for 'set' command
[root@Redis-Ubuntu-1804-p20:~]#