Redis主从环境布置

1.Redis主从一块原理

redis主服务器会周期性的把立异的数额写入磁盘或者把修改操作写入追加的笔录文件,然后将数据文件同步给从服务器,从服务器加载记录文件,在内存库中立异新数据.

2.VMWare配置2台服务器

在已设置好redis服务的虚拟机,重命名为Redis-Master(主机),另外克隆一个虚拟机,重命名Redis-Slave(从机)

图片 1

查看IP:192.168.74.128;

查阅IP跟主机同一网段192.168.74.129;

开辟PuTTY(session1),连接主机,(session2),连接从机.

session1启动主机的Redis服务,我们得以看来前几天库里没有任何key;

 

图片 2

长机不用怎么设置,session2从机打开redis.conf文件设置如下:

# 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.
#
# 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.
# 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.
# 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.
#
# slaveof <masterip> <masterport>
slaveof 192.168.74.128 6379

如若主机设置了密码,在此处安装连接主机的密码

# 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.
#
# masterauth <master-password>
masterauth 123456

起步session2起动从机Redis服务,并用客户端连接,同样数据库为空.

图片 3

那时,session1中主机增添一个key,切换到session2,从机立即能获取主机同步过来的数额,这样实现了主旨的数额同步.

图片 4