- 主从配置
1.环境描述:
master主:192.168.1.93 6379
slave:192.1681..111 6380
2.准备工作:
修改主从配置文件redis.conf,
将 daemonize no 改为 daemonize yes
将 bind 127.0.0.1 改为 bind 0.0.0.0
daemonize yes
bind 0.0.0.0
修改slave**redis的端口号为**6780
port 6380
3.启动主从服务
[root@localhost src]
[root@localhost src]
127.0.0.1:6379>
[root@localhost src]
[root@localhost src]
127.0.0.1:6380>
在从redis执行slaveof 192.168.1.93 6379
127.0.0.1:6380> slaveof 192.168.1.93 6379
OK
4.OK,主从配置完成,在master和slave分别执行info命令,查看结果如下:
master:
slave:
5.测试数据同步
master:
127.0.0.1:6379> set result success
OK
127.0.0.1:6379> get result
"success"
127.0.0.1:6379>
slave:
127.0.0.1:6380> get result
"success"
127.0.0.1:6380>
6.默认读写分离
127.0.0.1:6380> set result abc
(error) READONLY You can't write against a read only slave.
127.0.0.1:6380>