【请教】两台机器实现LVS(NAT)+Keepalived的结构,配置成功,访问时却只有一台能正常工作【解决】
使用两台rhel 5机器做的 lvs + keepalived的配置!
lvs使用的NAT模式,使用的mysql服务进行测试
最开始只安装了lvs时,测试能够成功轮询到不同的机器的mysql上
后来我装上keepalived,测试keepalived的切换这些都成功了,我以为所有都成功的时候,才发现LVS的轮询工作出问题了
使用VIP连接mysql时,如果LVS是轮询到keepalived的MASTER所在机器,那么可以连接,如果是轮询到BACKUP服务器时,mysql连接就超时了
其他一些可能有帮助的线索:
1、在BACKUP机器上,ping VIP是能通的,但是 telnet [VIP] 3306 就不通了,连接mysql更是不行了
2、在MASTER机器上,telnet [VIP] 3306 能通,使用VIP连接mysql只能连接到自己机器的mysql上(应该是保持了会话)
3、在任何机器上 telnet [realserver的真实IP] 3306 是通的
4、使用VIP连接mysql时,BACKUP机器上的mysql一定无法连接,感觉就像端口被屏蔽了一样
以下是我的配置,请教到底出了什么问题??- -
VIP 192.168.10.17
realserver1 192.168.11.200
realserver2 192.168.11.201
realserver1(MASTER)
############ keepalived 配置 ################! Configuration File for keepalived
global_defs {
notification_email {
uimeet@gmail.com
}
notification_email_from uimeet@gmail.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id realserver1
}
vrrp_sync_group VG_1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 150
advert_int 1
#nopreempt
authentication {
auth_type PASS
auth_pass tianzhen
}
virtual_ipaddress {
192.168.10.17/24 broadcast 192.168.10.255 dev eth0 label eth0:1
}
track_interface {
eth0
}
}
virtual_server 192.168.10.17 3306 {
delay_loop 6
lb_algo wlc
lb_kind NAT
nat_mask 255.255.255.0
persistence_timeout 5
protocol TCP
real_server 192.168.11.200 3306 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
real_server 192.168.11.201 3306 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
########### LVS ##############IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.10.17:mysql wlc persistent 5
-> realserver2:mysql Masq 3 0 0
-> 192.168.11.200:mysql Local 3 0 0
########### /etc/sysconfig/ipvsadm ###########
#keepalived自动生成的lvs规则
-A -t 192.168.10.17:mysql -s wlc -p 5
-a -t 192.168.10.17:mysql -r realserver2:mysql -m -w 3
-a -t 192.168.10.17:mysql -r 192.168.11.200:mysql -g -w 3
realserver2(BACKUP)
############ keepalived 配置 ################
! Configuration File for keepalived
global_defs {
notification_email {
uimeet@gmail.com
}
notification_email_from uimeet@gmail.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id realserver2
}
vrrp_sync_group VG_1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass tianzhen
}
virtual_ipaddress {
192.168.10.17/24 broadcast 192.168.10.255 dev eth0 label eth0:1
}
track_interface {
eth0
}
}
virtual_server 192.168.10.17 3306 {
delay_loop 6
lb_algo wlc
lb_kind NAT
nat_mask 255.255.255.0
persistence_timeout 5
protocol TCP
real_server 192.168.11.200 3306 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
real_server 192.168.11.201 3306 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
########## LVS ################
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.10.17:mysql wlc persistent 5
-> 192.168.11.201:mysql Local 3 0 0
-> realserver1:mysql Masq 3 0 0
########### /etc/sysconfig/ipvsadm ###########
#keepalived自动生成的lvs规则
-A -t 192.168.10.17:mysql -s wlc -p 5
-a -t 192.168.10.17:mysql -r 192.168.11.201:mysql -g -w 3
-a -t 192.168.10.17:mysql -r realserver1:mysql -m -w 3
- uimeet's blog
- Log in or register to post comments
- 13017 reads
Comments
Anonymous (没有被验证)
周六, 2010-09-18 08:06
Permalink
能和我联系吗?有些
能和我联系吗?有些问题想请教,我QQ 55218761!