Redis主从配置
环境: Mater: 192.168.238.131 Slave: 192.168.238.108 redis安装包:redis-6.2.5.tar.gz redis安装方式:源码安装
操作步骤:
[root@localhost tool]
[root@localhost tool]
[root@localhost redis-6.2.5]
[root@localhost redis-6.2.5]
将/usr/local/redis/redis.conf文件中,
bind 127.0.0.1 -::1
修改为
bind 0.0.0.0
systemctl stop firewalld
/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
nohup /usr/local/redis/bin/redis-server /usr/local/redis/redis.conf &
在/usr/local/redis/redis.conf文件添加
replicaof 192.168.238.131 6379
/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
nohup /usr/local/redis/bin/redis-server /usr/local/redis/redis.conf &
- 执行/usr/local/redis/bin/redis-cli ,通过info命令,查看redis主从信息和状态
- 验证redis主从配置
如图,先在左侧master机器上set键值,然后到右侧slave机器上去get键值,会发现已经从左侧master同步到了右侧slave
/usr/local/redis/bin/redis-cli -p 6379 shutdown
总结:
只需要在redis主库192.168.238.131配置文件中,修改bind绑定IP
只需要在Redis丛库192.168.238.108配置文件中,设置如下指令,replicaof表示指定主库的IP,192.168.238.131为master服务器,6379为master服务器Redis端口
|