首页 新闻 会员 周边

lvs+keepalived 负载均衡一启动备就主动接管主是什么原因

0
悬赏园豆:10 [已关闭问题] 关闭于 2018-10-03 19:22

主keepalived配置
! Configuration File for keepalived

global_defs {
notification_email {
123456@qq.com
}
notification_email_from 123456@qq.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL1
}

vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 50
priority 100
advert_int 1
unicast_src_ip 192.168.1.120
track_interface {
ens33
}
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.50
}

}

virtual_server 192.168.1.50 80 {
delay_loop 3
lb_algo rr
lb_kind DR
persistence_timeout 0
protocol TCP

real_server 192.168.1.122 80 {
    weight 1
TCP_CHECK { 
        connect_timeout 3
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
    }
}

real_server 192.168.1.123 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
    }
} 

}
备配置
! Configuration File for keepalived

global_defs {
notification_email {
123456@qq.com
}
notification_email_from 123456@qq.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL2
}

vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 50
priority 80
advert_int 1
unicast_src_ip 192.168.1.121

track_interface {
    ens33
}
authentication {
    auth_type PASS
    auth_pass 1111
}
virtual_ipaddress {
    192.168.1.50
}

}

virtual_server 192.168.1.50 80 {
delay_loop 3
lb_algo rr
lb_kind DR
persistence_timeout 0
protocol TCP

real_server 192.168.1.122 80 {
    weight 1
TCP_CHECK { 
        connect_timeout 30
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80    
}

}
real_server 192.168.1.123 80 {
weight 1
TCP_CHECK {
connect_timeout 30
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}

}

主日记
[root@localhost ~]# tail -f /var/log/messages
Sep 22 00:03:41 localhost Keepalived_vrrp[1456]: Registering Kernel netlink reflector
Sep 22 00:03:41 localhost Keepalived_vrrp[1456]: Registering Kernel netlink command channel
Sep 22 00:03:41 localhost Keepalived_vrrp[1456]: Opening file '/etc/keepalived/keepalived.conf'.
Sep 22 00:03:41 localhost Keepalived_vrrp[1456]: (VI_1) Ignoring track_interface ens33 since own interface
Sep 22 00:03:41 localhost Keepalived_vrrp[1456]: Assigned address 192.168.1.120 for interface ens33
Sep 22 00:03:41 localhost Keepalived_vrrp[1456]: Assigned address fe80::7bb2:1052:a47:53f9 for interface ens33
Sep 22 00:03:41 localhost Keepalived_vrrp[1456]: Registering gratuitous ARP shared channel
Sep 22 00:03:41 localhost Keepalived_vrrp[1456]: (VI_1) removing VIPs.
Sep 22 00:03:41 localhost Keepalived_vrrp[1456]: (VI_1) Entering BACKUP STATE (init)
Sep 22 00:03:41 localhost Keepalived_vrrp[1456]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(8,9)]
Sep 22 00:03:44 localhost Keepalived_healthcheckers[1455]: TCP connection to [192.168.1.123]:tcp:80 success.
Sep 22 00:03:45 localhost Keepalived_healthcheckers[1455]: TCP connection to [192.168.1.122]:tcp:80 success.
Sep 22 00:03:45 localhost Keepalived_vrrp[1456]: (VI_1) Receive advertisement timeout
Sep 22 00:03:45 localhost Keepalived_vrrp[1456]: (VI_1) Entering MASTER STATE
Sep 22 00:03:45 localhost Keepalived_vrrp[1456]: (VI_1) setting VIPs.
Sep 22 00:03:45 localhost Keepalived_vrrp[1456]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:03:45 localhost Keepalived_vrrp[1456]: (VI_1) Sending/queueing gratuitous ARPs on ens33 for 192.168.1.50
Sep 22 00:03:45 localhost Keepalived_vrrp[1456]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:03:45 localhost Keepalived_vrrp[1456]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:03:45 localhost Keepalived_vrrp[1456]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:03:45 localhost Keepalived_vrrp[1456]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:03:50 localhost Keepalived_vrrp[1456]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:03:50 localhost Keepalived_vrrp[1456]: (VI_1) Sending/queueing gratuitous ARPs on ens33 for 192.168.1.50
Sep 22 00:03:50 localhost Keepalived_vrrp[1456]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:03:50 localhost Keepalived_vrrp[1456]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:03:50 localhost Keepalived_vrrp[1456]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:03:50 localhost Keepalived_vrrp[1456]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:03:55 localhost chronyd[642]: Selected source 185.134.197.4
Sep 22 00:03:55 localhost chronyd[642]: Source 193.228.143.24 replaced with 193.228.143.13
Sep 22 00:04:42 localhost systemd: Started Session 3 of user root.
Sep 22 00:04:42 localhost systemd-logind: New session 3 of user root.
Sep 22 00:04:42 localhost systemd: Starting Session 3 of user root.
备日记
[root@localhost ~]# tail -f /var/log/messages
Sep 22 00:04:04 localhost Keepalived_vrrp[1413]: Registering Kernel netlink command channel
Sep 22 00:04:04 localhost Keepalived_vrrp[1413]: Opening file '/etc/keepalived/keepalived.conf'.
Sep 22 00:04:04 localhost Keepalived_vrrp[1413]: (VI_1) Ignoring track_interface ens33 since own interface
Sep 22 00:04:04 localhost Keepalived_vrrp[1413]: Assigned address 192.168.1.121 for interface ens33
Sep 22 00:04:04 localhost Keepalived_vrrp[1413]: Assigned address fe80::3d45:626b:2bf:e2db for interface ens33
Sep 22 00:04:04 localhost Keepalived_vrrp[1413]: Registering gratuitous ARP shared channel
Sep 22 00:04:04 localhost Keepalived_vrrp[1413]: (VI_1) removing VIPs.
Sep 22 00:04:04 localhost Keepalived_vrrp[1413]: (VI_1) Entering BACKUP STATE (init)
Sep 22 00:04:04 localhost Keepalived_vrrp[1413]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(8,9)]
Sep 22 00:04:06 localhost Keepalived_healthcheckers[1412]: TCP connection to [192.168.1.123]:tcp:80 success.
Sep 22 00:04:08 localhost Keepalived_healthcheckers[1412]: TCP connection to [192.168.1.122]:tcp:80 success.
Sep 22 00:04:08 localhost Keepalived_vrrp[1413]: (VI_1) Receive advertisement timeout
Sep 22 00:04:08 localhost Keepalived_vrrp[1413]: (VI_1) Entering MASTER STATE
Sep 22 00:04:08 localhost Keepalived_vrrp[1413]: (VI_1) setting VIPs.
Sep 22 00:04:08 localhost Keepalived_vrrp[1413]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:04:08 localhost Keepalived_vrrp[1413]: (VI_1) Sending/queueing gratuitous ARPs on ens33 for 192.168.1.50
Sep 22 00:04:08 localhost Keepalived_vrrp[1413]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:04:08 localhost Keepalived_vrrp[1413]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:04:08 localhost Keepalived_vrrp[1413]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:04:08 localhost Keepalived_vrrp[1413]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:04:13 localhost Keepalived_vrrp[1413]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:04:13 localhost Keepalived_vrrp[1413]: (VI_1) Sending/queueing gratuitous ARPs on ens33 for 192.168.1.50
Sep 22 00:04:13 localhost Keepalived_vrrp[1413]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:04:13 localhost Keepalived_vrrp[1413]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:04:13 localhost Keepalived_vrrp[1413]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:04:13 localhost Keepalived_vrrp[1413]: Sending gratuitous ARP on ens33 for 192.168.1.50
Sep 22 00:07:02 localhost systemd: Starting Cleanup of Temporary Directories...
Sep 22 00:07:02 localhost systemd: Started Cleanup of Temporary Directories.

两台服务器
[root@localhost ~]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.1.50:80 rr
-> 192.168.1.122:80 Route 1 0 0
-> 192.168.1.123:80 Route 1 0 0

这问题到底出在哪里? 而且是可以互相ping 虚拟ip 192.168.1.50没有问题的

freedom/cn的主页 freedom/cn | 初学一级 | 园豆:8
提问于:2018-09-22 10:53
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册