1.準(zhǔn)備環(huán)境
三臺(tái)linux環(huán)境,并且都安裝好redis
redis安裝:http://www.reibang.com/p/0b3fda241848
本人配置環(huán)境分別為:192.168.78.137? 192.168.78.138? 192.168.78.139
其中137為master
2.修改redis的配置文件
修改從節(jié)點(diǎn)(138踏志,139)的redis.conf配置
2.1添加追隨的master配置
在redis.conf配置中的 replication 配置段中添加? slaveof 192.168.78.137 6379
2.2如果master配置了密碼需要添加master的密碼配置
在上一步的配置下面添加?masterauth [master密碼]
3.分別啟動(dòng)臺(tái)機(jī)器的redis
注意:啟動(dòng)三臺(tái)機(jī)器的時(shí)候需要在啟動(dòng)命令后面添加啟動(dòng)配置文件redis.conf寺旺;如:redis-server reids.conf
4.啟動(dòng)成功校驗(yàn)
59080:S 12 Jun 2020 03:33:12.768 * DB loaded from disk: 0.000 seconds
59080:S 12 Jun 2020 03:33:12.768 * Ready to accept connections
59080:S 12 Jun 2020 03:33:12.768 * Connecting to MASTER 192.168.78.137:6379
59080:S 12 Jun 2020 03:33:12.768 * MASTER <-> REPLICA sync started
59080:S 12 Jun 2020 03:33:12.768 * Non blocking connect for SYNC fired the event.
59080:S 12 Jun 2020 03:33:12.769 * Master replied to PING, replication can continue...
59080:S 12 Jun 2020 03:33:12.769 * Partial resynchronization not possible (no cached master)
59080:S 12 Jun 2020 03:33:12.789 * Full resync from master: d1eb320d7d6a6b431399d83ab781f97c2a6ba3df:0
59080:S 12 Jun 2020 03:33:12.847 * MASTER <-> REPLICA sync: receiving 210 bytes from master
59080:S 12 Jun 2020 03:33:12.847 * MASTER <-> REPLICA sync: Flushing old data
59080:S 12 Jun 2020 03:33:12.847 * MASTER <-> REPLICA sync: Loading DB in memory
59080:S 12 Jun 2020 03:33:12.847 * MASTER <-> REPLICA sync: Finished with success
啟動(dòng)日志中出現(xiàn)如上日志信息的時(shí)候表示追隨master成功
還可以通過啟動(dòng)各節(jié)點(diǎn)的客戶端谬晕,在命令框中輸入 info replication 命令來查看,輸出信息如下:
# Replication
role:slave
master_host:192.168.78.137
master_port:6379
master_link_status:up
master_last_io_seconds_ago:7
master_sync_in_progress:0
slave_repl_offset:4020
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:d1eb320d7d6a6b431399d83ab781f97c2a6ba3df
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:4020
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:3993
repl_backlog_histlen:28
5.接下來在master中添加數(shù)據(jù)校驗(yàn)是否復(fù)制成功
自行測試,只是簡單的redis命令