代码之家  ›  专栏  ›  技术社区  ›  Himanshu Poddar

当我在为网站提供服务的同一台机器上设置负载平衡器时,haproxy.service启动失败

  •  0
  • Himanshu Poddar  · 技术社区  · 5 年前

    我有两台机器

    192.46.209.80 # server1
    192.46.209.82 # server2
    

    我在为我的网站提供服务的同一台机器server1上设置了HAProxy负载均衡器。 因此,现在server1将运行HAProxy和Web服务器。 我根据这个设置了Apache2和HAProxy tutorial

    在…上 192.46.209.80 服务器1这是我的 主机 文件

    127.0.0.1       localhost
    
    # The following lines are desirable for IPv6 capable hosts
    ::1             localhost ip6-localhost ip6-loopback
    ff02::1         ip6-allnodes
    ff02::2         ip6-allrouters
    HAproxy 192.46.209.80
    192.46.209.80 HAProxy
    192.46.209.80 server1
    192.46.209.82 server2
    

    在…上 192.46.209.82 server2这是我的 主机 文件

    127.0.0.1       localhost
    
    The following lines are desirable for IPv6 capable hosts
    ::1             localhost ip6-localhost ip6-loopback
    ff02::1         ip6-allnodes
    ff02::2         ip6-allrouters
    HAproxy 192.46.209.80
    

    然后在服务器1上安装HAProxy之后

    sudo sudo apt install haproxy
    

    我编辑并附加在 sudo nano/etc/haproxy/haproxy.cfg

    #HAProxy for web servers
    frontend web-frontend
      bind 192.46.209.80:80
      mode http
      default_backend web-backend
    
    backend web-backend
      balance roundrobin
      server server1 192.46.209.80 check port 80
      server server2 192.46.209.82 check port 80
    

    运行后

    sudo systemctl restart haproxy.service
    

    我出错了

    Job for haproxy.service failed because the control process exited with error code.
    See "systemctl status haproxy.service" and "journalctl -xe" for details.
    

    这是的结果 journalctl -xe

    -- Subject: Unit process exited
    -- Defined-By: systemd
    -- Support: http://www.ubuntu.com/support
    --
    -- An ExecStart= process belonging to unit haproxy.service has exited.
    --
    -- The process' exit code is 'exited' and its exit status is 1.
    Oct 19 14:13:18 localhost systemd[1]: haproxy.service: Failed with result 'exit-code'.
    -- Subject: Unit failed
    -- Defined-By: systemd
    -- Support: http://www.ubuntu.com/support
    --
    -- The unit haproxy.service has entered the 'failed' state with result 'exit-code'.
    Oct 19 14:13:18 localhost systemd[1]: Failed to start HAProxy Load Balancer.
    -- Subject: A start job for unit haproxy.service has failed
    -- Defined-By: systemd
    -- Support: http://www.ubuntu.com/support
    --
    -- A start job for unit haproxy.service has finished with a failure.
    --
    -- The job identifier is 6245 and the job result is failed.
    Oct 19 14:13:18 localhost systemd[1]: haproxy.service: Scheduled restart job, restart counter is at 5.
    -- Subject: Automatic restarting of a unit has been scheduled
    -- Defined-By: systemd
    -- Support: http://www.ubuntu.com/support
    --
    -- Automatic restarting of the unit haproxy.service has been scheduled, as the result for
    -- the configured Restart= setting for the unit.
    Oct 19 14:13:18 localhost systemd[1]: Stopped HAProxy Load Balancer.
    -- Subject: A stop job for unit haproxy.service has finished
    -- Defined-By: systemd
    -- Support: http://www.ubuntu.com/support
    --
    -- A stop job for unit haproxy.service has finished.
    --
    -- The job identifier is 6314 and the job result is done.
    Oct 19 14:13:18 localhost systemd[1]: haproxy.service: Start request repeated too quickly.
    Oct 19 14:13:18 localhost systemd[1]: haproxy.service: Failed with result 'exit-code'.
    -- Subject: Unit failed
    -- Defined-By: systemd
    -- Support: http://www.ubuntu.com/support
    --
    -- The unit haproxy.service has entered the 'failed' state with result 'exit-code'.
    Oct 19 14:13:18 localhost systemd[1]: Failed to start HAProxy Load Balancer.
    -- Subject: A start job for unit haproxy.service has failed
    -- Defined-By: systemd
    -- Support: http://www.ubuntu.com/support
    --
    -- A start job for unit haproxy.service has finished with a failure.
    --
    -- The job identifier is 6314 and the job result is failed.
    
    0 回复  |  直到 5 年前
        1
  •  0
  •   Himanshu Poddar    5 年前

    由于我的Apache web服务器正在端口80上侦听,因此我无法为我的HAProxy配置相同的端口。

    把它改成另一个端口,它就工作了。

    frontend web-frontend
      bind 192.46.209.80:541
      mode http
      default_backend web-backend
    
    backend web-backend
      balance roundrobin
      server server1 192.46.209.80 check port 80
      server server2 192.46.209.82 check port 80