我正在使用HAProxy在3个物理节点上build立一个testing集群 – Maria Galera集群。 它的工作,但我已经做了一些初学者的错误,我似乎无法解决 – 所以希望有人可以投下专家的眼睛,帮助我吗?!
我有3个物理节点Node1:10.1.1.120
节点2:10.1.1.121
节点3:10.1.1.124
使用HAProxy 10.1.1.113的虚拟IP
正在运行,当我通过虚拟IP查询时,我得到…
$ mysql -uroot -pPassword -P 3306 -h 10.1.1.113 -e "select @@hostname; show processlist;" +------------+ | @@hostname | +------------+ | node2 | +------------+ +----+-------------+-------------+------+---------+------+--------------------+------------------+----------+ | Id | User | Host | db | Command | Time | State | Info | Progress | +----+-------------+-------------+------+---------+------+--------------------+------------------+----------+ | 1 | system user | | NULL | Sleep | 37 | NULL | NULL | 0.000 | | 2 | system user | | NULL | Sleep | 37 | wsrep aborter idle | NULL | 0.000 | | 45 | root | node1:55877 | NULL | Query | 0 | init | show processlist | 0.000 | +----+-------------+-------------+------+---------+------+--------------------+-
如果我在node1上执行ip a – 这确实是我的虚拟IP地址所在的位置,但是主机名作为node2返回。
如果我在node1上closures(或只是禁用eth0),则虚拟IP地址在其他位置移动,但@@主机名仍然以节点2的forms返回。
问题来了,如果我closuresnode2,然后当我尝试使用虚拟IP的MySQL我得到:
**ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0 "Internal error/check (Not system error)"**
(此时如果我login到任何本地机器而不使用虚拟IP,它将工作)。
所以,看起来好像HAProxy部分正在工作(因为这适当地移动),但MariaDB正在尝试做自己的事情,并已决定一切需要通过Node2路由。
我的.cnf文件中没有绑定地址。 我正在使用端口1306为我的SQL服务,以避免与3306重新启动服务的计算机上碰巧具有虚拟IP和3306后同时发生任何冲突。
我的keepalived文件是…(不知道这是否正确,但所有节点设置为主,优先级分别为100,101和102 – 似乎没有什么差别)
global_defs { router_id geordi } vrrp_script haproxy { script "killall -0 haproxy" interval 1 weight 1 } vrrp_instance 51 { virtual_router_id 51 priority 101 state MASTER interface eth0 virtual_ipaddress { 10.1.1.113 dev eth0 } track_script { haproxy } }
和我的haproxy.cfg是:
global log /dev/log local0 log /dev/log local1 notice chroot /var/lib/haproxy user haproxy group haproxy daemon defaults log global mode http 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 mysql_proxy 10.1.1.113:3306 mode tcp balance roundrobin option tcpka option httpchk option mysql-check user haproxy server node1 10.1.1.120:1306 check server node2 10.1.1.121:1306 check server node3 10.1.1.124:1306 check
任何build议感激地收到请 – 我非常接近得到这一切工作,只是不完全在那里!
在my.cnf显式设置bind-address=0.0.0.0 。
另外(如果你是这样的话,你可能已经这样做了):
10.1.1.113 (如果使用keepalived,则通过伪接口为/ 32)。 /etc/sysctl.conf设置net.ipv4.conf.default.rp_filter = 2 /etc/sysctl.conf设置net.ipv4.conf.default.accept_source_route = 0 这允许MySQL在所有接口上侦听,并且允许MySQL在该数据包不适用的接口上响应。
node1(10.1.1.120)上的networking接口在10.1.1.120对应的接口上获取“10.1.1.13”。 通常情况下,这将会下降,说“那不适合我”。 这发生在TCP / IP模型的“Internet”层上。
然而,上面的条款2和条款3说“只是接受它,它可能是我们的”,然后传递到MySQL(TCP / IP模型的“应用程序”层)。 MySQL发现我们绑定了所有的地址,其中之一是10.1.1.113(规定1),并对其进行处理。