5

I m restarting HAproxy by following command

haproxy -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid)

but i get following message

[ALERT] 183/225022 (9278) : Starting proxy appli1-rewrite: cannot bind socket
[ALERT] 183/225022 (9278) : Starting proxy appli2-insert: cannot bind socket
[ALERT] 183/225022 (9278) : Starting proxy appli3-relais: cannot bind socket
[ALERT] 183/225022 (9278) : Starting proxy appli4-backup: cannot bind socket
[ALERT] 183/225022 (9278) : Starting proxy ssl-relay: cannot bind socket
[ALERT] 183/225022 (9278) : Starting proxy appli5-backup: cannot bind socket

my haproxy.cfg file looks likefollowing

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

defaults
    log    global
    mode    http
    option    httplog
    option    dontlognull
    retries    3
    option redispatch
    maxconn    2000
    contimeout    5000
    clitimeout    50000
    srvtimeout    50000

listen    appli1-rewrite 0.0.0.0:10001
    cookie    SERVERID rewrite
    balance    roundrobin
    server    app1_1 192.168.34.23:8080 cookie app1inst1 check inter 2000 rise 2 fall 5
    server    app1_2 192.168.34.32:8080 cookie app1inst2 check inter 2000 rise 2 fall 5
    server    app1_3 192.168.34.27:8080 cookie app1inst3 check inter 2000 rise 2 fall 5
    server    app1_4 192.168.34.42:8080 cookie app1inst4 check inter 2000 rise 2 fall 5

listen    appli2-insert 0.0.0.0:10002
    option    httpchk
    balance    roundrobin
    cookie    SERVERID insert indirect nocache
    server    inst1 192.168.114.56:80 cookie server01 check inter 2000 fall 3
    server    inst2 192.168.114.56:81 cookie server02 check inter 2000 fall 3
    capture cookie vgnvisitor= len 32

    option    httpclose        # disable keep-alive
    rspidel ^Set-cookie:\ IP=    # do not let this cookie tell our internal IP address

listen    appli3-relais 0.0.0.0:10003
    dispatch 192.168.135.17:80

listen    appli4-backup 0.0.0.0:10004
    option    httpchk /index.html
    option    persist
    balance    roundrobin
    server    inst1 192.168.114.56:80 check inter 2000 fall 3
    server    inst2 192.168.114.56:81 check inter 2000 fall 3 backup

listen    ssl-relay 0.0.0.0:8443
    option    ssl-hello-chk
    balance    source
    server    inst1 192.168.110.56:443 check inter 2000 fall 3
    server    inst2 192.168.110.57:443 check inter 2000 fall 3
    server    back1 192.168.120.58:443 backup

listen    appli5-backup 0.0.0.0:10005
    option    httpchk *
    balance    roundrobin
    cookie    SERVERID insert indirect nocache
    server    inst1 192.168.114.56:80 cookie server01 check inter 2000 fall 3
    server    inst2 192.168.114.56:81 cookie server02 check inter 2000 fall 3
    server    inst3 192.168.114.57:80 backup check inter 2000 fall 3
    capture cookie ASPSESSION len 32
    srvtimeout    20000

    option    httpclose        # disable keep-alive
    option  checkcache        # block response if set-cookie & cacheable

    rspidel ^Set-cookie:\ IP=    # do not let this cookie tell our internal IP address

    #errorloc    502    http://192.168.114.58/error502.html
    #errorfile    503    /etc/haproxy/errors/503.http
    errorfile    400    /etc/haproxy/errors/400.http
    errorfile    403    /etc/haproxy/errors/403.http
    errorfile    408    /etc/haproxy/errors/408.http
    errorfile    500    /etc/haproxy/errors/500.http
    errorfile    502    /etc/haproxy/errors/502.http
    errorfile    503    /etc/haproxy/errors/503.http
    errorfile    504    /etc/haproxy/errors/504.http

what is wrong with my aproach

5 Answers 5

4

Two options:

  1. You aren't running as root; probably needs a sudo in front of your command to start it on the command line if you aren't running as root (check with whoami).
  2. Another process, likely another instance of HAProxy, is already bound to those ports. Check with netstat -apn.
1
  • I am running this command from python via ssh root login and I get this error but not if i do it directly as root or ssh agent from tty
    – shreyas
    Jul 3, 2011 at 17:52
11

On RedHat Linux with enabled SELinux (which should be enabled), just enable the haproxy_connect_any boolean value, which allows haproxy to connect the socket to any port:

setsebool -P haproxy_connect_any on
3
  • 1
    I guess a better approach would be Creating Custom SELinux Policy Modules with audit2allow Sep 28, 2020 at 12:28
  • Yeah, that's definitely the better way. But way better than just disable selinux…
    – Adi Barone
    Sep 29, 2020 at 13:14
  • If you're deploying into prod (or setting up a staging env or something like prod), definitely do the audit2allow approach instead. If you're screwing around in dev, this sebool way is pretty nice. Oct 17, 2020 at 22:23
3

Maybe is because of selinux I type

setenforce 0

and solve the problem. The command is to make selinux to premissive mode. A not proper set selinux may block many service or connection.

5
  • 1
    Can you expand on what the command does and why it solves the problem? Mar 3, 2017 at 16:20
  • I think the default selinux setting block my service, because once I set the selinux to premissive mode, every thing goes well.
    – edwardwu
    Mar 17, 2017 at 8:02
  • Is this need to be done at each boot ?
    – Tony
    Mar 7, 2018 at 14:21
  • 3
    While this can be used as a quick method of determining if SELinux is the problem, disabling SELinux is a very insecure way to solve this kind of problem. Much better to find out exactly why SELinux is blocking the behavior and modifying the SELinux configuration appropriately.
    – Nick
    Aug 1, 2019 at 17:31
  • stopdisablingselinux.com Oct 17, 2020 at 22:24
0

Check to see if the process id in /var/run/haproxy.pid is the same as the currently running instance of HAProxy.

0

Looks like issue is with your IO address or port. Please verify that your public IP is properly configured. You can check it by running the commands below:

ifconfig 
ip addr

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .