本文共 889 字,大约阅读时间需要 2 分钟。
准备:192.168.3.76上启动两个端口,模拟两台机器。
1、[root@centos7-2 ~]# cp /etc/redis.conf /etc/redis2.conf更改端口、日志文件2、[root@centos7-2 ~]# vim /etc/redis2.confport 6380pidfile /var/run/redis_6380.pidlogfile "/tmp/logs/redis2.log"dir /data/redis2#slaveof <masterip> <masterport>slaveof 127.0.0.1 6379###指定主服务器IP和端口#masterauth <master-password>###如果主服务器设定了密码,需要在从服务器上添加该参数3、启动[root@centos7-2 ~]# redis-server /etc/redis.conf[root@centos7-2 ~]# redis-server /etc/redis2.conf[root@centos7-2 ~]# netstat -nutlp| grep redistcp 0 0 127.0.0.1:6379 0.0.0.0: LISTEN 18001/redis-server tcp 0 0 127.0.0.1:6380 0.0.0.0: LISTEN 18684/redis-server4、测试,有数据
[root@centos7-2 ~]# redis-cli -h 127.0.0.1 -p 6380127.0.0.1:6380> keys *1) "key3"2) "key2"3) "key1"5、配置完成,和mysql不同的时,不用同步数据库,redis会自动同步到从服务器上
6、从服务上不能写入数据因为在master上slave-read-only yes ,所以只能读
转载于:https://blog.51cto.com/jacksoner/2049321