一、部署keepalived

keealived并不通过ipvsadm来管理lvs,而是自身通过配置文件直接管理lvs;
keepalived三个功能:管理lvs、高可用、节点健康检查

1.安装keepalived[lb03,lb04]

1
yum -y install keepalived

2.全局配置

3.VIP配置

4.lvs的配置[两台一样]

5.启动keepalived并检查

1
2
systemctl start keepalived.service
systemctl status keepalived.service

二、web服务器操作和检查

lo绑定vip

1
ip addr add 10.0.0.13/32 dev lo

修改内核参数

1
2
3
4
5
6
7
cat >>/etc/sysctl.conf<<EOF
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
EOF
sysctl -p

以上完成即可开始测试并验证了

三、keepalived详细配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
[root@xxx ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL-1
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.3/24 dev eth0 label eth0:1
}
}
#ipvsadm -A -t 10.0.0.3:80 -s wrr
virtual_server 10.0.0.3 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
#ipvsadm -a -t 10.0.0.3:80 -r 10.0.0.7:80 -g -w 1
real_server 10.0.0.7 80 {
weight 1
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
#ipvsadm -a -t 10.0.0.3:80 -r 10.0.0.8:80 -g -w 1
real_server 10.0.0.8 80 {
weight 1
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}

从注释掉的ipvsadm ...开始为在原配置上增加的内容
两个LB服务器,要注意修改router_id,state(主备)priority(优先级)

可以一次性配置多个VIP,virtual_server,然后再给每个virtual_server指定多个real_server