基础环境准备:
proxy1 eth0:192.168.4.5
proxy2 eth0:192.168.4.6
web1 eth0:192.168.4.100
web2 eth0:192.168.4.200
client eth0:192.168.4.10
VIP 192.168.4.15
所有主机禁用防火墙和selinux
systemctl disable firewalld
sed -i ‘/SELINUX/s/enforcing/disabled/’ /etc/selinux/config
proxy1主机配置:
yum -y install ipvsadm keepalived
vim /etc/keepalived/keepalived.conf
router_id LVS_1
#12行修改
vrrp_iptables
#13行添加
192.168.4.15/24
#31行修改,多余的ip删除
virtual_server 192.168.4.15 80 {
#35行修改
lb_kind DR
#38行修改
#persistence_timeout 50
#39行注释掉
real_server 192.168.4.100 80 {
#42行修改
TCP_CHECK {
#44行修改
real_server 192.168.4.200 80 {
#50行修改
TCP_CHECK {
#52行修改
删除多余内容
proxy2主机配置:
yum -y install ipvsadm keepalived
vim /etc/keepalived/keepalived.conf
router_id LVS_1
#12行修改
vrrp_iptables
#13行添加
state BACKUP
#21行修改
priority 60
#24行修改
192.168.4.15/24
#31行修改,多余的ip删除
virtual_server 192.168.4.15 80 {
#35行修改
lb_kind DR
#38行修改
#persistence_timeout 50
#39行注释掉
real_server 192.168.4.100 80 {
#42行修改
TCP_CHECK {
#44行修改
real_server 192.168.4.200 80 {
#50行修改
TCP_CHECK {
#52行修改
删除多余内容
web1主机配置:
ifconfig lo:0 192.168.4.15 netmask 255.255.255.255
route add -host 192.168.4.15 dev lo:0
ip a s
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
yum -y install httpd
echo “web1” > /var/www/html/index.html
systemctl enable --now httpd
curl localhost
web2主机配置:
ifconfig lo:0 192.168.4.15 netmask 255.255.255.255
route add -host 192.168.4.15 dev lo:0
ip a s
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
yum -y install httpd
echo “web2” > /var/www/html/index.html
systemctl enable --now httpd
curl localhost
proxy1和proxy2同配置:
systemctl enable --now keepalived
ip a s
ipvsadm -Ln
client主机测试验证:
yum -y install elinks
while true; do elinks -dump http://192.168.4.15; sleep 3; done
此时可以看到web1和web2轮流输出显示
测试LVS高可用:
proxy1主机上执行systemctl stop keepalived
此时去client主机上观察网页依然不断输出显示
proxy2主机上执行ip a s可以看到VIP地址已自动切换到本机上,proxy1重新启用keepalived服务,VIP地址又切换到proxy1主机上了。
相关文章
- 01-30Docker 创建 PXC 高可用集群并配置 Harpoxy 负载均衡
- 01-30RHCS配置web高可用集群
- 01-3012.Dubbo高可用【Zokeeper宕机与dubbo直连,负载均衡】
- 01-30nginx和keeplive实现负载均衡高可用
- 01-30Hadoop(二)HA高可用集群安装与配置
- 01-30Flume-ng高可用集群负载安装与配置
- 01-30MHA高可用配置及故障切换
- 01-30Exchange 2010 SP2 高可用性配置Outlook Anywhere
- 01-30Dynamic crm 负载均衡配置(基于Always on 高可用) 第四篇:CRM环境搭建
- 01-30Dynamic crm 负载均衡配置(基于Always on 高可用) 第二篇:故障转移集群配置