This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
galaxy-deployment-ansible-d…/MariaDB/10.5.3/mariadb/role/templates/keepalived/check_mariadb.sh.j2

16 lines
533 B
Plaintext
Raw Normal View History

#!/bin/bash
PORT_CHECK=$(netstat -anlp | grep 3306 | grep LISTEN | grep mysqld | grep -v grep | wc -l)
if [[ $PORT_CHECK -eq 0 ]];then
echo "`date "+%Y-%m-%d %H:%M:%S"` - Mariadb 端口未监听,服务异常" >> /etc/keepalived/keepalived_check.log
exit 1
fi
SQL_CHECK=`mysql -h{{inventory_hostname}} -utsg_query -p{{mariadb_query_pin}} -e "SELECT 'ok' AS OK;"`
if [[ $? -ne '0' ]];then
echo "`date "+%Y-%m-%d %H:%M:%S"` - Mariadb SQL执行失败服务状态异常" >> /etc/keepalived/keepalived_check.log
exit 1
fi