1. 程式人生 > 實用技巧 >liunx簡單部署redis主從配置

liunx簡單部署redis主從配置

首先準備三臺以安好的redis,選擇一臺做主倆臺做從伺服器
redis-master----192.168.246.202
redis-slave-1-----192.168.246.203
redis-slave-2-----192.168.246.204
編輯master的redis配置檔案
[[email protected] redis]# vim redis.conf
在這裡插入圖片描述
修改slave1的配置檔案
[[email protected] redis]# vim redis.conf
在這裡插入圖片描述在這裡插入圖片描述
修改slave2的配置檔案
[[email protected] redis]# vim redis.conf #和slave1一樣

4.重啟三臺redis
systemctl restart redis
5.測試主從
1.在master上面執行
[[email protected] redis]# cd src/
[[email protected] src]# ./redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set name xuan
OK
127.0.0.1:6379> get name
“xuan”
127.0.0.1:6379>
2.分別在slave-1和slave-2上面執行:
[[email protected] redis]# cd src/
[[email protected] src]# ./redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> get name
“xuan”
127.0.0.1:6379>
[[email protected] src]# ./redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> get name
“xuan”
127.0.0.1:6379>
檢視複製狀態
master執行:
127.0.0.1:6379> info replication
#Replication
role:master
connected_slaves:2
slave0:ip=192.168.246.203,port=6379,state=online,offset=490,lag=0
slave1:ip=192.168.246.204,port=6379,state=online,offset=490,lag=1

slave上面執行:
127.0.0.1:6379> info replication
#Replication
role:slave
master_host:192.168.246.202
master_port:6379
master_link_status:up