数据管理与分析-Redis部署:配置哨兵

时间:2024-04-24 11:34:42

配置哨兵

  1. 创建哨兵数据目录
    # mkdir /data/redis-6.0.0/data/sentinel
  2. 新增配置文件
    # vim /opt/redis-6.0.0/config/sentinel/sentinel.conf
  3. 分别在主从redis创建sentinel配置文件(3个实例一样)
    port 16379
    daemonize yes
    pidfile /var/run/redis-sentinel.pid
    logfile /data/redis-6.0.0/logs/sentinel.log
    dir /data/redis-6.0.0/data/sentinel
    sentinel deny-scripts-reconfig yes
    #配置主redis的地址,“2”表示集群中有2个Sentinel认为master退出了就切换
    sentinel monitor redisMaster 192.168.0.82 6379 2
    sentinel auth-pass redisMaster Mypwd@123456
    sentinel config-epoch redisMaster 1
    sentinel leader-epoch redisMaster 1
  4. 启动哨兵,分别在主从redis创建redis-sentinel系统启动文件
    # vim /etc/systemd/system/redis-sentinel.service
    [Unit]
    Description=The redis-sentinel Process Manager
    After=syslog.target network.target
    [Service]
    Type=forking
    PIDFile=/var/run/redis-sentinel.pid
    ExecStart=/opt/redis-6.0.0/bin/redis-sentinel /opt/redis-6.0.0/config/sentinel/sentinel.conf
    ExecStop=/opt/redis-6.0.0/bin/redis-cli -h 127.0.0.1 -p 16379 shundown
    PrivateTmp=true
    [Install]
    WantedBy=multi-user.target
  5. 重新加载systemctl配置
    # systemctl daemon-reload
  6. 设置跟随linux启动,并启动es
    # systemctl start redis-sentinel && systemctl enable redis-sentinel
  7. 查看启动日志
    # cat /data/redis-6.0.0/logs/sentinel.log
    图2 查看启动日志
  8. 检查redis主从状态
    # redis-cli -h 127.0.0.1 -p 6379 -a Mypwd@123456 info replication
    图3 查看启动日志
    # Replication
    role:master          #角色master或者slave
    connected_slaves:2    #连接的slave个数
    min_slaves_good_slaves:2
    slave0:ip=192.168.0.228 ,port=6379,state=online,offset=288218,lag=0   #slave1节点信息
    slave1:ip=192.168.0.56,port=6379,state=online,offset=288078,lag=1   #slave2节点信息
    master_replid:2ac8c63f0185a38189010b192e42b761e69f549a
    master_replid2:4490ff668a9d41d5636e6a382ff1e80ca31892cf
    master_repl_offset:288218
    master_repl_meaningful_offset:288218
    second_repl_offset:69703
    repl_backlog_active:1
    repl_backlog_size:1048576
    repl_backlog_first_byte_offset:1
    repl_backlog_histlen:288218
support.huaweicloud.com/deepexidip-dma/deepexidip_13.html