标签:lvs的dr模式实现
功能实现:
实验环境为:前端lvs4层负载均衡做流量转发,后端web server为2台nginx。
LVS: 10.10.101.224
VIP: 10.10.101.240
RIP1: 10.10.101.225
RIP2: 10.10.101.226
禁用防火墙和selinux
systemctl disable firewalld
systemctl stop firewalld
setenforce 0
nginx服务器搭建
1.1安装编译系统环境
yum install c gcc gcc-c++
1.2 编译安装PCRE&ZLIB
1.3 编译安装nginx
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-pcre=/usr/local/pcre-8.40 --with-zlib=/usr/local/zlib-1.2.11
1.4 为检查实验效果,index.html内容替换为IP地址。
2. 配置director
2.1 10.10.101.224上安装ipvsadm
yum install -y ipvsadmin*
2.2 配置VIP
ifconfig eth0:0 10.10.101.240 netmask 255.255.255.255
route add -host 10.10.101.240 dev eth0:0
2.3 配置LVS
ipvsadm -C
ipvsadm -At 10.10.101.240:80 -s rr
ipvsadm -at 10.10.101.240:80 -r 10.10.101.225:80 -g
ipvsadm -at 10.10.101.240:80 -r 10.10.101.226:80 -g
ipvsadm -L -n
2.4 查看LVS
ipvsadmin
[root@localhost ~]# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.10.101.240:http rr
-> 10.10.101.225:http Route 1 0 0
-> 10.10.101.226:http Route 1 0 0
3 Real server 配置
ifconfig lo:0 10.10.101.240 netmask 255.255.255.255 broadcast 10.10.101.240
route add -host 10.10.101.240 dev lo:0
echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
4 验证
标签:lvs的dr模式实现
原文地址:http://zhengqizhq.blog.51cto.com/690602/1911136