案例测试:
1. Master新增网卡,修改server端配置
IP : 192.168.40.128/24
注释: bind,支持网络连接
2. 新建虚机slave,配置网络,修改redis配置
#slaveof <masterip> <masterport>
slaveof 192.168.40.128 6379
# masterauth <master-password>
masterauth "zcy1991"
3. 启动redis,打开日志

4. 查看Replication信息
Master:

Slave:


5.配置文件 “主从复制”部分 【翻译+理解】 (Verion 3.2.8)
################################# REPLICATION (复制) #################################
-------------------------------------------
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#主从复制。 使用slaveof使一个Redis实例成为另一个Redis服务器的拷贝(副本)。
关于Redis复制的几个事情:
# 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 slaves.
1) Redis复制是 异步 的,但是如果它看起来没有与至少给定数量的slave连接,您可以配置一个主设备停止接受写入。
# 2) Redis slaves 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.
2) 如果复制链路丢失相对较少的时间,Redis slave能够与master执行部分重新同步。 您可能需要根据需要,使用合理的值配置replication backlog 大小(请参阅此文件的下一个操作)。
# 3) Replication is automatic and does not need user intervention. After a
# network partition slaves automatically try to reconnect to masters
# and resynchronize with them.
# 3) 复制是自动的,不需要用户干预。 网络分割后,slaves 自动尝试重新连接到masters 并与它们重新同步。
# slaveof <masterip> <masterport>
# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the slave to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the slave request.
#如果master使用密码保护(使用下面的“requirepass”配置指令),可以在开始复制同步过程之前,告诉slaves进行认证,否则master将拒绝slave连接请求。
# masterauth <master-password>
-------------------------------------------
# When a slave loses its connection with the master, or when the replication
# is still in progress, the slave can act in two different ways:
# 当一个slave与master断开连接或复制仍在进行时,slave可以采用两种不同的方式:
# 1) if slave-serve-stale-data is set to 'yes' (the default) the slave 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.
# 如果slave-serve-stale-data设置为“yes”(默认值),则slave仍将回复客户端请求,可能使用过期数据,或者如果这是第一次同步,则数据集可能为空。
# 2) if slave-serve-stale-data is set to 'no' the slave will reply with
# an error "SYNC with master in progress" to all the kind of commands
# but to INFO and SLAVEOF.
#如果slave-serve-stale-data设置为“no”,除了INFO和SLAVEOF,slave将回复错误“SYNC with master in progress”给所有类型的命令。
slave-serve-stale-data yes
# You can configure a slave instance to accept writes or not. Writing against
# a slave instance may be useful to store some ephemeral data (because data
# written on a slave will be easily deleted after resync with the master) but
# may also cause problems if clients are writing to it because of a
# misconfiguration.
# 您可以配置slave实例接受写入或不接受写入。 对slave实例进行写操作对存储一些临时数据可能是有用的(因为写在slave上的数据将在与master重新同步后很容易被删除),但是如果客户端因为错误配置而写入它,也会导致问题。
#
# Since Redis 2.6 by default slaves are read-only. 自2.6之后,slaves默认只读(不可写)
#
# Note: read only slaves 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 slave 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 slaves using 'rename-command' to shadow all the
# administrative / dangerous commands.
# 注意:只读slaves并不设计为了暴露给互联网上的不受信任的客户端。 它只是一个防止滥用实例的保护层。 Slaves默认情况下仍然可以导出所有管理命令,如CONFIG,DEBUG等。 在有限的程度上,您可以使用“rename-command”来提高只读从设备的安全性,以隐藏所有管理/危险命令。
#作为从服务器,默认情况下是只读的(yes),可以修改成NO,用于写(不建议
slave-read-only yes
-------------------------------------------
# Replication SYNC strategy: disk or socket. 复制同步策略: disk或socket
#
# -------------------------------------------------------
# WARNING: DISKLESS REPLICATION IS EXPERIMENTAL CURRENTLY 警告:无磁盘的复制当前还处于试验阶段。
# -------------------------------------------------------
#
# New slaves and reconnecting slaves 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 slaves.
# The transmission can happen in two different ways:
#是否使用socket方式复制数据。目前redis复制提供两种方式,disk和socket。如果新的slave连上来或者重连的slave无法部分同步,就会执行全量同步,master会生成rdb文件。有2种方式:disk方式是master创建一个新的进程把rdb文件保存到磁盘,再把磁盘上的rdb文件传递给slave。socket是master创建一个新的进程,直接把rdb文件以socket的方式发给slave。disk方式的时候,当一个rdb保存的过程中,多个slave都能共享这个rdb文件。socket的方式就的一个个slave顺序复制。在磁盘速度缓慢,网速快的情况下推荐用socket方式。
#新的slaves和重新连接的slaves,不能继续复制过程只是接收差异,需要做的就是所谓的“完全同步”。 一个RDB文件从master传输到slaves。
# 传输可以以两种不同的方式发生:
# 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 slaves incrementally.
磁盘支持:Redis master创建一个新进程,负责将RDB文件写入磁盘。 稍后,该文件由父进程以增量方式传送到slaves。
# 2) Diskless: The Redis master creates a new process that directly writes the
# RDB file to slave sockets, without touching the disk at all.
#无盘:Redis master创建一个新的进程,直接将RDB文件写入slaves sockets,而不触及磁盘。
# With disk-backed replication, while the RDB file is generated, more slaves
# 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 slaves arriving will be queued and a new transfer
# will start when the current one terminates.
#使用"磁盘支持"的复制,在生成RDB文件时,只要生成RDB文件,当前子进程就完成了它的工作,更多的slaves就可以排队并被提供这一份RDB文件。(可同时提供给多个slaves)
# 使用无盘复制,一旦传输开始,新slaves到达将排队,并且当当前的一个终止时,新的传输将开始。(顺序复制,一个接一个)
# When diskless replication is used, the master waits a configurable amount of
# time (in seconds) before starting the transfer in the hope that multiple slaves
# will arrive and the transfer can be parallelized.
#当使用“无盘复制”时,master在开始传输之前等待可配置的时间量(以秒为单位),希望多个slaves将到达并且传输可以并行化。
#
# With slow disks and fast (large bandwidth) networks, diskless replication
# works better. 使用慢磁盘和快速(大带宽)网络,无盘复制工作更好(建议socket)
repl-diskless-sync no
# 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 slaves.
diskless复制的延迟时间,防止设置为0。一旦复制开始,节点不会再接收新slave的复制请求直到下一个rdb传输。所以最好等待一段时间,等更多的slave连上来。
#当启用无磁盘复制时,可以配置服务器等待的延迟,以便产生子进程,通过socket传输RDB给slaves。
# This is import