admincai 发表于 2017-03-15 16:51

keepalived+LVS+Tomcat7负载均衡只有第一台realserver可用的问题

两台虚拟机,操作系统RHEL6.5,建了keepalived+LVS+Tomcat7,主备切换都正常,但是用另外两台机器测试负载时,第一台机器可以正常通过VIP访问页面,但是第二台机器访问VIP时就会提示服务器没有响应。这两台realserver肯定没问题,使用实IP访问都能正常,就是使用VIP访问时才会出现这个问题。结构如下:1、realserver(master:192.168.92.98:9080    backup:192.168.92.99:9080)2、virtual_server(192.168.92.100:9080)


3、两台客户机,客户机A192.168.92.1和客户机B192.168.92.132
4、测试场景:在客户机A访问:http://192.168.92.100:9080时,可以正常访问,在服务器上查询,是访问到192.168.92.98服务器上。在客户机B上访问:http://192.168.92.100:9080 ,可以在192.168.92.99服务器上看到连接了,但就是无法返回页面,过会在客户机浏览器报错”网络连接异常、网站服务器失去响应“,此时192.168.92.99服务器使用netstat -ant|grep 9080 ,发现连接状态是”tcp      0      0 192.168.92.99:9080          192.168.92.1:52438          SYN_RECV“,但访问http://192.168.92.99:9080是可以正常访问的。/var/var/log/messages没有报错。
请教各位高手帮忙分析一下,谢谢,谢谢,谢谢哈。


master的keepalived.conf
global_defs {
#   notification_email {
#   acassen@firewall.loc
#   failover@firewall.loc
#   sysadmin@firewall.loc
#   }
#   notification_email_from Alexandre.Cassen@firewall.loc
#   smtp_server 192.168.200.1
#   smtp_connect_timeout 30
   router_id LVS_DEVEL_HA1
}

vrrp_sync_group VGM {
group {
VI_1
}
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
      192.168.92.100/24
    }
}

virtual_server 192.168.92.100 9080 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP
    sorry_server 127.0.0.1 9080

    real_server 192.168.92.98 9080 {
      weight 1
            TCP_CHECK {
      connect_timeout 5
        nb_get_retry 3
        connect_port 9080
      }
    }
    real_server 192.168.92.99 9080 {
      weight 1
            TCP_CHECK {
      connect_timeout 5
        nb_get_retry 3
        connect_port 9080
      }
    }
}



backup的keepalived.conf
global_defs {
#   notification_email {
#   acassen@firewall.loc
#   failover@firewall.loc
#   sysadmin@firewall.loc
#   }
#   notification_email_from Alexandre.Cassen@firewall.loc
#   smtp_server 192.168.200.1
#   smtp_connect_timeout 30
   router_id LVS_DEVEL_HA2
}

vrrp_sync_group VGM {
group {
VI_1
}
}

vrrp_instance VI_1 {
    state BAKEUP
    interface eth0
    virtual_router_id 51
    priority 99
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
      192.168.92.100/24
    }
}

virtual_server 192.168.92.100 9080 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP
    sorry_server 127.0.0.1 9080

    real_server 192.168.92.98 9080 {
      weight 1
      TCP_CHECK {
      connect_timeout 5
      nb_get_retry 3
      connect_port 9080
      }
    }
    real_server 192.168.92.99 9080 {
      weight 1
      TCP_CHECK {
      connect_timeout 5
      nb_get_retry 3
      connect_port 9080
      }   
    }   
}




pingningcheng 发表于 2017-04-14 22:52

楼主,我也是碰到这个问题,通过vip访问时时好时坏。
这个keepalive是不是只有master才对外工作,backup节点不对外工作,当master故障时backup节点接管?
另外你是lvs+keepalived+tomcat均在同一台服务器?

一般都会通过nginx做代理吧。

夏织风 发表于 2017-05-27 09:55

回复 2# pingningcheng

不需要nginx作负载均衡,keepalived+lvs本身就是用来做负载均衡+互为主备。

夏织风 发表于 2017-05-27 10:19

回复 1# admincai

请问你的master和backup是也同时承担具体业务吗?官方文档上使用的是4台机器,2台做负载均衡和主备、2台提供具体业务。
你这个问题是因为master和backup同时既作为负载均衡和主备又作为具体业务提供机器,造成master和backup在相互调用的时候产生了死锁。

shang2010 发表于 2017-05-27 16:03

nginx对于大多数公司的一般的业务场景够用了,跑十来台没有问题

ashchen 发表于 2018-06-04 13:05

回复 4# 夏织风

能问下是怎么实现的吗?我也正在试验这个问题

ashchen 发表于 2018-06-04 13:05

回复 4# 夏织风

能问下是怎么实现的吗?我也正在试验这个问题

ashchen 发表于 2018-06-04 13:05

回复 4# 夏织风

能问下是怎么实现的吗?我也正在试验这个问题

锐讯小何 发表于 2018-07-23 20:49

遇到服务器问题都可以咨询我咯 ,我们这边这边是做服务器出租的vx 13413398997
页: [1]
查看完整版本: keepalived+LVS+Tomcat7负载均衡只有第一台realserver可用的问题