在lvs高负载中,LB节点(也就是常说的DR)会存在单点问题;这里使用了keepalived来解决单点问题;实现冗余;
看图操作;
LB1:eth0:192.168.182.133 (vip:eth0:0 192.168.182.200)
LB2: eth0:192.168.182.138 (vip: eth0:0 192.168.182.200)
rs1: eth0:192.168.182.130 (vip: lo:0 192.168.182.200)
rs2: eth0:192.168.182.129 (vip: lo:0 192.168.182.200)
lvs模型为DR;
首先在两台rs1、rs2上进行操作;
1
2
3
4
5
6
7
8
9
10
11
|
echo
2
> /proc/sys/net/ipv4/conf/all/arp_announce
echo
2
> /proc/sys/net/ipv4/conf/eth0/arp_announce
echo
1
> /proc/sys/net/ipv4/conf/all/arp_ignore
echo
1
> /proc/sys/net/ipv4/conf/eth0/arp_ignore
service network restart
ifconfig lo:
0
192.168
.
182.200
netmask
255.255
.
255.255
broadcast
182.168
.
182.200
route add -host
192.168
.
182.200
dev lo:
0
yum install httpd -y
echo web1 > /
var
/www/html/index.html #rs1标识web1
echo web2 > /
var
/www/html/index.html #rs2标识web2
service httpd start
|
LB1、LB2上进行操作;
1
|
yum install ipvsadm keepalived httpd -y
|
LB1的上的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
49
50
51
|
! Configuration File
for
keepalived
global_defs {
notification_email {
coffee_lanshan@sina.com
}
notification_email_from root@localhost
smtp_server
127.0
.
0.1
smtp_connect_timeout
30
router_id LVS_1
}
vrrp_instance VI_1 {
state MASTER #LB2为BACKUP
interface
eth0
virtual_router_id
51
priority
101
#LB2为
100
advert_int
1
authentication {
auth_type PASS
auth_pass lansgg
}
virtual_ipaddress {
192.168
.
182.200
}
}
virtual_server
192.168
.
182.200
80
{
delay_loop
6
lb_algo wrr
lb_kind DR
nat_mask
255.255
.
255.0
persistence_timeout
50
protocol TCP
real_server
192.168
.
182.130
80
{
weight
2
TCP_CHECK {
connect_timeout
3
nb_get_retry
3
delay_before_retry
1
connect_port
80
}
}
sorry_server
127.0
.
0.1
80
real_server
192.168
.
182.129
80
{
weight
2
TCP_CHECK {
connect_timeout
3
nb_get_retry
3
delay_before_retry
1
connect_port
80
}
}
}
|
LB1:
1
|
echo error:
192.168
.
182.133
> /
var
/www/html/index.html #此步为了测试错误展示页面
|
LB2:
1
|
echo error:
192.168
.
182.138
> /
var
/www/html/index.html
|
LB1、LB2分别启动keepalived、httpd、ipvsadm
在LB1查看发现如下:
发现vip和ipvs规则已经添加;
下面进行测试;
我们停掉rs1的httpd服务
你会发现LB1的ipvs规则变化;并且进行页面测试;
现在你可以停掉LB1上的keepalived,vip会自动漂移到LB2上;服务及相关规则不受影响;
1
|
[root@LB1 ~]# /etc/init.d/keepalived stop
|
你发现vip由优先级为100的顶替了,也就是LB2
而我们的业务没有受到影响:
然后进行测试当停掉2台rs,看看vip显示的页面;
上图就相当于我们网站的错误提示页面;
转载于:https://blog.51cto.com/3711573/1240490