准备两台web服务器50 & 60,两台分发器80 & 90,测试机10
先搭建好lvs-dr 模式集群( https://blog.youkuaiyun.com/weixin_42182501/article/details/85109723)
这里要注意的是80和90两台机子上不需要绑定虚拟IP,只需要安装keepalived,由keepalived来分配虚拟IP.
两台都装好keepalived,关闭firewalld和selinux.
[root@lvs90 ~]# yum -y install keepalived
在80上打开keepalived配置文件,将内容修改成如下:
[root@lvs80 ~]# vim /etc/keepalived/keepalived.conf
1 ! Configuration File for keepalived
2
3 global_defs {
4 notification_email {
5 acassen@firewall.loc
6 failover@firewall.loc
7 sysadmin@firewall.loc
8 }
9 notification_email_from Alexandre.Cassen@firewall.loc
10 smtp_server 192.168.200.1
11 smtp_connect_timeout 30
12 router_id LVS_DEVEL
13 }
14
15 vrrp_instance lvsha {
16 state MASTER
17 interface eth0
18 virtual_router_id 51
19 priority 150
20 advert_int 1
21 authentication {
22 auth_type PASS
23 auth_pass 1111
24 }
25 virtual_ipaddress {
26 192.168.4.200
27 }
28 }
29
30 virtual_server 192.168.4.200 80 {
31 delay_loop 6
32 lb_algo rr
33 lb_kind DR
34 nat_mask 255.255.255.0
35 #persistence_timeout 50
36 protocol TCP
37 connect_timeout 3
38 nb_get_retry 3
39 delay_before_retry 3
40 real_server 192.168.4.50 80 {
41 weight 1
42 }
43 real_server 192.168.4.60 80 {
44 weight 1
45 }
46 }
90上也要同样的配置,但是90的配置有点区别,因为90是作为备份的分发器。
区别在于
16行的描叙要改成
16 state BACKUP
19行的权重值要改成100
19 priority 100
接下来就是开启keepalived服务。
先启动80再启动90
[root@lvs80 ~]# systemctl start keepalived
[root@lvs90 ~]# systemctl start keepalived
[root@lvs80 ~]# ip addr show |grep 192.168.4.
inet 192.168.4.80/24 brd 192.168.4.255 scope global eth0
inet 192.168.4.200/32 scope global eth0
使用10测试
[root@pc10 ~]# elinks --dump http://192.168.4.200/test.html
web50
[root@pc10 ~]# elinks --dump http://192.168.4.200/test.html
web60
[root@pc10 ~]# elinks --dump http://192.168.4.200/test.html
web50
[root@pc10 ~]# elinks --dump http://192.168.4.200/test.html
web60
关掉80上的keepalived,虚拟IP就自动转到90上了,分发服务并不会中断.
[root@lvs80 ~]# systemctl stop keepalived.service
[root@lvs90 ~]# ip addr show |grep 192.168.4
inet 192.168.4.90/24 brd 192.168.4.255 scope global eth0
[root@pc10 ~]# elinks --dump http://192.168.4.200/test.html
web50
[root@pc10 ~]# elinks --dump http://192.168.4.200/test.html
web60
[root@pc10 ~]#