我的 HAProxy 正在运行VIP:192.168.61.32
,我也检查过netstat -tulnp|grep 3306
tcp 0 0 192.168.61.32:3306 0.0.0.0:* LISTEN 7895/haproxy
但是当我跑步时
mysql -h 192.168.61.32 -u root -p:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
192.168.61.30 & 192.168.61.31
当我尝试连接到数据库时,HA 代理节点位于&
root@haproxy1:~# mysql -h 192.168.61.30 -u root -p
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.61.30' (111)
root@haproxy1:~# mysql -h 192.168.61.31 -u root -p
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.61.31' (111)
我的后端 Mysql 节点位于192.168.61.33 & 192.168.61.34,
我可以使用直接连接到它们
mysql -h 192.168.61.33 -u root -p
mysql -h 192.168.61.34 -u root -p
haproxy.conf的配置细节:
global
log /dev/log local0
# log /dev/log local1 notice
chroot /var/lib/haproxy
user haproxy
group haproxy
daemon
log 192.168.61.31 local0
stats socket /var/lib/haproxy/stats
maxconn 4000
defaults
log global
# mode http
# option httplog
option dontlognull
contimeout 5000
clitimeout 50000
srvtimeout 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
listen stats 192.168.61.31:80
mode http
option httplog
stats enable
stats uri /stats
stats realm HAProxy\ Statistics
stats auth admin:admin
listen galera 192.168.61.32:3306
balance source
mode tcp
option tcpka
option mysql-check user haproxy
server mysql1 192.168.61.33:3306 check weight 1
server mysql2 192.168.61.34:3306 check weight 1
这就是我在第二个 HA-Proxy 服务器中的 haproxy.conf 的配置,第一个 HA-Proxy 服务器配置是相同的,除了global & stats 部分中的 Ip 地址是 192.168.61.30 [First HA-Proxy Server]