![Redis 6 主从复制配置教程-程序旅途](https://www.chengxulvtu.net/wp-content/uploads/2022/06/2022060520413465.jpg)
本文讲一下 Redis 6 主从复制的配置。
两台服务器:45.46.178.220 (主)和 45.46.178.221 (从),在两台服务器上安装好 Redis。
我的 Redis 版本是 6.2.6
![Redis 6 主从复制配置教程-程序旅途](https://www.chengxulvtu.net/wp-content/uploads/2022/06/2022060516254569.png)
Master 配置
主服务器上修改 redis.conf 配置文件
bind 127.0.0.1 45.46.178.220
或
bind 0.0.0.0
保存,并重启 redis 服务,不要忘了开放端口。
Slave 配置
从服务器上修改 redis.conf 配置文件
replicaof 45.46.178.220 6379
masterauth 主redis密码
保存并重启 redis 服务。
测试主从复制
在主服务器上登录 redis,info replication 查看 redis 信息
![Redis 6 主从复制配置教程-程序旅途](https://www.chengxulvtu.net/wp-content/uploads/2022/06/2022060520173064.png)
上图中可以看到 role 为 master,有2个从节点,slave0 和 slave1
从服务器上登录 redis,info replication 查看 redis 信息
![Redis 6 主从复制配置教程-程序旅途](https://www.chengxulvtu.net/wp-content/uploads/2022/06/2022060520195779.png)
可以看到 role 为 slave,主服务器的信息,以及 master_link_status 为 up。
在主服务器上设置键值
set name1 aa
在从服务器上获取键值
get name1
![Redis 6 主从复制配置教程-程序旅途](https://www.chengxulvtu.net/wp-content/uploads/2022/06/2022060520270499.png)