本文共 1132 字,大约阅读时间需要 3 分钟。
此脚本是keepalive服务中用的监控脚本。
主要的高级部分体现在事先定义好的变量中。[root@search63 ~]# cat /home/op/scripts/ha_keepalived_monitor.sh
#!/bin/shSCRIPT_PATH=$(cd "$(dirname "$0")"; pwd)
SCRIPT_NAME=$(basename "$0")PARA_NUM="$#"PROC_PID="$$"LOG_DIR='/var/log/monitor'vrrp_ip="172.16.136.117"
prog_flag="$MYSQL_HOME"log_file="${LOG_DIR}/ha_keepalived.log"record_time=$(date '+%Y-%m-%d %H:%M:%S')chown_user='root'chown_group='root'parse_arguments() {
for arg docase "$arg" in-H|--help)usage;;-D|--debug)set -x;;esacshiftdone}cd "${SCRIPT_PATH}"
parse_arguments $@test ! -d "${LOG_DIR}" && mkdir -p "${LOG_DIR}" && chown "${chown_user}"."${chown_group}" "${LOG_DIR}"prog_exists=$(ps -ef | grep "${prog_flag}" | grep -v grep | wc -l)if [ "${prog_exists}" -eq 0 ];thenvrrp_ip_exists=$(/sbin/ip a | grep "${vrrp_ip}" | wc -l)if [ "${vrrp_ip_exists}" -ge 1 ];then/etc/init.d/keepalived stopecho "[${record_time}] ERROR Detect mysql service does not exist, stop keepalived server!" >> "${log_file}"chown "${chown_user}"."${chown_group}" "${log_file}"fifiexit 0
转载于:https://blog.51cto.com/jingfeng/2285412