Redis主从部署

Redis主从部署

  • 配置

    • redis目录下创建master、slave1、slave2三个目录,每个目录下分别创建一个redis.conf

    • 修改slave的redis配置文件

      1
      2
      slaveof ip port(映射到主服务器上)
      masterauth pwd
    • 分表启动master、slave1、slave2三个服务

      在三个服务下分别执行info命令

      master显示如下

      slave显示如下

    ​ 则三个服务启动成功

  • 哨兵监控–可以自动切换故障主从

    • redis目录下创建sentinel1.conf、sentinel2.conf、sentinel3.conf、sentinel1.log、sentinel2.log、sentinel3.log

    • sentinel.conf配置如下

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      #端口
      port **
      #后端启动
      daemonize yes
      #日志文件路径
      logfile "/install/redis/redis-3.2.1/sentinel.log”
      #唯一id,选举时用到
      sentinel myid a36dd6517a54a4fb8f0e1024c3acaa16417652d0 id
      #监控redis主库
      sentinel monitor mymaster 127.0.0.1 6384 2
      #多久不回复心跳反应,则默认服务不可用
      redis sentinel down-after-milliseconds mymaster 5000
      #认证密码配置
      sentinel auth-pass mymaster 123456
      #保护模式关闭
      protected-mode no
    • 分表启动三个哨兵sentinel.conf