redis-sentinel哨兵模式部署

https://blog.51cto.com/9025736/2498152

consul集群部署参考文章

https://blog.51cto.com/9025736/2500976

规划

consul实现redis-sentinelHA高可用-02_第1张图片

配置redis-sentinel自动切换主节点配置(仅需要consul_client节点配置)

[root@server3 consul.d]# cat redis-6379.json 
 {
   "services": [
     {
       "id": "redisnode1",
       "name": "redis",
       "tags": [
         "master"
       ],
       "address": "192.168.31.178",
       "port": 6379,
       "checks": [
         {
           "args": ["/usr/bin/bash","/data/a.sh"],
           "interval": "5s"
         }
       ]
     },
     {
       "id": "redisnode2",
       "name": "redis",
       "tags": [
         "master"
       ],
       "address": "192.168.31.179",
       "port": 6379,
       "checks": [
         {
           "args": ["/usr/bin/bash","/data/b.sh"],
           "interval": "5s"
         }
       ]
     },
     {
       "id": "redisnode3",
       "name": "redis",
       "tags": [
         "master"
       ],
       "address": "192.168.31.180",
       "port": 6379,
       "checks": [
         {
           "args": ["/usr/bin/bash","/data/c.sh"],
           "interval": "5s"
         }
       ]
     }
   ]
 }
    consul reload
注意:在consul json配置文件中,每个consul agent的service里面 id都不能重复,name是强制要求的,必须要有,如果id省略,则跟name来匹配,其他的都是可选的,可有可无。但为了能够使用某条服务信息,就必须要有IP和port,当然port可以在应用中指定。check最好要有,否则当出现问题时不能从consul中注销。

可以访问http://192.168.31.178/v1/catalog/service/redis来查看服务

dig检查

consul实现redis-sentinelHA高可用-02_第2张图片
consul实现redis-sentinelHA高可用-02_第3张图片
consul实现redis-sentinelHA高可用-02
consul实现redis-sentinelHA高可用-02

redis测试consul是否可以切换

停止192.168.31.178 redis-server

consul实现redis-sentinelHA高可用-02_第4张图片
consul实现redis-sentinelHA高可用-02_第5张图片
停止192.168.31.180 redis-server 开启 192.168.31.178 redis-server
consul实现redis-sentinelHA高可用-02
consul实现redis-sentinelHA高可用-02
consul实现redis-sentinelHA高可用-02_第6张图片
consul实现redis-sentinelHA高可用-02_第7张图片