我是靠谱客的博主 欣喜母鸡,最近开发中收集的这篇文章主要介绍03、redis sentinel 测试实验,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

安装参考:https://blog.csdn.net/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>             

最后

以上就是欣喜母鸡为你收集整理的03、redis sentinel 测试实验的全部内容,希望文章能够帮你解决03、redis sentinel 测试实验所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部