如何使用HA代理服务器作为负载均衡器

时间:2019-03-29 06:01:44

标签: load-balancing haproxy

我正在尝试将HA代理服务器用作两个Web服务器之间的负载平衡器。 各个服务器已启动并在指定端口上运行。 但是我无法通过HA代理服务器访问Web服务器。 我已使用以下标准设置配置了HA代理

/etc/haproxy/haproxy.cfg

global
    log         127.0.0.1 local0

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend  main *:80
    mode http
    default_backend             app

backend app
    balance     roundrobin
    option forwardfor
    http-request set-header X-Forwarded-Port %[dst_port]
    http-request add-header X-Forwarded-Proto https if { ssl_fc }
    option httpchk HEAD / HTTP/1.1\r\nHost:localhost
    server  app1 10.368.240.116:9091
    server  app2 10.368.240.317:9092
    #server  app3 127.0.0.1:5003 check
    #server  app4 127.0.0.1:5004 check

我可以从我的HA代理主机上成功卷曲上述服务器

curl -i "10.368.240.116:9091"
HTTP/1.1 200 OK

curl -i "10.368.240.317:9091"
HTTP/1.1 200 OK

我的HA代理服务器正在侦听80端口 但是当我点击它时,它显示了503错误

curl -iv  "127.0.0.1"
* About to connect() to 127.0.0.1 port 80 (#0)
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 127.0.0.1
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 503 Service Unavailable
HTTP/1.0 503 Service Unavailable
< Cache-Control: no-cache
Cache-Control: no-cache
< Connection: close
Connection: close
< Content-Type: text/html
Content-Type: text/html

<
<html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>
* Closing connection 0

任何人都可以指导我在哪里做错

0 个答案:

没有答案