keepalived+LVS/DR HA负载均衡部署
Posted logansxb
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了keepalived+LVS/DR HA负载均衡部署相关的知识,希望对你有一定的参考价值。
LVS是一种负载均衡集群;属于四层负载均衡,处理高并发非常有优势;但是LVS本身不具备监控故障点、剔除、添加的功能。我们可以将keepalived+LVS的形式,达到可以自动工作的目的;
我们选用两台主机作为keepalived+LVS服务器;两台运行httpd服务进行测试;
我们先准备集群服务器;
安装ipvsadm;
[root@sxb-1 ~]# yum install ipvsadm
配置keepalive文件;
virtual_server 192.168.88.230 80 delay_loop 6 lb_algo rr lb_kind DR # persistence_timeout 50 #端口亲缘性 protocol TCP real_server 192.168.88.102 80 weight 1 TCP_CHECK connect_timeout 3
real_server 192.168.88.103 80 weight 1 TCP_CHECK connect_timeout 3
开启转发功能;(两台keepalive都需要开启)
[root@sxb-1 ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
启动 keepalived服务;
[root@sxb-1 ~]# systemctl start keepalived.service
httpd配置;103也需要进行ip的配置;
[root@sxb-2 ~]# ip addr add 192.168.88.230 dev lo [root@sxb-2 ~]# ip addr show 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 192.168.88.230/32 scope global lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever
我们还需要修改两个参数;(都需要修改)
[root@sxb-2 ~]# echo 1 > /proc/sys/net/ipv4/conf/ens33/arp_ignore 不作答 [root@sxb-2 ~]# echo 2 > /proc/sys/net/ipv4/conf/ens33/arp_announce 帮兄弟转发
测试:
我们可以看到浮动IP和LVS策略自动生成了;
[root@sxb-1 ~]# ip addr s 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 inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:88:9d:40 brd ff:ff:ff:ff:ff:ff inet 192.168.88.101/24 brd 192.168.88.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet 192.168.88.230/24 scope global secondary ens33 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe88:9d40/64 scope link valid_lft forever preferred_lft forever [root@sxb-1 ~]# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.88.230:80 rr -> 192.168.88.102:80 Masq 1 0 0 -> 192.168.88.103:80 Masq 1 0 0
[root@sxb-5 ~]# curl 192.168.88.230 103 [root@sxb-5 ~]# curl 192.168.88.230 102 [root@sxb-5 ~]# curl 192.168.88.230 103 [root@sxb-5 ~]# curl 192.168.88.230 102
[root@sxb-1 ~]# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.88.230:80 rr -> 192.168.88.102:80 Route 1 0 2 -> 192.168.88.103:80 Route 1 0 2
我们停掉master;发现浮动IP消失了
[root@sxb-1 ~]# systemctl stop keepalived.service [root@sxb-1 ~]# ip addr s 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 inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:88:9d:40 brd ff:ff:ff:ff:ff:ff inet 192.168.88.101/24 brd 192.168.88.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe88:9d40/64 scope link valid_lft forever preferred_lft forever
keepalived将fudongIP给了104;
[root@sxb-4 ~]# ip addr s 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 inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:5b:71:db brd ff:ff:ff:ff:ff:ff inet 192.168.88.104/24 brd 192.168.88.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet 192.168.88.230/24 scope global secondary ens33 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe5b:71db/64 scope link valid_lft forever preferred_lft forever
对于httpd服务器来说没有影响;
[root@sxb-5 ~]# curl 192.168.88.230 103 [root@sxb-5 ~]# curl 192.168.88.230 102 [root@sxb-5 ~]# curl 192.168.88.230 103 [root@sxb-5 ~]# curl 192.168.88.230 102
当master恢复后,依然会出现抢夺问题(王者归来);具体问题具体对待是否需要抢夺;
以上是关于keepalived+LVS/DR HA负载均衡部署的主要内容,如果未能解决你的问题,请参考以下文章
LVS DR模式负载均衡搭建keepalived高可用+LVS负载均衡配合