无法通过haproxy加载balanace Galera Cluster节点

时间:2017-07-05 00:25:02

标签: redhat haproxy galera

我最近在两台Red Hat 7服务器上安装了Galera Cluster并正确配置了它。但是,我无法让HAProxy工作。我只是犯了错误。

节点1的IP为1.1.1.1,所有流量都是开放的。 SELinux将mysql设置为允许。

节点2的IP为2.2.2.2,所有流量都是开放的。 SELinux将mysql设置为允许。

HAProxy的IP为3.3.3.3,所有流量都是开放的。 SELinux已被禁用。

所有节点都在不同的服务器上。 Node 3上安装的唯一东西是HAProxy和mysql客户端。

因此,根据Galera文档,我安装HAProxy并将此部分添加到配置文件的底部:

# Load Balancing for Galera Cluster
listen galera 3.3.3.3:3306
     balance roundrobin
     mode tcp
     option tcpka
     option mysql-check user haproxy
     server node1 1.1.1.1:3306 check weight 1
     server node2 2.2.2.2:3306 check weight 1

但是当我检查HAProxy的状态时,我得到了这些错误:

[root@nodemgr haproxy]# service haproxy restart
Redirecting to /bin/systemctl restart  haproxy.service
[root@nodemgr haproxy]# service haproxy status
Redirecting to /bin/systemctl status  haproxy.service
● haproxy.service - HAProxy Load Balancer
   Loaded: loaded (/usr/lib/systemd/system/haproxy.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2017-07-04 20:18:50 EDT; 3s ago
  Process: 11773 ExecStart=/usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid $OPTIONS (code=exited, status=1/FAILURE)
 Main PID: 11773 (code=exited, status=1/FAILURE)

Jul 04 20:18:50 nodemgr systemd[1]: Started HAProxy Load Balancer.
Jul 04 20:18:50 nodemgr systemd[1]: Starting HAProxy Load Balancer...
Jul 04 20:18:50 nodemgr haproxy-systemd-wrapper[11773]: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /ru...pid -Ds
Jul 04 20:18:50 nodemgr haproxy-systemd-wrapper[11773]: [WARNING] 184/201850 (11774) : parsing [/etc/haproxy/haproxy.cfg:45] : 'option httplog'...cplog'.
Jul 04 20:18:50 nodemgr haproxy-systemd-wrapper[11773]: [WARNING] 184/201850 (11774) : config : 'option forwardfor' ignored for proxy 'galera' ...P mode.
Jul 04 20:18:50 nodemgr haproxy-systemd-wrapper[11773]: [ALERT] 184/201850 (11774) : Starting proxy galera: cannot bind socket [3.3.3.3:3306]
Jul 04 20:18:50 nodemgr systemd[1]: haproxy.service: main process exited, code=exited, status=1/FAILURE
Jul 04 20:18:50 nodemgr haproxy-systemd-wrapper[11773]: haproxy-systemd-wrapper: exit, haproxy RC=1
Jul 04 20:18:50 nodemgr systemd[1]: Unit haproxy.service entered failed state.
Jul 04 20:18:50 nodemgr systemd[1]: haproxy.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

我假设我的问题在这里:

 Jul 04 20:18:50 nodemgr haproxy-systemd-wrapper[11773]: [ALERT] 184/201850 (11774) : Starting proxy galera: cannot bind socket [3.3.3.3:3306]

但是在禁用SELinux后我不知道还需要做什么。非常感谢任何帮助!

完整的haproxy配置文件在这里:

#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    # to have these messages end up in /var/log/haproxy.log you will
    # need to:
    #
    # 1) configure syslog to accept network log events.  This is done
    #    by adding the '-r' option to the SYSLOGD_OPTIONS in
    #    /etc/sysconfig/syslog
    #
    # 2) configure local2 events to go to the /var/log/haproxy.log
    #   file. A line like the following can be added to
    #   /etc/sysconfig/syslog
    #
    #    local2.*                       /var/log/haproxy.log
    #
    log         127.0.0.1 local2

    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 *:5000
    acl url_static       path_beg       -i /static /images /javascript /stylesheets
    acl url_static       path_end       -i .jpg .gif .png .css .js

    use_backend static          if url_static
    default_backend             app

#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
    balance     roundrobin
    server      static 127.0.0.1:4331 check
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
    balance     roundrobin
    server  app1 127.0.0.1:5001 check
    server  app2 127.0.0.1:5002 check
    server  app3 127.0.0.1:5003 check
    server  app4 127.0.0.1:5004 check

# Load Balancing for Galera Cluster
listen galera 3.3.3.3:3306
     balance roundrobin
     mode tcp
     option tcpka
     option mysql-check user haproxy
     server node1 1.1.1.1:3306 check weight 1
     server node2 2.2.2.2:3306 check weight 1

1 个答案:

答案 0 :(得分:0)

vi /etc/sysctl.conf并将'net.ipv4.ip_nonlocal_bind = 1'添加到文件底部,最终完成我需要的操作。