redis的主从配置
环境描述:
主Redis:192.168.1.4 6379 (以下简称M4)
从redis:192.168.1.3 6379 (以下简称M3)
一、主从配置
1、将M3redis配置文件redis.conf中的
aemonize no 改为 yes requirepass 123456 #设置redis连接密码。
2、修改M3从redis配置文件redis.conf
slaveof 192.168.1.4 6379 masterauth 123456
重启redis服务。
二、测试数据同步
[root@centos-04 ~]# redis-cli -h 192.168.1.4 -p 6379 -a 123456 192.168.1.4:6379> set namesys 11111 OK [root@centos-03 redis]# redis-cli -h 192.168.1.3 -p 6379 -a 123456 192.168.1.3:6379> get namesys "11111" 192.168.1.3:6379> set name1 1234 (error) READONLY You can't write against a read only slave.
主从设置成功。
参考:
http://blog.csdn.net/zfl092005/article/details/17523945