【问题标题】:Can't get haproxy to load balanace Galera Cluster nodes无法让 haproxy 加载 balanace Galera Cluster 节点
【发布时间】:2017-07-05 00:25:01
【问题描述】:

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

节点 1 的 IP 为 1.1.1.1,并且所有流量都是开放的。 SELinux 已将 mysql 设置为 permissive。

节点 2 的 IP 为 2.2.2.2,并且所有流量都是开放的。 SELinux 已将 mysql 设置为 permissive。

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

【问题讨论】:

  • netstat -a -n | grep ':3306'... 有什么显示吗? ifconfig 是否显示绑定了 3.3.3.3 的实际接口?
  • 经过数小时的摸索后,我发现这一步可行:vi /etc/sysctl.conf 并将“net.ipv4.ip_nonlocal_bind=1”添加到文件底部
  • 这不应该是必要的。 listen galera :3306 可能已经完成了您的预期。

标签: redhat haproxy galera


【解决方案1】:

vi /etc/sysctl.conf 并在文件底部添加“net.ipv4.ip_nonlocal_bind=1”最终完成了我需要的操作。

【讨论】:

    猜你喜欢
    • 2018-05-27
    • 1970-01-01
    • 2017-05-15
    • 2021-11-24
    • 2014-04-07
    • 1970-01-01
    • 1970-01-01
    • 2016-07-11
    • 2021-10-07
    相关资源
    最近更新 更多