环境

主机名 地址 操作系统 初始状态
sentinel86 10.1.14.86 CentOS7.4 null
redis87 10.1.14.87 CentOS7.4 master
redis88 10.1.14.88 CentOS7.4 slave
redis89 10.1.14.89 CentOS7.4 slave

安装 redis

  • 在全部服务器上安装 redis

    1
    2
    
    yum install epel-release
    yum install redis

redis master 配置

  • 在 redis87 上修改 /etc/redis.conf

    1
    
    bind 0.0.0.0

redis slave 配置

  • 在 redis88 和 redis89 上修改 /etc/redis.conf

    1
    2
    
    bind 0.0.0.0
    slaveof 10.1.14.87 6379

redis sentinel 配置

  • 在 sentinel86 上创建三个 sentinel 配置文件

    1
    2
    3
    4
    5
    
    cd /etc/
    cp redis-sentinel.conf redis-sentinel-16379.conf
    cp redis-sentinel.conf redis-sentinel-26379.conf
    mv redis-sentinel.conf redis-sentinel-36379.conf
    chown redis.root redis-sentinel-?6379.conf
  • 修改 /etc/redis-sentinel-16379.conf

    1
    2
    3
    4
    5
    6
    
    bind 0.0.0.0
    port 16379
    dir /var/log/redis/16379
    sentinel monitor mymaster 10.1.14.87 6379 2
    sentinel down-after-milliseconds mymaster 8000
    logfile /var/log/redis/16379/sentinel.log
  • 修改 /etc/redis-sentinel-26379.conf

    1
    2
    3
    4
    5
    6
    
    bind 0.0.0.0
    port 26379
    dir /var/log/redis/26379
    sentinel monitor mymaster 10.1.14.87 6379 2
    sentinel down-after-milliseconds mymaster 8000
    logfile /var/log/redis/26379/sentinel.log
  • 修改 /etc/redis-sentinel-36379.conf

    1
    2
    3
    4
    5
    6
    
    bind 0.0.0.0
    port 36379
    dir /var/log/redis/36379
    sentinel monitor mymaster 10.1.14.87 6379 2
    sentinel down-after-milliseconds mymaster 8000
    logfile /var/log/redis/36379/sentinel.log
  • 创建日志目录

    1
    2
    3
    
    cd /var/log/redis/
    mkdir 16379 26379 36379
    chown redis.redis ?6379 -R
  • 创建两个 sentinel service 文件

    1
    2
    3
    4
    
    cd /usr/lib/systemd/system/
    cp redis-sentinel.service redis-sentinel-16379.service
    cp redis-sentinel.service redis-sentinel-26379.service
    mv redis-sentinel.service redis-sentinel-36379.service
  • 修改 /usr/lib/systemd/system/redis-sentinel-16379.service

    1
    2
    
    ExecStart=/usr/bin/redis-sentinel /etc/redis-sentinel-16379.conf --daemonize no
    ExecStop=/usr/libexec/redis-shutdown redis-sentinel-16379
  • 修改 /usr/lib/systemd/system/redis-sentinel-26379.service

    1
    2
    
    ExecStart=/usr/bin/redis-sentinel /etc/redis-sentinel-26379.conf --daemonize no
    ExecStop=/usr/libexec/redis-shutdown redis-sentinel-26379
  • 修改 /usr/lib/systemd/system/redis-sentinel-36379.service

    1
    2
    
    ExecStart=/usr/bin/redis-sentinel /etc/redis-sentinel-36379.conf --daemonize no
    ExecStop=/usr/libexec/redis-shutdown redis-sentinel-36379
  • 更新服务

    1
    
    systemctl daemon-reload

启动 redis 服务

  • 在 redis87、redis88 和 redis89 上启动 redis 服务

    1
    2
    3
    
    systemctl start redis
    # 查看当前节点主从信息
    redis-cli info replication

启动 redis sentinel 监控

  • 在 sentinel86 上启动 sentinel 监管程序

    1
    2
    3
    
    systemctl start redis-sentinel-16379
    systemctl start redis-sentinel-26379
    systemctl start redis-sentinel-36379