Benutzer-Werkzeuge

Webseiten-Werkzeuge


wsrep_notify_cmd

wsrep_notify_cmd

Mit Hilfe dieser Funktionalität, kann man auf Pacemaker+Corosync verzichten.

/var/lib/mysql/bin/wsrep_notify_cmd.sh
#!/bin/bash -e
#!/bin/bash -eu
 
#==============================================================================#
#
# http://www.fromdual.com/unbreakable-mysql-cluster-with-galera-and-lvs
# http://galeracluster.com/documentation-webpages/mysqlwsrepoptions.html#wsrep-notify-cmd
#
# /etc/mysql/galera_mariadb.cnf
#
# [mysqld]
# wsrep_notify_cmd = /var/lib/mysql/bin/wsrep_notify_cmd.sh
#
#==============================================================================#
#
# Warning!
#
# The node will block and wait until the script completes and returns before it
# can proceed. If the script performs any potentially blocking or long-running
# operations, such as network communication, you may wish initiate such
# operations in the background and have the script return immediately.
#
#==============================================================================#
#
# SET GLOBAL wsrep_notify_cmd='/var/lib/mysql/bin/wsrep_notify_cmd.sh';
# SHOW VARIABLES LIKE 'wsrep_notify_cmd';
#
#==============================================================================#
 
#MYIP=''
VERSION="v2017110800"
 
LOG="/var/log/mysql/wsrep_notify_cmd.log"
#ETC="/etc/mysql/conf.d/wsrep.cnf"
#ETC="/home/mysql/data/mysql-5.5-wsrep-23.7-a/my.cnf"
ETC="/etc/mysql/galera_mariadb.cnf"
 
DATUM_ZEIT="$(date +'%Y-%m-%d %H:%M:%S')"
echo "${DATUM_ZEIT}" >>${LOG}
echo "${0} ${@}" >>${LOG}
 
#------------------------------------------------------------------------------#
 
#regex='^.*=\s*([0-9]+.[0-9]+.[0-9]+.[0-9]+).*'
#
#str=$(grep -E "^wsrep_node_incoming_address" ${ETC} 2>>${LOG})
#
#if [[ ${str} =~ ${regex} ]] ; then
#       MYIP=${BASH_REMATCH[1]}
#else
#       echo "Cannot find IP address in ${str}" >>${LOG}
#       exit 1
#fi
 
#------------------------------------------------------------------------------#
 
while [ "${#}" -gt "0" ] ; do
        case "${1}" in
                --status)
                        # Undefined, Joiner, Donor, Joined, Synced, Error
                        STATUS="$2"
                        shift
                        ;;
                --uuid)
                        # The cluster state UUID.
                        CLUSTER_UUID="$2"
                        shift
                        ;;
                --primary)
                        # yes, no
                        PRIMARY="$2"
                        shift
                        ;;
                --index)
                        # The index of this node in the node list.
                        INDEX="$2"
                        shift
                        ;;
                --members)
                        # eine durch Komma getrennte Liste mit UUIDs
                        MEMBERS="$2"
                        shift
                        ;;
        esac
        shift
done
 
#------------------------------------------------------------------------------#
 
# echo $* >> ${LOG}
echo "
STATUS=${STATUS}
CLUSTER_UUID=${CLUSTER_UUID}
PRIMARY=${PRIMARY}
INDEX=${INDEX}
MEMBERS=${MEMBERS}
" >>${LOG}
 
# Undefined means node is shutting down
# Synced means node is ready again
#if [ "${STATUS}" = "Synced" -a "${PRIMARY}" = "[Yy][Ee][Ss]" ] ; then
if [ "${STATUS}" = "Synced" ] ; then
        #DB_STAT="System ist bereit: ${STATUS},${PRIMARY}"
        DB_STAT="System ist bereit: ${STATUS}"
else
        #DB_STAT="System ist nicht bereit: ${STATUS},${PRIMARY}"
        DB_STAT="System ist nicht bereit: ${STATUS}"
fi
 
echo "${DB_STAT}" >>${LOG}
echo "ret=$?" >>${LOG}
echo "#------------------------------------------------------------------------------#" >>${LOG}
 
exit 0

Die Variable wsrep_notify_cmd wird beim DB-Start nicht gesetzt, dass muss man manuell machen:

> echo "SET GLOBAL wsrep_notify_cmd='/var/lib/mysql/bin/wsrep_notify_cmd.sh'" | mysql

Um das setzen der Variable wsrep_notify_cmd (z.B. nach dem Restart) zu automatisieren, kann man folgendes Skript verwenden:

/root/bin/wsrep_notify_cmd_setzen.sh
#!/bin/bash
 
#==============================================================================#
#
# mit diesem Skript wird die Variable 'wsrep_notify_cmd' in der Galera-DB
# gesetzt und anschließend der aktuelle Status gesendet
#
#==============================================================================#
 
VERSION="v2017110800"
 
WSREP_NOTIFY_CMD="/var/lib/mysql/bin/wsrep_notify_cmd.sh"
 
echo "
SHOW STATUS LIKE 'wsrep_cluster_status';
SHOW STATUS LIKE 'wsrep_local_state_comment';
SHOW VARIABLES LIKE 'wsrep_notify_cmd';
" | mysql -t
 
echo "wsrep_notify_cmd wird gesetzt..."
echo "SET GLOBAL wsrep_notify_cmd='${WSREP_NOTIFY_CMD}'" | mysql
 
echo "
SHOW STATUS LIKE 'wsrep_cluster_status';
SHOW STATUS LIKE 'wsrep_local_state_comment';
SHOW VARIABLES LIKE 'wsrep_notify_cmd';
" | mysql -t
 
PRIMARY="$(echo "SHOW STATUS LIKE 'wsrep_cluster_status';" | mysql -N | grep -Ev '^[ \t]*$' | awk '{print $2}')"
STATUS="$(echo "SHOW STATUS LIKE 'wsrep_local_state_comment';" | mysql -N | grep -Ev '^[ \t]*$' | awk '{print $2}')"
echo "${WSREP_NOTIFY_CMD} --primary ${PRIMARY} --status ${STATUS}"
su - mysql -s /bin/bash -c "${WSREP_NOTIFY_CMD} --primary ${PRIMARY} --status ${STATUS}"

Dieses Skript kann man in die /etc/rc.local eintragen, es muss nur sichergestellt werden, dass es erst gestartet wird, wenn die DB vollständig hochgefahren ist.

Das kann man mit den folgenden Skripten bzw. Eintragungen erreichen.

/etc/rc.local
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
 
### wsrep_notify_cmd in Galera setzen
/root/bin/wsrep_notify_cmd_beim_boot_setzen.sh | logger -t wsrep_notify_cmd

Weil das synchronisieren per SST bei großen Galera-Datenbanken sehr lange dauern kann, sind hier 1800 Sekunden (1/2 Stunde) angegeben worden.

/root/bin/wsrep_notify_cmd_beim_boot_setzen.sh
#!/usr/bin/env bash
 
MYSQL_LOGIN="--defaults-file=/root/.my.cnf"
ZAEHLER="1800"
 
while [ "${ZAEHLER}" -gt "0" ]
do
        ZAEHLER="$(echo "${ZAEHLER}"|awk '{print $1-1}')"
        if [ "$(mysqlshow ${MYSQL_LOGIN})" ] ; then
                ZAEHLER="0"
                /root/bin/wsrep_notify_cmd_setzen.sh
        fi
        sleep 1
done

damit die Platte nicht voll läuft:

/etc/logrotate.d/wsrep_notify_cmd
# - damit die Platte nicht voll läuft
/var/log/mysql/wsrep_notify_cmd.log {
        daily
        rotate 7
        missingok
        create 640 mysql adm
        compress
        sharedscripts
}
/home/http/wiki/data/pages/wsrep_notify_cmd.txt · Zuletzt geändert: von manfred