Xinetd
使用 Percona XtraDB Cluster Check 從對等方接收數據時出現 Curl 失敗
我遇到了與此處提到的問題類似的問題: xinetd ‘connection reset by peer’
我已經使用 xinetd 設置了 percona-clustercheck(Percona 的 XtraDB Cluster 軟體包附帶),並且在嘗試遠端 curl clustercheck 時出現錯誤。(注意它在本地工作得很好。)
這是本地的樣子:
[root@db1 tmp]# for i in {1..1000}; do curl http://db1.ourdomain.local:9200; sleep 2; date; done Percona XtraDB Cluster Node is synced. Fri May 3 07:30:16 EDT 2013 Percona XtraDB Cluster Node is synced. Fri May 3 07:30:18 EDT 2013 Percona XtraDB Cluster Node is synced. Fri May 3 07:30:20 EDT 2013 Percona XtraDB Cluster Node is synced. Fri May 3 07:30:22 EDT 2013 Percona XtraDB Cluster Node is synced. Fri May 3 07:30:24 EDT 2013 Percona XtraDB Cluster Node is synced. Fri May 3 07:30:26 EDT 2013 Percona XtraDB Cluster Node is synced. Fri May 3 07:30:28 EDT 2013 Percona XtraDB Cluster Node is synced. Fri May 3 07:30:30 EDT 2013 Percona XtraDB Cluster Node is synced. Fri May 3 07:30:32 EDT 2013 Percona XtraDB Cluster Node is synced. Fri May 3 07:30:34 EDT 2013 Percona XtraDB Cluster Node is synced.
和遠端:
[root@db2 ~]# for i in {1..1000}; do curl http://db1.ourdomain.local:9200; sleep 2; date; done Percona XtraDB Cluster Node is synced. Fri May 3 07:32:23 EDT 2013 curl: (56) Failure when receiving data from the peer <----- error Fri May 3 07:32:25 EDT 2013 curl: (56) Failure when receiving data from the peer <----- error Fri May 3 07:32:27 EDT 2013 Percona XtraDB Cluster Node is synced. Fri May 3 07:32:29 EDT 2013 curl: (56) Failure when receiving data from the peer <----- error Fri May 3 07:32:31 EDT 2013 Percona XtraDB Cluster Node is synced. Fri May 3 07:32:33 EDT 2013 Percona XtraDB Cluster Node is synced. Fri May 3 07:32:35 EDT 2013 Percona XtraDB Cluster Node is synced. Fri May 3 07:32:37 EDT 2013
上一篇文章中的解決方案是設置“內容長度:”但我正在使用的腳本已經嘗試設置內容長度:
if [[ "${WSREP_STATUS}" == "4" ]] || [[ "${WSREP_STATUS}" == "2" && ${AVAILABLE_WHEN_DONOR} == 1 ]] then # Percona XtraDB Cluster node local state is 'Synced' => return HTTP 200 # Shell return-code is 0 echo -en "HTTP/1.1 200 OK\r\n" echo -en "Content-Type: text/plain\r\n" echo -en "Connection: close\r\n" echo -en "Content-Length: 40\r\n" echo -en "\r\n" echo -en "Percona XtraDB Cluster Node is synced.\r\n" exit 0 else # Percona XtraDB Cluster node local state is not 'Synced' => return HTTP 503 # Shell return-code is 1 echo -en "HTTP/1.1 503 Service Unavailable\r\n" echo -en "Content-Type: text/plain\r\n" echo -en "Connection: close\r\n" echo -en "Content-Length: 44\r\n" echo -en "\r\n" echo -en "Percona XtraDB Cluster Node is not synced.\r\n" exit 1 fi
我嘗試按照建議將內容長度更改為零。echo -en “Content-Length: 0\r\n” 在 if 和 else 語句中 - 但這對我來說似乎沒有幫助。
這是我在詳細模式下執行 curl 時看到的內容:
Fri May 3 08:34:33 EDT 2013 * About to connect() to db1.ourdomain.local port 9200 (#0) * Trying 1.2.3.4... connected * Connected to db1..local (1.2.3.4) port 9200 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2 > Host: db1.ourdomain.local:9200 > Accept: */* > < HTTP/1.1 200 OK * Closing connection #0 * Failure when receiving data from the peer curl: (56) Failure when receiving data from the peer
如果我在本地使用 curl 或遠端使用 telnet,一切似乎都可以正常工作。它只是遠端捲曲,這是一個問題。不幸的是,我們使用的硬體負載平衡器要求我執行 http 檢查(沒有 telnet 選項)。
我該如何進一步解決這個問題?
謝謝!布拉德
編輯 - 添加 xinetd 腳本的內容:
cat /etc/xinetd.d/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_type = FILE /var/log/xinetdlog log_on_failure += USERID only_from = 0.0.0.0/0 # recommended to put the IPs that need # to connect exclusively (security purposes) per_source = UNLIMITED }
問題是這個檢查腳本將 HAproxy 作為單個流來回答,而不尊重 HTTP 協議。引入睡眠似乎對我的設置有用。
then # Cluster node state is 'OK' => return HTTP 200 /bin/echo -en "HTTP/1.1 200 OK\r\n" sleep 0.1 /bin/echo -en "Content-Length: 26\r\n" sleep 0.1 /bin/echo -en "Content-Type: text/plain\r\n" sleep 0.1 /bin/echo -en "\r\n" sleep 0.1 /bin/echo -en "Cluster Node is GOOD.\r\n" sleep 0.1 /bin/echo -en "\r\n" exit 0 else # Cluster node local state is 'BAD' => return HTTP 503 /bin/echo -en "HTTP/1.1 503 Service Unavailable\r\n" sleep 0.1 /bin/echo -en "Content-Length: 0\r\n" sleep 0.1 /bin/echo -en "Content-Type: text/plain\r\n" sleep 0.1 /bin/echo -en "Connection: close\r\n" sleep 0.1 /bin/echo -en "\r\n" sleep 0.1 /bin/echo -en "Cluster Node state is BAD.\r\n" sleep 0.1 /bin/echo -en "\r\n" sleep 0.1 exit 1