LVS 负载均衡——直接路由模式DR

一、配置的网络拓扑结构图
在这里插入图片描述

二、配置lvs服务器

  • 配置虚拟网卡地址(VIP地址)
[root@localhost ~]# ifconfig eno16777728:0 192.168.200.253 netmask 255.255.255.0
#查看配置结果
[root@localhost ~]# ifconfig eno16777728:0 
eno16777728:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.200.253  netmask 255.255.255.0  broadcast 192.168.200.255
        ether 00:0c:29:f0:42:97  txqueuelen 1000  (Ethernet)
  • 安装ipvsadm软件包实现lvs轮询
[root@localhost ~]# yum -y install ipvsadm
#查看安装结果
[root@localhost ~]# rpm -qa ipvsadm
ipvsadm-1.27-7.el7.x86_64
  • 配置轮询规则
[root@localhost ~]#  ipvsadm -A -t 192.168.200.253:80 -s rr
[root@localhost ~]#  ipvsadm -a -t  192.168.200.254:80 -r 192.168.200.112:80 -g -w 1
[root@localhost ~]#  ipvsadm -a -t  192.168.200.253:80 -r 192.168.200.113:80 -g -w 1

三、配置Apache节点服务器(两台服务器配置相同)

  • 配置虚拟网卡IP地址(VIP地址)
[root@localhost ~]# ifconfig lo:0  192.168.200.253 netmask 255.255.255.255 
  • 添加路由规则
[root@localhost ~]# route add -host 192.168.200.253 dev lo:0
#将访问VIP的数据限制在本地以避免通信紊乱。
  • 调整/proc响应参数
[root@localhost ~]# vim /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore=1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
#启用参数
[root@localhost ~]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
  • 安装Apache开启服务
[root@localhost ~]# yum -y install httpd
#开启httpd服务
[root@localhost ~]# systemctl start httpd

四、测试

  • 所有机器关闭防火墙,安全规则
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# iptables -F
  • 准备测试页
[root@localhost ~]# echo "111111111" > /var/www/html/index.html
  • 测试
    在这里插入图片描述
posted @ 2019-10-08 13:55  会飞的fish  阅读(375)  评论(0编辑  收藏  举报