Xinetd

xinetd ‘由對等方重置連接’

  • August 18, 2014

我正在使用帶有 xinetd 的percona-clustercheck(Percona 的 XtraDB Cluster 軟體包附帶),並且在嘗試 curl 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 <olaf.vanzandwijk@nedap.com>
# 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 個字節(因此 add Content-Length: 42),在未同步節點的情況下為 46 個字節。

# curl localhost:9200
Percona XtraDB Cluster Node is synced.

我將推送更新的腳本,以便它也將在新版本的 Percona XtraDB Cluster 包中得到修復。

Content-Length: 0在 clustercheck 響應中添加了一個標頭,這似乎對 Amazon 的健康檢查起到了作用。如果有人有更好的做法,請告訴我

引用自:https://serverfault.com/questions/490163