数据链路层负载均衡:lvs-dr
时间:2016-12-04 23:51 来源:潇湘夜雨 作者:华嵩阳 点击:次
DR工作模式的负载均衡 概述:DR方式的集群节点跟director必须在同一个物理网络中,中间没有其它路由设备; RIP可以使用私有地址,也可以使用公网地址,实现便捷的远程管理和监控; director仅负责处理入站请求,响应报文则由realserver直接发往客户端; realserver不能将网关指向DIP; 不支持端口映射; os支持VIP隐藏 1. 网络环境配置 CIP DIP RIP 的配置和常规IP配置一样,相互间能够互访即可。 拓扑图如下: 2. RS VIP服务器配置: 1>ARP配置(rip1、rip2): [root@localhost ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore [root@localhost ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore [root@localhost ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce [root@localhost ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce [root@localhost ~]# sysctl -p 永久生效配置: 在配置文件中设置参数: [root@localhost ~]# vim /etc/sysctl.conf net.ipv4.conf.lo.arp_ignore = 1 net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.lo.arp_announce = 2 net.ipv4.conf.all.arp_announce = 2 [root@localhost ~]# sysctl -p 通过以上配置,可以使得realserver的VIP不会被广播到其它主机,避免客户机访问时,不经过DIP直接访问到RIP,调度算法也就不能生效。 2>配置VIP [root@localhost ~]# ifconfig lo:0 172.18.109.237 broadcast 172.18.109.237 netmask 255.255.255.255 永久生效: [root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-lo:0 DEVICE=lo:0 IPADDR=172.18.109.237 NETMASK=255.255.255.255 BROADCAT=172.18.109.237 # If you're having problems with gated making 127.0.0.0/8 a martian, # you can change this to something else (255.255.255.255, for example) ONBOOT=yes NAME=loopback 3>路由添加 [root@localhost ~]# route add -host 172.18.109.237 dev lo:0 3.DR VIP 配置 1>VIP配置 [root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0:0 DEVICE=eth0:0 BOOTPROTO=none TYPE=Ethernet HWADDR=00:0c:29:d8:bf:40 IPV6INIT=no ONBOOT=yes USERCTL=no IPADDR=172.18.109.237 NETMASK=255.255.255.255 BROADCAT=172.18.109.237 2>路由添加 [root@localhost ~]# route add -host 172.18.109.237 dev eth0:0 1. DR服务和算法配置 先要安装ipvsadm模块:yum install ipvsadm -y [root@localhost ~]# ipvsadm -A -t 172.18.109.237:80 -s wlc [root@localhost ~]# ipvsadm -a -t 172.18.109.237:80 -r 172.18.109.235 -g -w 3 [root@localhost ~]# ipvsadm -a -t 172.18.109.237:80 -r 172.18.109.233 -g -w 1 [root@localhost ~]# ipvsadm -L -n IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 172.18.109.237:80 wlc -> 172.18.109.233:80 Route 1 0 0 -> 172.18.109.235:80 Route 3 0 0 [root@localhost ~]#service ipvsadm save #保存规则 chkconfig ipvsadm on #开机启动lvs服务 注意:-g参数表示dr模式,一定要和m参数的nat模式区分开,否则会出现架构和模式不匹配的错误。 5.测试 http://172.18.109.237/ (责任编辑:liangzh) |