我在 xinetd 中使用percona-clustercheck(Percona 的 XtraDB Cluster 软件包附带),在尝试卷曲 clustercheck 服务时出现错误。
/usr/bin/clustercheck
:
#!/bin/bash
#
# Script to make a proxy (ie HAProxy) capable of monitoring Percona XtraDB Cluster nodes properly
#
# Author: Olaf van Zandwijk <[email protected]>
# Documentation and download: https://github.com/olafz/percona-clustercheck
#
# Based on the original script from Unai Rodriguez
#
MYSQL_USERNAME="clustercheckuser"
MYSQL_PASSWORD="clustercheckpassword!"
ERR_FILE="/dev/null"
AVAILABLE_WHEN_DONOR=0
#
# Perform the query to check the wsrep_local_state
#
WSREP_STATUS=`mysql --user=${MYSQL_USERNAME} --password=${MYSQL_PASSWORD} -e "SHOW STATUS LIKE 'wsrep_local_state';" 2>${ERR_FILE} | awk '{if (NR!=1){print $2}}' 2>${ERR_FILE}`
if [[ "${WSREP_STATUS}" == "4" ]] || [[ "${WSREP_STATUS}" == "2" && ${AVAILABLE_WHEN_DONOR} == 1 ]]
then
# Percona XtraDB Cluster node local state is 'Synced' => return HTTP 200
/bin/echo -en "HTTP/1.1 200 OK\r\n"
/bin/echo -en "Content-Type: text/plain\r\n"
/bin/echo -en "\r\n"
/bin/echo -en "Percona XtraDB Cluster Node is synced.\r\n"
/bin/echo -en "\r\n"
exit 0
else
# Percona XtraDB Cluster node local state is not 'Synced' => return HTTP 503
/bin/echo -en "HTTP/1.1 503 Service Unavailable\r\n"
/bin/echo -en "Content-Type: text/plain\r\n"
/bin/echo -en "\r\n"
/bin/echo -en "Percona XtraDB Cluster Node is not synced.\r\n"
/bin/echo -en "\r\n"
exit 1
fi
/etc/xinetd.mysqlchk
:
# default: on
# description: mysqlchk
service mysqlchk
{
# this is a config for xinetd, place it in /etc/xinetd.d/
disable = no
flags = REUSE
socket_type = stream
port = 9200
wait = no
user = nobody
server = /usr/bin/clustercheck
log_on_failure += USERID
only_from = 10.0.0.0/8 127.0.0.1
# recommended to put the IPs that need
# to connect exclusively (security purposes)
per_source = UNLIMITED
}
当尝试 curl 服务时,我得到了一个有效的响应(HTTP 200,文本),但最后有一个“连接被对等重置”的通知:
HTTP/1.1 200 OK
Content-Type: text/plain
Percona XtraDB Cluster Node is synced.
curl: (56) Recv failure: Connection reset by peer
不幸的是,Amazon ELB 似乎将此视为失败的检查,而不是成功的检查。
如何让 clustercheck 以 curl 看不到连接失败的方式正常退出?
添加
Content-Length: 0
会使客户端忽略内容,即使在这种情况下也有内容。所以这可能会破坏其他检查软件。在您的情况下,同步节点的内容长度为 42 字节(因此添加Content-Length: 42
),未同步节点的内容长度为 46 字节。我将推送更新的脚本,以便它也将在新版本的 Percona XtraDB Cluster 包中得到修复。
我
Content-Length: 0
在 clustercheck 响应中添加了一个标头,这似乎可以解决 Amazon 的健康检查问题。如果有人有更好的做法,请告诉我我使用解决了类似的问题
反而
我还注意到您在本地主机上使用脚本。您还可以在命令行上执行 clustercheck 并检查返回值。
如果是同步节点:
如果是未同步的节点: