diff --git a/HowtoHaproxy.md b/HowtoHaproxy.md index 745705a6..edcbcee8 100644 --- a/HowtoHaproxy.md +++ b/HowtoHaproxy.md @@ -310,48 +310,26 @@ mysqlchk 8306/tcp # mysqlchk On crée le script à exécuter dans `/root/mysqlchk` (droits: root:root 0750) : -~~~{.bash} -#!/bin/bash - -# Créer un utilisateur limité pour ces checks : -# mysql> CREATE USER 'mysqlchk'@'localhost' IDENTIFIED BY 'PASSWORD'; -# mysql> GRANT SHOW DATABASES ON *.* TO 'mysqlchk'@'localhost'; - -MYSQL_HOST="127.0.0.1" -MYSQL_PORT="3306" -MYSQL_USERNAME="mysqlchk" -MYSQL_PASSWORD="PASSWORD" -TMP_FILE="/tmp/mysqlchk.out" -ERR_FILE="/tmp/mysqlchk.err" - -/usr/bin/mysql --host=$MYSQL_HOST --port=$MYSQL_PORT --user=$MYSQL_USERNAME \ - --password=$MYSQL_PASSWORD -e"show databases;" > $TMP_FILE 2> $ERR_FILE - -uptime=`cat /proc/uptime | cut -f 1 -d .` - -if [ "$(/bin/cat $TMP_FILE)" != "" ] && ( /root/nrpe-check-mysql-slave.sh >/dev/null || [ $uptime -gt 3600 ] ); then - # mysql is fine, return http 200 - /bin/echo -e "HTTP/1.1 200 OK\r\n" - /bin/echo -e "Content-Type: Content-Type: text/plain\r\n" - /bin/echo -e "\r\n" - /bin/echo -e "MySQL is running.\r\n" - /bin/echo -e "\r\n" -else - # mysql is fine, return http 503 - /bin/echo -e "HTTP/1.1 503 Service Unavailable\r\n" - /bin/echo -e "Content-Type: Content-Type: text/plain\r\n" - /bin/echo -e "\r\n" - /bin/echo -e "MySQL is *down*.\r\n" - /bin/echo -e "\r\n" -fi -~~~ - -Puis le script de check mysql lui-même, par exemple `/root/nrpe-check-mysql-slave.sh` (droits: root:root 0750) : - ~~~{.bash} #!/bin/sh -exec /usr/lib/nagios/plugins/check_mysql -f /etc/mysql/debian.cnf --check-slave -w 5 -c 60 +# Mysql is down, return a 503 +return="503 Service Unavailable" + +# Mysql is fine, return a 200 +/usr/lib/nagios/plugins/check_mysql -f /etc/mysql/debian.cnf >/dev/null && return="200 OK" + +# Mysql is up but replication is not ok, return a 404 +# You may want to comment this line in master/master mode +# It disable server (NOLB status) when replication is down or lagging +/usr/lib/nagios/plugins/check_mysql -f /etc/mysql/debian.cnf --check-slave -c 60 >/dev/null || return="404 OK" + +cat <