Redis 4.0主從複製配置

feelpurple發表於2017-11-04
Master:    192.168.174.201
Slave: 192.168.174.202

在兩臺伺服器上面安裝Redis,參考
http://blog.itpub.net/26506993/viewspace-2146826/

在主節點上,編輯配置檔案
[root@MySQL01 redis-4.0.2]# vim redis.conf
# 指定埠
port 6379

# 配置密碼
requirepass abc

# 監聽來自網路的所有連線
# bind 127.0.0.1

在從節點上,編輯配置檔案

[root@localhost redis-4.0.2]# vim redis.conf
# 配置主節點的IP和埠
slaveof 192.168.174.201 6379

配置連線到主庫所使用的密碼
masterauth abc

# 配置密碼
requirepass abc

# 監聽來自網路的所有連線
# bind 127.0.0.1

# 指定埠
port 6380

在主節點上,啟動redis
[root@MySQL01 redis-4.0.2]# src/redis-server redis.conf 
51173:C 04 Nov 07:12:09.019 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
51173:C 04 Nov 07:12:09.019 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=51173, just started
51173:C 04 Nov 07:12:09.019 # Configuration loaded

在從節點上,啟動redis
[root@localhost redis-4.0.2]# src/redis-server /opt/redis-4.0.2/redis.conf 
61391:C 04 Nov 07:14:10.695 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
61391:C 04 Nov 07:14:10.695 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=61391, just started
61391:C 04 Nov 07:14:10.695 # Configuration loaded

驗證複製
在主節點上面插入連結串列資料
[root@MySQL01 redis-4.0.2]# src/redis-cli -a abc
127.0.0.1:6379> rpush list-key item1
(integer) 1
127.0.0.1:6379> rpush list-key item2
(integer) 2
127.0.0.1:6379> rpush list-key item3
(integer) 3
127.0.0.1:6379> lrange list-key 0 -1
1) "item1"
2) "item2"
3) "item3"

檢視複製狀態
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.174.202,port=6380,state=online,offset=1785,lag=0
master_replid:17cc14861639f71ed1f82ce9999f22ff337014e4
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:1785
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:1785

在從節點上面檢視連結串列資料
[root@localhost redis-4.0.2]# src/redis-cli -h 192.168.174.202 -p 6380 -a abc
192.168.174.202:6380> lrange list-key 0 -1
1) "item1"
2) "item2"
3) "item3"

檢視複製狀態
192.168.174.202:6380> info replication
# Replication
role:slave
master_host:192.168.174.201
master_port:6379
master_link_status:up
master_last_io_seconds_ago:6
master_sync_in_progress:0
slave_repl_offset:1771
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:17cc14861639f71ed1f82ce9999f22ff337014e4
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:1771
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:1771

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2146831/,如需轉載,請註明出處,否則將追究法律責任。

相關文章