Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HaProxy (cannot bind socket, select test failed)

Hello everyone, Im working about an high availbility project, I had to put in production an haproxy for some applications. Everything was ok after some basics tests but I had some errors and cant fix it. Does someone have some ideas ?

here is the test

# /usr/sbin/haproxy -d -f /etc/haproxy/haproxy.cfg

Available polling systems : 

 sepoll : pref=400,  test result OK 
 epoll : pref=300,  test result OK 
 poll : pref=200,  test result OK 
 select : pref=150,  test result FAILED 

Total: 4 (3 usable), will use sepoll. 
Using sepoll() as the polling mechanism. 
[ALERT] 174/160258 (22038) : Starting proxy mysql: cannot bind socket 
[ALERT] 174/160258 (22038) : Starting proxy http: cannot bind socket 

There is my file haproxy.cfg

global 
log 127.0.0.1 local0 notice
user haproxy
group haproxy
maxconn 32000
ulimit-n 65536

defaults
log global
option dontlognull
retries 2
timeout connect 3000
timeout server 5000
timeout client 5000
option redispatch

listen  mysql
bind *:3306
mode tcp
option tcplog
balance roundrobin
option  mysql-check user haproxy_check
server mysql1 10.83.83.167:3306 check
server mysql2 10.83.83.168:3306 check
server mysql3 10.83.83.169:3306 check 

listen  http
mode http
bind *:80
stats enable
stats uri /stats
stats auth admin:HaProxy2014
acl app1_cluster_acl hdr_beg(host) -i app1
acl app2_cluster_acl hdr_beg(host) -i app2
acl mysql_cluster_acl hdr_beg(host) -i mysql
use_backend app1_cluster if app1_cluster_acl
use_backend app2_cluster if app2_cluster_acl
use_backend mysql_cluster if mysql_cluster_acl 

backend app1_cluster
mode http
cookie SERVERID insert indirect nocache
option  forwardfor header X-Real-IP
option  http-server-close
option  httplog
balance roundrobin
server serv1 10.83.83.203:80 check cookie serv1
server serv2 10.83.83.204:80 check cookie serv2 

backend app2_cluster
mode http
cookie SERVERID insert indirect nocache
option  forwardfor header X-Real-IP
option  http-server-close
option  httplog
balance roundrobin
server serv1 10.83.83.187:80 check cookie serv1
server serv2 10.83.83.188:80 check cookie serv2 

backend mysql_cluster
mode http
cookie SERVERID insert indirect nocache
option  forwardfor header X-Real-IP
option  http-server-close
option  httplog
balance roundrobin
server mysql1 10.83.83.167:80 check cookie serv1
server mysql2 10.83.83.168:80 check cookie serv2
server mysql3 10.83.83.169:80 check cookie serv2
like image 339
user3773525 Avatar asked Jun 25 '14 04:06

user3773525


People also ask

Can not bind to socket?

Introduction. An HAProxy cannot bind socket error message is generated when there is another process listening on the same interface and TCP port combination that HAProxy is configured to use, or when HAProxy attempts to use an IP address that is not assigned to a network interface.

How do I know if HAProxy is working?

Use this systemctl command to examine HAProxy's status on any Linux distribution: sudo systemctl status haproxy. service -l --no-pager.

Could not bind socket address and port are already in use?

To do so, open the program options by going to Edit -> Options -> Browsers and change the value of the WebSockets port. The same value must then also be set in the browser add-on (within the browser itself).


1 Answers

I get the same error if there is already a mysql or http service running on my load balancer in addition to ruuning on the back ends.

For example if nginx/apache is already running on my load balancer.

$ netstat -anp | grep ":80"
tcp        0      0 127.0.0.1:80            0.0.0.0:*               LISTEN      3646/nginx    

And i try to start my load balancer with bind *:80 i get a similar error.

$ haproxy -d -f /etc/haproxy/haproxy.cfg
Available polling systems :
      epoll : pref=300,  test result OK
      poll : pref=200,  test result OK
     select : pref=150,  test result FAILED
Total: 3 (2 usable), will use epoll.
Using epoll() as the polling mechanism.
[ALERT] 195/001456 (1903) : Starting frontend www: cannot bind socket [0.0.0.0:80]

If you need to have a mysql or http instance listening on 127.0.0.1 then you can specify the ip of another interface in the bind call.

bind: 10.0.0.20:80

With the latest version of haproxy you can now even use variables.

bind ${LB1}:80

And export these from the haproxy startup script or /etc/default/haproxy

export LB1="10.0.0.20"

Otherwise perhaps there is an issue with your haproxy startup scripts.

like image 173
ftmon Avatar answered Nov 15 '22 10:11

ftmon