Layer4“连接被拒绝”与haproxy

时间:2016-11-21 20:51:20

标签: haproxy

我需要一些关于如何设置 haproxy 的建议。我有两台网络服务器正在运行。为了测试,他们在端口8080上运行一个简单的节点服务器。

现在在我的haproxy服务器上,我启动haproxy,它给了我以下内容:

$> /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg 
[WARNING] 325/202628 (16) : Server node-backend/server-a is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[WARNING] 325/202631 (16) : Server node-backend/server-b is DOWN, reason: Layer4 timeout, check duration: 2001ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[ALERT] 325/202631 (16) : backend 'node-backend' has no server available!

只需一个注释:如果我这样做:

haproxy$> wget server-a:8080

我从节点服务器获得响应。

这是我的haproxy.cfg:

#---------------------------------------------------------------------  
# Global settings
#---------------------------------------------------------------------
global
    log         127.0.0.1 local2

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

    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                    tcp
    log                     global
    option                  tcplog
    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  www
    bind                        *:80
    default_backend             node-backend

#---------------------------------------------------------------------
# round robin balancing between the various backends
#--------------------------------------------------------------------
backend node-backend
   balance roundrobin
   mode tcp
   server server-a 172.19.0.2:8080 check
   server server-b 172.19.0.3:8080 check

如果我删除check选项,它似乎有用。有关如何修复haproxy检查机制的任何建议吗?

3 个答案:

答案 0 :(得分:2)

删除“mode tcp”并将其更改为“mode http” 我只是在这里猜测,但我想haproxy正在对您的Web服务器进行tcp检查,并且Web服务器无法响应它。
在“模式http”中,它以http模式检查Web服务器,并期望L4检查“响应200” 并期望一个字符串(无论你定义什么)作为L7检查

例如。 L4

backend node-backend balance roundrobin mode http #(NOT NEEDED IF DEFINED IN DEFAULTS) option httpchk server server-a 172.19.0.2:8080 check server server-b 172.19.0.3:8080 check
例如。 L7

backend node-backend balance roundrobin mode http #(NOT NEEDED IF DEFINED IN DEFAULTS) option httpchk get /SOME_URI http-check expect status 200 server server-a 172.19.0.2:8080 check server server-b 172.19.0.3:8080 check

答案 1 :(得分:1)

您需要借助命令获取服务器的确切IP地址

<EditText
   android:id="@+id/tv_email"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:backgroundTint="@color/transparent"
   android:drawablePadding="20dp"
   android:drawableStart="@drawable/email_white_24"
   android:hint="@string/hint_username"
   android:imeOptions="flagNoExtractUi|actionNext"
   android:inputType="textEmailAddress"
   android:textColor="@color/white"
   android:textColorHint="@color/color_green_hint"
   android:textSize="@dimen/textsize_regular"/>

并更正haproxy.cfg文件中的以下地址:

drawable

或如下所示修改行

ifconfig

答案 2 :(得分:1)

与@basickarl对docker的评论有关的另一条注释。如果要发送到docker(docker-compose)实例(即您正在运行多个服务实例的实例)中,则可能需要定义docker解析器并将其用于后端的dns解析:

解析器:

resolvers docker_resolver
nameserver dns 127.0.0.11:53

解析器的后端用法:

backend main
    balance roundrobin
    option http-keep-alive
    server haproxyapp app:80 check inter 10s resolvers docker_resolver resolve-prefer ipv4