一、实验环境
VMware创建两个虚拟机A(192.168.191.128)、B(192.168.191.130),在两个虚拟机上分别安装好Redis。并将redis.conf文件的daemonize no改为daemonize yes,以便redis服务在后台运行。
如果要A作为master,B作为slave,则A无需额外处理,B需对其redis.conf文件做如下配置:
(1)将port 6379修改为port 6380
(2)添加slaveof 192.168.191.128 6379 #即主redis的IP和port
二、测试
1、启动主从redis
will@ubuntu:~/redis-master$ redis-server ./redis.conf
will@ubuntu:~/redis-slave$ redis-server ./redis.conf
2、同步数据
(1)master:

(2)slave:

3、默认读写分离
在slave节点无法对msg进行设置和更改:

三、关闭主从redis
will@ubuntu:~/redis-master$ redis-cli -h localhost -p 6379 shutdown
will@ubuntu:~/redis-slave$ redis-cli -h localhost -p 6380 shutdown