实现目标:
- 一台LVS通过DR模式将请求负载均衡到两台http服务上
- 两台Keepalived实现LVS的HA
1 一台LVS实现负载均衡
需要三台虚拟机:node01 和 node02 作为web server, node03 作为流量入口,分发到web server 上
# node01 ip: 10.0.0.6
# node02 ip: 10.0.0.7
systemctl firewall stop
yum install httpd -y
echo "<h1>form node01</h1>" > /var/www/html/index.html
echo 1 > /proc/sys/net/ipv4/conf/ens33/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/ens33/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
ifconfig lo:1 10.0.0.200/32
service httpd start
curl 10.0.0.200
# node03 ip: 10.0.0.5
systemctl firewall stop
ifconfig ens33:1 10.0.0.200/24
yum install ipvsadm -y
ipvsadm -A -t 10.0.0.200:80 -s rr
ipvsadm -a -t 10.0.0.200:80 -r 10.0.0.6:80 -g -w 1
ipvsadm -a -t 10.0.0.200:80 -r 10.0.0.7:80 -g -w 1
ipvsadm -ln
curl 10.0.0.200
ipvsadm -lnc
2 Keepalived实现LVS的HA
需要四台虚拟机:node01 和 node02 作为web server, node03 和 node04 作为LVS的主和备实现HA
# node01 ip: 10.0.0.6 同上
# node02 ip: 10.0.0.7 同上
# node03 ip: 10.0.0.4
# node03 ip: 10.0.0.5
systemctl firewall stop
yum install keepalived ipvsadm -y
# edit keepalived.conf
vim keepalived.conf
service keepalived start
- keepalived.conf 配置
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.200/24 dev ens33 label ens33:1
}
}
virtual_server 10.0.0.200 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 0
protocol TCP
real_server 10.0.0.6 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 10.0.0.7 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}