我正在用HAProxy在3个物理节点上设置一个测试集群- Maria集群。它的工作,但我已经做了一些初学者的错误,我似乎无法解决-所以希望有人可以投出专家的眼睛,并帮助我?!
我有3个物理节点Node1: 10.1.1.120
Node2: 10.1.1.121
Node3: 10.1.1.124
使用HAProxy虚拟IP为10.1.1.113
开始运行,当我通过虚拟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上关闭(或仅禁用node1),虚拟IP地址将转移到其他地方,但@@hostname仍然以node2的形式返回。
如果我关闭node2,那么当我尝试使用我得到的虚拟IP来mysql时,问题就来了:
**ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0 "Internal error/check (Not system error)"**(此时,如果我在不使用虚拟IP的情况下登录到任何本地机器,它就会工作)。
因此,似乎HAProxy部件正在正常工作(这是适当的),但是MariaDB正在尝试做它自己的事情,并且已经决定一切都需要通过Node2路由。
我的.cnf文件中没有绑定地址.我使用端口1306作为sql服务,以避免在同时具有虚拟IP和post 3306的机器上重新启动服务时与3306发生冲突。
我保存的文件是..。(不确定这是否正确,但所有节点都被设置为主节点,优先级分别为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感激地收到任何建议
发布于 2015-07-04 19:34:34
在bind-address=0.0.0.0中显式设置my.cnf。
此外(如果您已经做到了这一点,您可能已经这样做了):
10.1.1.113 (如果使用的是保持生存,然后通过虚拟接口作为/32)。net.ipv4.conf.default.rp_filter = 2中设置/etc/sysctl.confnet.ipv4.conf.default.accept_source_route = 0中设置/etc/sysctl.conf这允许MySQL在所有接口上侦听,并允许MySQL在数据包不适合的接口上进行响应。
node1上的网络接口( 10.1.1.120 )在对应于10.1.1.120的接口上以"10.1.1.13“的形式获取数据包。通常情况下,这句话会被删除,说“那不是给我的”。这发生在TCP/IP模型的"Internet“层。
然而,上面的第2条和第3条规定“只要接受它,它可能是我们的”,然后传递给MySQL ( TCP/IP模型的“应用程序”层)。MySQL看到我们绑定到所有地址,其中一个地址是10.1.1.113 (提供1),并对其进行处理。
https://serverfault.com/questions/670601
复制相似问题