Redis主从复制

本次搭建一个一主2从的模式

1.进入redis目录中,创建3个conf文件,分别是redis6379.conf 、 redis6380.conf 、redis6381.conf。

redis6379.conf配置如下:

include redis.conf
pidfile /var/run/redis_6379.pid
port 6379
dbfilename dump6379.rdb

redis6380.conf配置如下:

include redis.conf
pidfile /var/run/redis_6380.pid
port 6380
dbfilename dump6380.rdb

redis6381.conf配置如下:

include redis.conf
pidfile /var/run/redis_6381.pid
port 6381
dbfilename dump6381.rdb

2.分别启动 6379、6380、6381这3个redis服务

3.进入6380和6381的客户端,输入命令slaveof ip:端口 把他们变更成从服务。然后输入命令info replication查看当前服务节点的状态。

[root@localhost redis-6.2.1]# redis-cli -h 192.168.80.140 -p 6380
127.0.0.1:6380> slaveof 192.168.80.140 6379
OK
127.0.0.1:6380> info replication
# Replication
role:slave
[root@localhost redis-6.2.1]# redis-cli -h 192.168.80.140 -p 6381
127.0.0.1:6381> slaveof 192.168.80.140 6379
OK
127.0.0.1:6381> info replication
# Replication
role:slave

 进入 6379节点中查看6380和6381已变成了从节点。

192.168.80.140:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.80.140,port=6380,state=online,offset=42,lag=0
slave1:ip=192.168.80.140,port=6381,state=online,offset=42,lag=0

4.在主节点6379中添加一个key,然后在6380中能看到这个key,说明节点数据已同步。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值