Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to use HAProxy as a load balancer for 2 mysql nodes. I have HAProxy listening on 3307 and it routes requests to the DBs on 3306. When the client is trying to connect to the Proxy (mysql -u ... -h .. -P3307 -p...) it gets the following error:

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

When the client is trying to connect directly to the DB it works fine. I have no idea why its failing when traffic goes via the Proxy.

Here's what I've already checked:

  1. /etc/hosts.allow includes "mysqld: ALL : allow "

  2. MySQL config file (my.cnf) doesn't have a bind address line (open to all).

I am using HAProxy 1.5dev, Mysql 5.1.x and the whole enchilada is running in ec2 on Amazon linux.

Here's the HAProxy config file:

    global
     log 127.0.0.1   local0
     log 127.0.0.1   local1 notice
     #log loghost    local0 info
     user haproxy
     group haproxy
     maxconn 4096
     daemon
     #debug
     #quiet

    defaults
     log     global
     mode    tcp
     option  tcplog
     option  dontlognull
     retries 3
     option redispatch
     maxconn 4096
     contimeout      5000
     clitimeout      50000
     srvtimeout      50000

    frontend mysql_cluster
     bind 10.0.0.150:3307
     default_backend mysql_cluster

    backend mysql_cluster
     mode tcp
     balance roundrobin
     option tcpka
     option httpchk
     server lb1 10.0.0.140:3306 check port 9200 inter 5s rise 2 fall 2
     server lb2 10.0.0.214:3306 check port 9200 inter 5s rise 2 fall 2 

    listen stats 10.0.0.150:8081
     mode http
     option httpclose
     balance roundrobin
     stats uri /
     stats realm Haproxy\ Statistics
     stats auth ***:***

Has anyone tackled this problem before? Any ideas how to solve this?

Any help much appreciated

share|improve this question

migrated from stackoverflow.com Sep 29 '11 at 11:28

This question came from our site for professional and enthusiast programmers.

    
Can you add your haproxy config file? –  James Little Sep 28 '11 at 20:02
    
Just added it. Thanks for your help. –  A.RG Sep 28 '11 at 20:47
    
Are you running replication or anything like that on MySQL? How are they in sync to load balance between them? –  Paul Kroon Sep 29 '11 at 18:20
    
Paul - DB instances are synced using drbd –  A.RG Sep 30 '11 at 0:01
    
probably a red herring, but you don't need the option httpchk on a tcp backend, also in my own config I've commented out the option tcpka line. It was long enough ago that I can't remember why :) –  Richard Benson Sep 30 '11 at 9:51

1 Answer 1

OK, I solved it. I had a problem with my xinetd script.

It failed to bind on 9200 - fixed it in /etc/services file.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.