我正在尝试使用 HAProxy 来控制一个带有 IP 的 Mariadb 集群:
192.168.206.41 mariadb1
192.168.206.157 mariadb2
192.168.206.94 mariadb3
,我在同一台服务器上安装了 haproxy,数据库为:
192.168.206.41 haproxy1
192.1628.206.157 haproxy
我的问题是当我使用语法时:mysql -u root -p -h 192.168.206.94 -P 3030 -e "select Host, User, Password from mysql.user"在 mariadb1 上测试 haproxy1 和 mariadb3 之间的连接。它不起作用并响应:
[root@mariadb1 ~]# mysql -u root -p -h 192.168.206.94 -P 3030 -e "select Host, User, Password from mysql.user" Enter password:
ERROR 2002 (HY000): Can't connect to MySQL '192.168.206.94' (115) 上的服务器
虽然我已禁用 SELinux 并在两台服务器上的 firewalld 上添加了必要的端口
[root@mariadb1 ~]# firewall-cmd --list-ports;
3306/tcp 443/tcp 80/tcp 4567/tcp 4568/tcp 4444/tcp 4567/udp 873/tcp 9200/tcp 9000/tcp 3030/tcp
这在两台服务器上都是一样的。
这是我的 /etc/haproxy/haproxy.cfg:
global
log 127.0.0.1 local2
maxconn 1024
user haproxy
group haproxy
daemon
stats socket /var/run/haproxy.sock mode 600 level admin # Make sock file for haproxy
defaults
log global
mode tcp
option tcplog
option dontlognull
retries 3
option redispatch
maxconn 1024
timeout http-request 10s
timeout connect 5s
timeout client 50000ms
timeout server 50000ms
listen mariadb_cluster 0.0.0.0:3030
## MariaDB balance leastconn - the cluster listening on port 3030.
mode tcp
balance leastconn
option httpchk
option tcp-check
server mariadb1 192.168.206.41:3306 check port 9200
server mariadb2 192.168.206.157:3306 check port 9200
server mariadb3 192.168.206.94:3306 check port 9200 backup # Make mariadb3 as backup - automatic replication data
listen stats 0.0.0.0:9000
## HAProxy stats web gui running on port 9000 - username and password: huy123.
mode http
stats enable
stats uri /stats
stats realm HAProxy\ Statistics
stats auth huy123:huy123
stats admin if TRUE
我还检查并禁用了 /etc/my.cnf 中的 bind-address=127.0.0.1
mariadb 集群工作正常,语法 Mariadb>show status like 'wsrep_cluster_size'; 回复:
MariaDB [(none)]> show status like 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 3 |
+--------------------+-------+
1 row in set (0.001 sec)
而且我还确定创建一个具有所有权限的用户 root@'%' 和另一个用于 xinetd 的 clustercheck 用户
我还在文件 /etc/hosts 中声明了服务器的所有 IP。
另一个重要问题是,当我尝试将 haproxy1 连接到 mariadb2(带有 haproxy 的那个)时,它显示:
[root@mariadb1 ~]# mysql -u root -p -h 192.168.206.157 -P 3030 -e "select Host, User, Password from mysql.user" Enter password:
ERROR 2013 (HY000): Lost connection to MySQL server at '握手:读取初始通信数据包',系统错误:11
虽然我曾经# semanage port -m -t http_port_t -p tcp 3030让 SELinux 在不禁用 SELinux 的情况下绕过端口 3030,9200 和 9000
但是当我禁用 SElinux 时,它又可以正常工作了。我知道这不是一种合适的方式,因为在管理服务器时不会禁用 SELinux。
我在谷歌上查了好几个小时,很可能我是地球上唯一一个有这些问题的人。有人可以帮我解决这两种情况吗?