redis 哨兵模式,主节点检查脚本

此脚本可以设置为keepalived的检查脚本,以进行VIP的漂移

脚本内容

redis-master-check.sh

#!/bin/bash
#Date:20220720
#By: PlatoWG
# $1 is redis server's IP ADDRESS;$2 is redis server's PORT;$3 is redis server's password

if [ -z "$(/usr/bin/redis-cli -h $1 -p $2 -a $3 INFO replication 2>/dev/null|grep "role:master")" ];then
        echo -e "\033[31m$1:$2 is not master Redis\033[0m"
        exit 1
else
        echo -e "\033[32m$1:$2 is master Redis\033[0m"
        exit 0
fi


脚本测试

[root@k8s-master1 tmp]# ./redis-master-check.sh 192.168.137.51 7003 XXXXXXXX
192.168.137.51:7003 is not master Redis
[root@k8s-master1 tmp]# ./redis-master-check.sh 192.168.137.51 7002 XXXXXXXX
192.168.137.51:7002 is master Redis
[root@k8s-master1 tmp]# ./redis-master-check.sh 192.168.137.51 7001 XXXXXXXX
192.168.137.51:7001 is not master Redis

你可能感兴趣的:(数据库,Linux,redis,数据库,缓存)