sentinel节点是一个特殊的redis节点,有自己专属的API
API
sentinel masters
展示所有被监控的主节点状态以及相关的统计信息, 例如:
127.0.0.1:26379> sentinel masters
1) 1) "name"
2) "mymaster-2"
3) "ip"
4) "127.0.0.1"
5) "port"
6) "6382"
.........忽略............
2) 1) "name"
2) "mymaster-1"
3) "ip"
4) "127.0.0.1"
5) "port"
6) "6379"
.........忽略............
sentinel master < master name >
展示指定 < master name >的主节点状态以及相关的统计信息, 例如:
127.0.0.1:26379> sentinel master mymaster-1
1) "name"
2) "mymaster-1"
3) "ip"
4) "127.0.0.1"
5) "port"
6) "6379"
.........忽略............
sentinel slaves< master name >
展示指定< master name>的从节点状态以及相关的统计信息, 例如:
127.0.0.1:26379> sentinel slaves mymaster-1
1) 1) "name"
2) "127.0.0.1:6380"
3) "ip"
4) "127.0.0.1"
5) "port"
6) "6380"
.........忽略............
2) 1) "name"
2) "127.0.0.1:6381"
3) "ip"
4) "127.0.0.1"
5) "port"
6) "6381"
.........忽略............
sentinel sentinels< master name>
展示指定< master name >的Sentinel节点集合(不包含当前Sentinel节点),例如:
127.0.0.1:26379> sentinel sentinels mymaster-1
1) 1) "name"
2) "127.0.0.1:26380"
3) "ip"
4) "127.0.0.1"
5) "port"
6) "26380"
.........忽略............
2) 1) "name"
2) "127.0.0.1:26381"
3) "ip"
4) "127.0.0.1"
5) "port"
6) "26381"
.........忽略............
sentinel get-master-addr-by-name< master name>
返回指定< master name>主节点的IP地址和端口, 例如:
127.0.0.1:26379> sentinel get-master-addr-by-name mymaster-1
1) "127.0.0.1"
2) "6379"
sentinel reset< pattern>
当前sentinel节点对符合< pattern >主节点的配置进行重置,包含清除主节点的相关状态(比如故障转移),重新发现从节点和sentinel节点
例如sentinel-1节点对mymaster-1节点重置状态如下:
127.0.0.1:26379> sentinel reset mymaster-1
(integer) 1
sentinel failover < master name >
对指定< master name>主节点进行强制故障转移(没有和其他Sentinel节点“协商”),当故障转移完成后,其他Sentinel节点按照故障转移的结果更新自身配置,这个命令在Redis Sentinel的日常运维中非常有用
例如,对mymaster-2进行故障转移:
127.0.0.1:26379> sentinel failover mymaster-2
OK
执行命令前,mymaster-2是127.0.0.1:6382
127.0.0.1:26379> info sentinel
# Sentinel
sentinel_masters:2
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
master0:name=mymaster-2,status=ok,address=127.0.0.1:6382,slaves=2,sentinels=3
master1:name=mymaster-1,status=ok,address=127.0.0.1:6379,slaves=2,sentinels=3
执行命令后: mymaster-2由原来的一个从节点127.0.0.1: 6383代替。
127.0.0.1:26379> info sentinel
# Sentinel
sentinel_masters:2
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
master0:name=mymaster-2,status=ok,address=127.0.0.1:6383,slaves=2,sentinels=3
master1:name=mymaster-1,status=ok,address=127.0.0.1:6379,slaves=2,sentinels=3
sentinel ckquorum< master name>
检测当前可达的Sentinel节点总数是否达到的个数。例如quorum=3, 而当前可达的Sentinel节点个数为2个,那么将无法进行故障转移,Redis Sentinel的高可用特性也将失去。
比如:
127.0.0.1:26379> sentinel ckquorum mymaster-1
OK 3 usable Sentinels. Quorum and failover authorization can be reached
sentinel flushconfig
将Sentinel节点的配置强制刷到磁盘上,这个命令Sentinel节点自身用得比较多,对于开发和运维人员只有当外部原因(例如磁盘损坏)造成配置文件损坏或者丢失时,这个命令是很有用的。
例如:
127.0.0.1:26379> sentinel flushconfig
OK
sentinel remove< master name>
取消当前Sentinel节点对于指定< master name>主节点的监控。
例如sentinel-1当前对mymaster-1进行了监控:
127.0.0.1:26379> info sentinel
# Sentinel
sentinel_masters:2
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
master0:name=mymaster-2,status=ok,address=127.0.0.1:6382,slaves=2,sentinels=3
master1:name=mymaster-1,status=ok,address=127.0.0.1:6379,slaves=2,sentinels=3
例如下面,sentinel-1节点取消对mymaster-1节点的监控,但是要注意这个命令仅仅对当前Sentinel节点有效。
127.0.0.1:26379> sentinel remove mymaster-1
OK
再执行info sentinel命令,发现sentinel-1已经失去对mymaster-1的监控:
127.0.0.1:26379> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
master0:name=mymaster-2,status=ok,address=127.0.0.1:6383,slaves=2,sentinels=3
sentinel monitor< master name>< ip>< port>< quorum>
这个命令和配置文件中的含义是完全一样的, 只不过是通过命令的形式来完成Sentinel节点对主节点的监控。
例如命令sentinel-1节点重新监控mymaster-1节点:
127.0.0.1:26379> sentinel monitor mymaster-1 127.0.0.1 6379 2
OK
命令执行后, 发现sentinel-1节点重新对mymaster-1节点进行监控:
# Sentinel
sentinel_masters:2
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
master0:name=mymaster-2,status=ok,address=127.0.0.1:6383,slaves=2,sentinels=3
master1:name=mymaster-1,status=ok,address=127.0.0.1:6379,slaves=2,sentinels=3
sentinel set< master name>
动态修改Sentinel节点配置选项
sentinel is-master-down-by-addr
Sentinel节点之间用来交换对主节点是否下线的判断, 根据参数的不同,还可以作为Sentinel领导者选举的通信方式