1.准备环境
三台linux环境,并且都安装好redis
redis安装:https://www.jianshu.com/p/0b3fda241848
本人配置环境分别为:192.168.78.137 192.168.78.138 192.168.78.139
其中137为master
2.修改redis的配置文件
修改从节点(138,139)的redis.conf配置
2.1添加追随的master配置
在redis.conf配置中的 replication 配置段中添加 slaveof 192.168.78.137 6379
2.2如果master配置了密码需要添加master的密码配置
在上一步的配置下面添加 masterauth [master密码]
3.分别启动台机器的redis
注意:启动三台机器的时候需要在启动命令后面添加启动配置文件redis.conf;如:redis-server reids.conf
4.启动成功校验
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
启动日志中出现如上日志信息的时候表示追随master成功
还可以通过启动各节点的客户端,在命令框中输入 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中添加数据校验是否复制成功
自行测试,只是简单的redis命令