使用 Percona XtraDB Cluster Check 从对等方接收数据时出现 Curl 故障

使用 Percona XtraDB Cluster Check 从对等方接收数据时出现 Curl 故障

我遇到了与这里提到的问题类似的问题: xinetd‘对方重置连接’

我已经使用 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

上一篇文章中的解决方案是设置“Content-Length:”,但我正在使用的脚本已经尝试设置内容长度:

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

我尝试按照建议将内容长度更改为零。在 if 和 else 语句中都使用 echo -en“Content-Length: 0\r\n” - 但这似乎对我的情况没有帮助。

这是我在详细模式下运行 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,一切似乎都正常工作。只是远程 curl 有问题。不幸的是,我们使用的硬件负载平衡器要求我执行 http 检查(没有 telnet 选项)。

我该如何进一步排除此故障?

谢谢!Brad

编辑-添加 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
}

答案1

问题是这个检查脚本将 HAproxy 作为单个流进行响应,而不遵守 HTTP 协议。引入 sleep 似乎对我的设置有效。

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

答案2

我在您的调试会话中注意到,您的 curl 在收到响应的第一行后立即关闭了连接。它没有收到“Content-Length”标头,因此不使用它(这就是为什么将其设置为 0 无关紧要的原因)。对我来说,它看起来像这样:

* About to connect() to vm0010 port 9200 (#0)
*   Trying 1.2.3.4... connected
* Connected to vm0010 (1.2.3.4) port 9200 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.15 libssh2/1.2.6
> Host: vm0010:9200
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: text/plain
< Connection: close
< Content-Length: 40
< 
Percona XtraDB Cluster Node is synced.
* Closing connection #0

您的 xinetd 如何针对该脚本进行配置?

相关内容