Mysql – Monitoring MySQL replication through HAProxy Xinetd service

haproxyMySQLreplicationxinetd

I have have set up MySQL multi-master replication with HAProxy as a load balancer following Alex Williams' tutorial found here;
http://www.alexwilliams.ca/blog/2009/08/10/using-haproxy-for-mysql-failover-and-redundancy/

I am using a status checker found here;
http://sysbible.org/2008/12/04/having-haproxy-check-mysql-status-through-a-xinetd-script/

as well as a replication checker found here;
http://forge.mysql.com/tools/tool.php?id=6

The Mysql status checker works fine when I have the following line in my HAProxy config file:

server db02 192.168.15.119:3306 check port 9200 inter 1s weight 1 rise 1 fall 1

But when I try to test the check replication script with this line:

server db02 192.168.15.119:3306 check port 9201 inter 1s weight 1 rise 1 fall 1

and try to connect through the proxy I get a failure:

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication  packet', system error: 0

When I telnet from the HAProxy machine to that port it works fine:

# telnet 192.168.15.119 9201

Trying 192.168.15.119...
Connected to 192.168.15.119.
Escape character is '^]'.
Replication slave is running
Connection closed by foreign host.

Is there any reason that that would not work while I can still check it through telnet? Is this a limitation of HAProxy? I would assume not as it seems that this is what others have used for their setups. Is it a configuration or permissions issue? I am confused as to how one of them would work and let me connect fine, but the other will not.

Best Answer

Your replication script run by xinetd should return HTTP 200 or 503, so HAProxy can detect the health of MySQL replication.