不用网上流传的pl和php插件,利用redis本身的redis-cli命令来监控。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #!/bin/bash redis_bin= '/home/app/redis/src' redis_ip=(192.168.1.161 192.168.1.162 192.168.1.163 192.168.1.164) redis_master_port= '6379' redis_slave_port= '6380' for (( i = 0; i < 1; i++ )); do ALIVE_master= '' $redis_bin '/redis-cli -h ' ${redis_ip[$i]} ' -p ' $redis_master_port ' ping' ALIVE_slave= '' $redis_bin '/redis-cli -h ' ${redis_ip[$i]} ' -p ' $redis_slave_port ' ping' if [ `$ALIVE_master` == "PONG" ] && [ `$ALIVE_slave` == "PONG" ]; then echo "redis ${redis_ip[$i]} is healthy." exit 0 else echo "the redis ${redis_ip[$i]} 6379 or 6380 is down." exit 1 fi done |