centos 搭建redis主從

大飛_dafei發表於2018-11-16

!!! 由於這是在虛擬機器中做的測試,配置過程中可能出現錯誤,記得看日誌

檢視主從資訊:  info replication

搭建主從確保,兩臺伺服器直接可以連通, ping 連線ok, redis 互相可以登入

redis 主: 192.168.56.3      redis 從: 192.168.56.101 

我的這兩臺伺服器redis密碼都設定為123456, redis.conf 中bind 已經註釋

1). 測試1:

[root@localhost vagrant]# ping 192.168.56.101
PING 192.168.56.101 (192.168.56.101) 56(84) bytes of data.
64 bytes from 192.168.56.101: icmp_seq=1 ttl=64 time=0.149 ms
64 bytes from 192.168.56.101: icmp_seq=2 ttl=64 time=0.163 ms
64 bytes from 192.168.56.101: icmp_seq=3 ttl=64 time=0.152 ms
64 bytes from 192.168.56.101: icmp_seq=4 ttl=64 time=0.173 ms
^C
--- 192.168.56.101 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.149/0.159/0.173/0.013 ms
[root@localhost vagrant]# 
[root@localhost vagrant]# ping 192.168.56.3
PING 192.168.56.3 (192.168.56.3) 56(84) bytes of data.
64 bytes from 192.168.56.3: icmp_seq=1 ttl=64 time=0.175 ms
64 bytes from 192.168.56.3: icmp_seq=2 ttl=64 time=0.134 ms
64 bytes from 192.168.56.3: icmp_seq=3 ttl=64 time=0.149 ms
64 bytes from 192.168.56.3: icmp_seq=4 ttl=64 time=0.140 ms
^C
--- 192.168.56.3 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.134/0.149/0.175/0.019 ms
[root@localhost vagrant]# 

測試2 , redis 互相登入:

#在192.168.56.3 上登入 192.168.56.101

[root@localhost vagrant]#  /usr/bin/redis-cli -h 192.168.56.101 -a 123456
192.168.56.101:6379> keys *



#在192.168.56.101 上登入 192.168.56.3

[root@localhost vagrant]# /usr/bin/redis-cli -h 192.168.56.3 -a 123456
192.168.56.3:6379> keys *

2).  配置主從:

在conf伺服器上 redis.conf 中配置  

slaveof 192.168.56.3 6379

masterauth 123456

3). 配置完畢,測試資料:

 

相關文章