无法让haproxy加载balanace Galera集群节点
问题描述:
我最近在两台Red Hat 7服务器上安装了Galera集群,并且配置正确。但是我无法使HAProxy正常工作。我只是得到错误。无法让haproxy加载balanace Galera集群节点
节点1的IP为1.1.1.1,所有流量都打开。 SELinux已将mysql设置为宽容。
节点2的IP为2.2.2.2,所有流量都打开。 SELinux已将mysql设置为宽容。
HAProxy的IP地址为3.3.3.3,所有流量都打开。 SELinux已被禁用。
所有节点位于不同的服务器上。节点3安装的唯一东西是HAProxy和mysql客户端。
所以每加莱拉文档,我安装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的状态,我得到这些错误:
[[email protected] haproxy]# service haproxy restart
Redirecting to /bin/systemctl restart haproxy.service
[[email protected] 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
答
六/etc/sysctl.conf,加上“net.ipv4.ip_nonlocal_bind = 1”文件末尾终于实现了我所需要的。
'netstat -a -n | grep':3306''...什么都显示? ifconfig是否显示一个3.3.3.3绑定的实际接口? –
经过几个小时的摸索,我发现这一步工作:vi /etc/sysctl.conf并在文件底部添加'net.ipv4.ip_nonlocal_bind = 1' – user3299633
这应该不是必须的。 “听加莱拉:3306”可能已经完成了你的意图。 –