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>             

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章