HAProxy mysqlconfiguration

我尝试了几次,但我无法弄清楚为什么我的mariadb负载平衡器与haproxy不工作。 我有 :

  • 1 HAProxy(CentOS):10.181.102.249
  • 1名硕士(CentOS):10.183.241.150
  • 2个奴隶(CentOS):10.182.2.50和10.181.164.36

HAproxy conf:

global log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon stats socket /var/lib/haproxy/stats defaults mode http log global option dontlognull 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 listen mysql-read 0.0.0.0:3307; mode tcp balance roundrobin option tcpka option httpchk server db2 10.182.2.50:3306 check port 9201 inter 1s rise 1 fall 1 server db3 10.181.164.36:3306 check port 9201 inter 1s rise 1 fall 1 #server db1 10.183.241.150:3306 check port 9201 inter 1s rise 1 fall 1 server db1 10.183.241.150:3306 backup listen mysql-write 0.0.0.0:3306 mode tcp option mysql-check user haproxy balance roundrobin server db1 10.183.241.150:3306 check listen stats :1981 mode http stats enable stats uri / stats realm Strictly\ Private stats auth test:test 

我禁用了firewalld,并确保没有安装iptables,以及selinux不工作,首先让我的testing知道这是否工作。

但是当我尝试连接时:

 mysql -hlocalhost -uuser -P 3307 -p -e "show variables like 'server_id'"; 

要么

 mysql -hlocalhost -uuser -p -e "show variables like 'server_id'"; 

我得到:

 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 

从远程服务器到haproxy以及相同的。

如果我列出来自haproxy服务器的端口,我得到:

 [root@haproxy ~]# netstat -tnlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 21261/haproxy tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 21261/haproxy tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1294/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1533/master tcp 0 0 0.0.0.0:1981 0.0.0.0:* LISTEN 21261/haproxy tcp6 0 0 :::22 :::* LISTEN 1294/sshd tcp6 0 0 ::1:25 :::* LISTEN 1533/master 

有任何想法吗 ?

谢谢。

正如你的错误信息所示, mysql命令试图通过一个UNIX套接字而不是一个TCP套接字进行连接,从而忽略了端口号。 如果你把localhost作为主机参数,这是mysql所做的。 请尝试使用-h 127.0.0.1

MySQL客户端不是试图通过系统的IP连接,而是通过my.cnf定义的套接字文件来连接。 由于该服务不在本地运行,因此不起作用。

尝试在连接时使用IP:

 mysql -h10.181.102.249 -uuser -P 3307 -p -e "show variables like 'server_id'"; 

要么

 mysql -h10.181.102.249 -uuser -p -e "show variables like 'server_id'";