Route by domain name not working

hello,

routing by domain name ist not workin in my setup.
when i connect from a client with the command

mysql -htest-db2.example.com -uxxx -pxxx

i get every time connected to server db1 (172.17.2.111).
i think acl ist ignored and default_backend used.

my os ist ubuntu 16.04 with haproxy 1.6.3

please can anybody help me?

my config:

frontend mysql
bind 0.0.0.0:3306
mode tcp
acl usedb1 hdr(host) -i test-db1.example.com
acl usedb2 hdr(host) -i test-db2.example.com
use_backend mysql-db1 if usedb1
use_backend mysql-db2 if usedb2
default_backend mysql-db1

backend mysql-db1
mode tcp
server db1 172.17.2.111:3306 check
server db2 172.17.2.112:3306 check backup

backend mysql-db2
mode tcp
server db1 172.17.2.111:3306 check backup
server db2 172.17.2.112:3306 check

Hi,

You are correct, the acl is ignored, because it is checking for HTTP headers while your client is speaking a completely different protocol.

In order to achieve what I think you’re trying to achieve, I would use something like this instead:
listen mysql-db1
bind 0.0.0.0:3307

mode tcp
server db1 172.17.2.111:3306 check
server db2 172.17.2.112:3306 check backup

listen mysql-db2
bind 0.0.0.0:3308

mode tcp
server db1 172.17.2.111:3306 check backup
server db2 172.17.2.112:3306 check

… and then you connect to db2 with this command:
mysql -h name.example.com -P 3308 -uxxx -pxxx

So, basically you have HAProxy listening on 2 different TCP ports and you tell the client to connect to the preferred backend servers port (instead of using 2 separate DNS names like in your example), but will get connected to the other backend in case the preferred one is down.

You might also want to look into using the mysql-check option for better backend server checking:
http://cbonte.github.io/haproxy-dconv/1.6/configuration.html#4-option%20mysql-check

1 Like

hello,

thanks for the explanation!
i didn’t know that dns names only working for http headers.

instead of using different ports i preffer different ips.

i have removed temporarily the mysql-check option for troubleshooting.

tanks