LVS 不工作

LVS 不工作
  • 贵宾:10.110.23.239
  • 真实服务器:10.110.23.141
  • 级别:10.110.23.134

我在 real-server(10.110.23.141) 上部署了一个 spring-boot 应用,端口是 18787,在任何服务器上都可以成功访问。但是我无法通过 vip 连接我的应用。

keepalived配置文件

global_defs 
{
   router_id LVS_S
   vrrp_skip_check_adv_addr
}
vrrp_instance VI_1 {
    state BACKUP
    nopreempt
    interface eth0
    virtual_router_id 51
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.110.23.239
    }
}

virtual_server 10.110.23.239 18787 {
    delay_loop 3000
    lb_algo wrr
    lb_kind DR
    persistence_timeout 1
    protocol TCP
    real_server 10.110.23.141 18787 { 
        weight 1  
        TCP_CHECK {
            connect_timeout 10
            delay_before_retry 3
        }
    }
}

“ipvsadm -Ln”显示:

IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.110.23.239:18787 wrr persistent 1
  -> 10.110.23.141:18787          Route   1      0          0 

我已经配置了真实服务器如下:

#!/bin/bash 
SNS_VIP=10.110.23.239
case "$1" in
start)
       ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP up
       /sbin/route add -host $SNS_VIP dev lo:0
       echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
       echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
       echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
       echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
       echo "1" > /proc/sys/net/ipv4/conf/eth0/arp_ignore
    echo "2" > /proc/sys/net/ipv4/conf/eth0/arp_announce
    echo "1" > /proc/sys/net/ipv4/conf/default/arp_ignore
    echo "2" > /proc/sys/net/ipv4/conf/default/arp_announce
       sysctl -p >/dev/null 2>&1
       echo "RealServer Start OK"
       ;;
stop)
       ifconfig lo:0 down
       route del $SNS_VIP >/dev/null 2>&1
       echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
       echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
       echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
       echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
    echo "0" > /proc/sys/net/ipv4/conf/eth0/arp_ignore
    echo "0" > /proc/sys/net/ipv4/conf/eth0/arp_announce
    echo "0" > /proc/sys/net/ipv4/conf/default/arp_ignore
    echo "0" > /proc/sys/net/ipv4/conf/default/arp_announce
       echo "RealServer Stoped"
       ;;
*)
       echo "Usage: $0 {start|stop}"
       exit 1
esac
exit 0

“ip a”在真实服务器上显示:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 10.110.23.239/32 brd 10.110.23.239 scope global lo:0
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever

当我在 lvs 服务器上使用“curl 10.110.23.239:18787/test”时,它无法工作。

lvs 服务器上显示“ipvsadm -Lnc”:

IPVS connection entries
pro expire state       source             virtual            destination
TCP 00:49  NONE        10.110.23.239:0    10.110.23.239:18787 10.110.23.141:18787
TCP 00:55  SYN_RECV    10.110.23.239:36808 10.110.23.239:18787 10.110.23.141:18787

lvs服务器上显示“tcpdump -i eth0 port 18787 -n -e”:

15:04:36.249440 fa:16:3e:fd:65:9c > 68:05:ca:21:d6:e5, ethertype IPv4 (0x0800), length 74: 10.110.23.239.36830 > 10.110.23.239.18787: Flags [S], seq 2344358212, win 43690, options [mss 65495,sackOK,TS val 1435554847 ecr 0,nop,wscale 7], length 0
15:04:36.249497 68:05:ca:21:d6:e5 > fa:16:3e:fd:65:9c, ethertype IPv4 (0x0800), length 74: 10.110.23.239.36830 > 10.110.23.239.18787: Flags [S], seq 2344358212, win 43690, options [mss 65495,sackOK,TS val 1435554847 ecr 0,nop,wscale 7], length 0
15:04:37.250335 fa:16:3e:fd:65:9c > 68:05:ca:21:d6:e5, ethertype IPv4 (0x0800), length 74: 10.110.23.239.36830 > 10.110.23.239.18787: Flags [S], seq 2344358212, win 43690, options [mss 65495,sackOK,TS val 1435555848 ecr 0,nop,wscale 7], length 0
15:04:37.250488 68:05:ca:21:d6:e5 > fa:16:3e:fd:65:9c, ethertype IPv4 (0x0800), length 74: 10.110.23.239.36830 > 10.110.23.239.18787: Flags [S], seq 2344358212, win 43690, options [mss 65495,sackOK,TS val 1435555848 ecr 0,nop,wscale 7], length 0

我已关闭所有服务器上的防火墙。

我的服务器出了什么问题?

顺便说一句,我的服务器在 Pass 上运行。

相关内容