linux 搭建Redis 主从复制

Redis 主从搭建

将redis.conf配置文件复制三份

分别为 命名为:
redis6380.conf
redis6381.conf
redis6382.conf


需要修改的配置文件内容如下

  • redis6380.conf

    bind 0.0.0.0    # (配置文件69行)
    
    protected-mode:no  # (配置文件88行)
    
    prot 6380   # (配置文件92行)
    
    pidfile /var/run/redis_6380.pid # (配置文件158行)
    
  • redis6381.conf

    bind 0.0.0.0    # (配置文件69行)
    
    protected-mode:no  # (配置文件88行)
    
    prot 6381   # (配置文件92行)
    
    pidfile /var/run/redis_6381.pid # (配置文件158行)
    
    slaveof 127.0.0.1 6380  # (配置文件21行)
    
    replicaof 192.168.218.130 6380  # (配置文件286行)
    
    masterauth 123456  # (配置文件293行)
    
  • redis6382.conf

    bind 0.0.0.0    # (配置文件69行)
      
    protected-mode:no  # (配置文件88行)
      
    prot 6382   # (配置文件92行)
      
     pidfile /var/run/redis_6382.pid # (配置文件158行)
     
     slaveof 127.0.0.1 6380  # (配置文件21行)
     
     replicaof 192.168.218.130 6380  # (配置文件286行)
     
     masterauth 123456  # (配置文件293行)
    

然后通过配置文件分别启动3个服务:

分别启动三个服务:

[root@Test1 redis-5.0.3]# src/redis-server  redis6380.conf
[root@Test1 redis-5.0.3]# src/redis-server  redis6381.conf
[root@Test1 redis-5.0.3]# src/redis-server  redis6382.conf

分别进入三个服务的客户端:

从服务器 能获取到 主服务器 的key则为配置成功

  • 启动主服务器:
[root@Test1 redis-5.0.3]# src/redis-cli  -p 6380 -a 123456
127.0.0.1:6380> set name wll
OK
127.0.0.1:6380> get name
"wll"
  • 启动从服务器客户端:
[root@Test1 redis-5.0.3]# src/redis-cli -p 6381 -a 123456
127.0.0.1:6381> get name
"wll"
  • 启动第二台从服务器客户端:
[root@Test1 redis-5.0.3]# src/redis-cli -p 6382  -a 123456
127.0.0.1:6382> get name
"wll"
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值