我试图在一系列3个EC2实例上与Percona XtraDB集群一起设置HAproxy。 我在网上find了一些关于这个问题的教程,但是我有点卡住了。
Percona服务器和HAproxy服务器都运行Ubuntu 12.04。 HAProxy版本是1.4.18,
当我启动HAProxy时,出现以下错误:服务器pxc-back / db01已closures,原因:套接字错误,检查持续时间:2ms。
我不确定这个问题会是什么。 我已经validation了以下内容:
任何帮助,这是非常感谢。
这是我目前的configuration
负载平衡器
/etc/haproxy/haproxy.cfg
global log 127.0.0.1 local0 log 127.0.0.1 local1 notice maxconn 4096 user haproxy group haproxy debug #quiet daemon defaults log global mode http option tcplog option dontlognull retries 3 option redispatch maxconn 2000 contimeout 5000 clitimeout 50000 srvtimeout 50000 frontend pxc-front bind 0.0.0.0:3307 mode tcp default_backend pxc-back frontend stats-front bind 0.0.0.0:22002 mode http default_backend stats-back backend pxc-back mode tcp balance leastconn option httpchk server db01 10.86.154.105:3306 check port 9200 inter 12000 rise 3 fall 3 backend stats-back mode http balance roundrobin stats uri /haproxy/stats
MySql服务器
/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_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 }
MySql服务器
/ etc / services中
添加了行mysqlchk 9200 / tcp#mysqlchk
MySql服务器
在/ usr / bin中/ clustercheck
# GNU nano 2.2.6 File: /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="testuser" MYSQL_PASSWORD="" 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" 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" fi
请确保以下步骤并在此处发布结果。
testuser netstat -nltvalidation监听TCP端口(9200) telnet 127.0.0.1 9200 /usr/bin/clustercheck 一旦你完成了这一切,请在这里发布结果。
我有问题在哪里telnet 127.0.0.1 9200给503服务器不可用的响应,但是当我作为root执行/usr/bin/clustercheck表明,一切都很好。
使用这个命令,我能够以nobody用户的身份执行clustercheck,并将真正的MySQL错误信息传递给/tmp/cluster.log :
sudo -H -u nobody bash -c "/usr/bin/clustercheck clustercheckuser clustercheckpassword! 0 /tmp/cluster.log"
和/tmp/cluster.log包含:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql/mysql.sock' (13)
问题是mysql.sock所在的目录没有执行(+ x)标志,因此用户无法读取,修复程序是:
chmod o+x /var/run/mysql