天天看點

Redis主從配置

準備:192.168.3.76上啟動兩個端口,模拟兩台機器。

1、[root@centos7-2 ~]# cp /etc/redis.conf /etc/redis2.conf

更改端口、日志檔案

2、[root@centos7-2 ~]# vim /etc/redis2.conf

port 6380

pidfile /var/run/redis_6380.pid

logfile "/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 redis

tcp 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-server

4、測試,有資料

[root@centos7-2 ~]# redis-cli -h 127.0.0.1 -p 6380

127.0.0.1:6380> keys *

1) "key3"

2) "key2"

3) "key1"

5、配置完成,和mysql不同的時,不用同步資料庫,redis會自動同步到從伺服器上

6、從服務上不能寫入資料

Redis主從配置

因為在master上slave-read-only yes ,是以隻能讀

本文轉自 jiekegz  51CTO部落格,原文連結:http://blog.51cto.com/jacksoner/2049321