03、redis sentinel 测试实验

本文档详细介绍了如何进行Redis Sentinel的配置和启动,包括主从节点的设置,Sentinel配置文件的创建,以及Sentinel节点的启动和验证过程。通过这些步骤,可以实现Redis高可用性的监控和故障转移。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装参考:https://blog.youkuaiyun.com/EVISWANG/article/details/94553100

1、配置文件:

   主节点配置:

       cat redis-7000.conf

       port 7000

       daemonize yes

       pidfile  /var/run/redis-7000.pid

       logfile "7000.log"

       dir  /opt/redis/data

    从节点配置:

       [root@centos03ms config]# sed "s/7000/7001/g"  redis-7000.conf >redis-7001.conf

       [root@centos03ms config]# cat redis-7002.conf

 

       port 7002

       daemonize yes

       pidfile  /var/run/redis-7002.pid

       logfile "7002.log"

       dir  /opt/redis/data

       slaveof  127.0.0.1 7000

 

       [root@centos03ms config]# cat redis-7001.conf

       port 7001

       daemonize yes

       pidfile  /var/run/redis-7001.pid

       logfile "7001.log"

       dir  /opt/redis/data

       slaveof  127.0.0.1 7000

 

2、启动主从节点:

      [root@centos03ms config]# redis-server redis-7000.conf

      [root@centos03ms config]# redis-server redis-7001.conf

      [root@centos03ms config]# redis-server redis-7002.conf

      [root@centos03ms config]# ps -ef |grep redis

      root     19874     1  0 00:11 ?        00:00:00 redis-server *:7000         

      root     19881     1  0 00:11 ?        00:00:00 redis-server *:7001         

      root     19885     1  0 00:11 ?        00:00:00 redis-server *:7002         

      root     19893 16693  0 00:11 pts/7    00:00:00 grep redis

      [root@centos03ms config]#

      

3、配置第一个sentinel的配置文件

      [root@centos03ms redis]# cp sentinel.conf ./config/sentinel.conf

      [root@centos03ms redis]# cd config/

      [root@centos03ms config]# cat sentinel.conf |grep -v "#" |grep -v "^$"

     

      daemonize yes

      port 26379

      dir /opt/redis/data/

      logfile "26379.log"

      sentinel monitor mymaster 127.0.0.1 7000 2

      sentinel down-after-milliseconds mymaster 30000

      sentinel parallel-syncs mymaster 1

      sentinel failover-timeout mymaster 180000

 

4、启动第一个sentinel

      [root@centos03ms config]# redis-sentinel redis-sentinel-26379.conf

      [root@centos03ms config]# ps -ef |grep redis-sentinel

      root     20989     1  0 00:49 ?        00:00:00 redis-sentinel *:26379 [sentinel]       

      root     20999 16693  0 00:49 pts/7    00:00:00 grep redis-sentinel

      [root@centos03ms config]#

      

      [root@centos03ms config]# redis-cli -p 26379

      127.0.0.1:26379> set hello word

      (error) ERR unknown command 'set'

      127.0.0.1:26379> ping

      PONG

      127.0.0.1:26379> info

      # Server

      redis_version:3.0.7

      redis_git_sha1:00000000

      redis_git_dirty:0

      redis_build_id:1a25b1c96c33e9a5

      redis_mode:sentinel

      os:Linux 2.6.32-504.el6.x86_64 x86_64

      arch_bits:64

      multiplexing_api:epoll

      gcc_version:4.4.7

      process_id:20989

      run_id:8cc1143d4562470e964b1aa4bc29b1afedc1edc6

      tcp_port:26379

      uptime_in_seconds:86

      uptime_in_days:0

      hz:11

      lru_clock:1805185

      config_file:/opt/redis-3.0.7/config/redis-sentinel-26379.conf

      

      # Sentinel

      sentinel_masters:1

      sentinel_tilt:0

      sentinel_running_scripts:0

      sentinel_scripts_queue_length:0

      master0:name=mymaster,status=ok,address=127.0.0.1:7000,slaves=2,sentinels=1

      127.0.0.1:26379>

 

   再看下sentinel配置:

     [root@centos03ms config]# cat redis-sentinel-26379.conf

     

     daemonize yes

     port 26379

     dir "/opt/redis-3.0.7/data"

     logfile "26379.log"

     sentinel monitor mymaster 127.0.0.1 7000 2

     sentinel config-epoch mymaster 0

     sentinel leader-epoch mymaster 0

     sentinel known-slave mymaster 127.0.0.1 7002

     # Generated by CONFIG REWRITE

     sentinel known-slave mymaster 127.0.0.1 7001

     sentinel current-epoch 0

     [root@centos03ms config]#  

 

5、配置第二、三个sentinel的配置文件:

     [root@centos03ms config]# sed "s/26379/26380/g" redis-sentinel-26379.conf > redis-sentinel-26380.conf

     [root@centos03ms config]# sed "s/26379/26381/g" redis-sentinel-26379.conf > redis-sentinel-26381.conf

     [root@centos03ms config]# cat redis-sentinel-26380.conf

     

     daemonize yes

     port 26380

     dir "/opt/redis-3.0.7/data"

     logfile "26380.log"

     sentinel monitor mymaster 127.0.0.1 7000 2

     sentinel config-epoch mymaster 0

     sentinel leader-epoch mymaster 0

     sentinel known-slave mymaster 127.0.0.1 7002

     # Generated by CONFIG REWRITE

     sentinel known-slave mymaster 127.0.0.1 7001

     sentinel current-epoch 0

     [root@centos03ms config]# cat redis-sentinel-26381.conf

     

     daemonize yes

     port 26381

     dir "/opt/redis-3.0.7/data"

     logfile "26381.log"

     sentinel monitor mymaster 127.0.0.1 7000 2

     sentinel config-epoch mymaster 0

     sentinel leader-epoch mymaster 0

     sentinel known-slave mymaster 127.0.0.1 7002

     # Generated by CONFIG REWRITE

     sentinel known-slave mymaster 127.0.0.1 7001

     sentinel current-epoch 0

     [root@centos03ms config]#      

   

   启动二、三节点的sentinel

     [root@centos03ms config]# redis-sentinel  redis-sentinel-26380.conf

     [root@centos03ms config]# redis-sentinel  redis-sentinel-26381.conf

     [root@centos03ms config]# ps -ef |grep redis-sentinel

     root     20989     1  0 00:49 ?        00:00:01 redis-sentinel *:26379 [sentinel]       

     root     21259     1  0 00:58 ?        00:00:00 redis-sentinel *:26380 [sentinel]       

     root     21266     1  0 00:58 ?        00:00:00 redis-sentinel *:26381 [sentinel]       

     root     21273 19342  0 00:59 pts/9    00:00:00 grep redis-sentinel

     [root@centos03ms config]#  

     

   验证:

     [root@centos03ms config]# redis-cli -p 26381

     127.0.0.1:26381> info sentinel

     # Sentinel

     sentinel_masters:1

     sentinel_tilt:0

     sentinel_running_scripts:0

     sentinel_scripts_queue_length:0

     master0:name=mymaster,status=ok,address=127.0.0.1:7000,slaves=2,sentinels=3

     127.0.0.1:26381>             

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值