keepalived – 没有连接,不听港口?

以下服务器:

....:100::10 mysql1 master ....:100::20 mysql2 master ....:100::30 loadbalancer (keepalived) with virtual ip ...:100::40 

configuration:

 vrrp_instance V1 { state MASTER interface eth0 lvs_sync_daemon_inteface eth0 virtual_router_id 51 priority 150 advert_int 1 smtp_alert virtual_ipaddress { ...:100::40 } } virtual_server ...:100::40 3306 { delay_loop 6 lb_algo wrr lb_kind DR protocol TCP real_server ...:100::10 3306 { weight 50 TCP_CHECK { connect_timeout 3 connect_port 3306 } } real_server ...:100::20 3306 { weight 10 TCP_CHECK { connect_timeout 3 connect_port 3306 } } } 

直接连接到两个服务器的连接工作:( bind-address = ::和没有ip6tables防火墙活动)

 $ mysql -uroot -p -h...:100::10 Welcome to the MySQL monitor. Commands end with ; or \g. $ mysql -uroot -p -h...:100::20 Welcome to the MySQL monitor. Commands end with ; or \g. 

…:100:30当然不是:

 $ mysql -uroot -p -h...:100::30 ERROR 2003 (HY000): Can't connect to MySQL server on '...:100::30' (111) 

不幸的是,我得到了…:100 :: 40的超时时间

 $ mysql -uroot -p -h...:100::40 ERROR 2003 (HY000): Can't connect to MySQL server on '...:100::40' (110) 

ipvsadm看起来对我好:

 # ipvsadm IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP [...:100::40]:mysql wrr -> [...:100::10]:mysql Route 50 0 0 # ifconfig eth0 Link encap:Ethernet HWaddr .......... inet6 addr: ............/64 Scope:Link inet6 addr: ...:100::30/64 Scope:Global inet6 addr: ...:100::40/128 Scope:Global 

我现在的问题是,keepalived不在端口3306上监听:

 # netstat -nlta Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN # keepalived --help Keepalived v1.2.2 (12/18,2011) 

故障在哪里?

每个realserver需要更改configuration,否则会丢弃networking数据包,因为它不会响应虚拟IP地址(例如…:100:40)

 # nano /etc/sysctl.conf net.ipv4.conf.eth0.arp_ignore = 1 net.ipv4.conf.eth0.arp_announce = 2 

或直接

 echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce 

您需要将虚拟IP地址添加到本地环回:

 ip addr add 2a00:14e0:600:1200:100::40 dev lo 

并编辑/ etc / network / interfaces,以便在重新引导后更改是持久的:

 iface eth0 inet6 static address ...:100::20 netmask 64 gateway ...::1 post-up ip addr add ...:100::40 dev lo 

现在第一次连接超时,但第二次连接工作正常。 我会testing这个。