负载均衡群集LVS-DR 与 LVS-NAT

负载均衡群集之LVS-DR

调度服务器:
一块网卡:
Vmnet1:192.168.80.100
-------------------------加载LVS内核模块----------------------
LVS现在已成为Linux内核的一部分,默认编译为ip_vs模块,必要时能够自动调用。以下操作可以手动加载ip_vs模块,并查看当前系统中ip_vs模块的版本信息
[root@lss ~]# cat /proc/net/ip_vs
cat: /proc/net/ip_vs: 没有那个文件或目录
[root@lss ~]# modprobe ip_vs //加载ip_vs模块,
[root@lss ~]# cat /proc/net/ip_vs //查看ip_vs版本信息
[root@lss ~]# rpm -ivh /mnt/Packages/ipvsadm-1.27-7.el7.x86_64.rpm //安装管理软件,不需要启动

---------------------DR模式调度器配置------(调度器与各服务器在同个网段内)-------------
------------------注意:80.188是调度器和各真实服务器要共同虚拟出的一个地址---------------
[root@lss ~]# vi dr.sh
#!/bin/bash
#
ifconfig ens33:0 192.168.80.188 broadcast 192.168.80.188 netmask 255.255.255.255 up
route add -host 192.168.80.188 dev ens33:0
ipvsadm -C
ipvsadm -A -t 192.168.80.188:80 -s rr
ipvsadm -a -t 192.168.80.188:80 -r 192.168.80.101:80 -g
ipvsadm -a -t 192.168.80.188:80 -r 192.168.80.102:80 -g
ipvsadm –Ln
[root@lss ~]# sh dr.sh
[root@lss ~]# ifconfig

192.168.80.101服务器:
Vmnet1内网:192.168.80.101
[root@lss01 ~]# yum install -y httpd
[root@lss01 ~]# vi /etc/httpd/conf/httpd.conf
ServerName www.aa.com
[root@lss01 ~]# vi /var/www/html/index.html
<h1>Server aa </h1>
[root@lss01 ~]# service httpd restart
------DR模式,各真实服务器配置---虚拟地址是相同的---
[root@lss01 ~]# vi web.sh
#!/bin/bash
#haha
ifconfig lo:0 192.168.80.188 broadcast 192.168.80.188 netmask 255.255.255.255 up
route add -host 192.168.80.188 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
sysctl -p &>/dev/null
[root@lss01 ~]# sh web.sh
[root@lss01 ~]# ifconfig

负载均衡群集LVS-DR 与 LVS-NAT

192.168.80.102服务器:
Vmnet1内网:192.168.80.102
[root@lss02 ~]# yum install -y httpd
[root@lss02 ~]# vi /etc/httpd/conf/httpd.conf
ServerName www.bb.com
[root@lss02 ~]# vi /var/www/html/index.html
<h1>Server bb </h1>
[root@lss02 ~]# service httpd restart
------DR模式,各真实服务器配置---虚拟地址是相同的---
[root@lss02 ~]# vi web.sh
#!/bin/bash
#haha
ifconfig lo:0 192.168.80.188 broadcast 192.168.80.188 netmask 255.255.255.255 up
route add -host 192.168.80.188 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
sysctl -p &>/dev/null
[root@lss02 ~]# sh web.sh

负载均衡群集LVS-DR 与 LVS-NAT

真机浏览器测试:
Vmnet1:192.168.80.88
浏览器输入:http://192.168.80.188/会轮流出现192.168.80.101和192.168.80.102的页面

负载均衡群集LVS-DR 与 LVS-NAT

 

负载均衡群集之LVS-NAT

调度服务器:
两块网卡:
Vmnet1内网:192.168.80.100
Vmnet2外网:192.168.90.100(调度器的地址是外网口地址)
-------------------------加载LVS内核模块----------------------
LVS现在已成为Linux内核的一部分,默认编译为ip_vs模块,必要时能够自动调用。以下操作可以手动加载ip_vs模块,并查看当前系统中ip_vs模块的版本信息
[root@lss ~]# cat /proc/net/ip_vs
cat: /proc/net/ip_vs: 没有那个文件或目录
[root@lss ~]# modprobe ip_vs //加载ip_vs模块,
[root@lss ~]# cat /proc/net/ip_vs //查看ip_vs版本信息
[root@lss ~]# rpm -ivh /mnt/Packages/ipvsadm-1.27-7.el7.x86_64.rpm //安装管理软件,不需要启动

[root@lss ~]# vi nat.sh
#!/bin/bash
echo "1" > /proc/sys/net/ipv4/ip_forward
ipvsadm -C
ipvsadm -A -t 192.168.90.100:80 -s rr
ipvsadm -a -t 192.168.90.100:80 -r 192.168.80.102:80 -m
ipvsadm -a -t 192.168.90.100:80 -r 192.168.80.101:80 -m
ipvsadm -Ln
[root@lss ~]# sh nat.sh

192.168.80.101服务器:
Vmnet1内网:192.168.80.101
网关:192.168.80.100
[root@lss01 ~]# yum install -y httpd
[root@lss01 ~]# vi /etc/httpd/conf/httpd.conf
ServerName www.aa.com
[root@lss01 ~]# vi /var/www/html/index.html
<h1>Server aa </h1>
[root@lss01 ~]# service httpd restart
[root@lss01 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
GATEWAY=192.168.80.100
[root@lss01 ~]# service network restart

192.168.80.102服务器:
Vmnet1内网:192.168.80.102
网关:192.168.80.100

[root@lss02 ~]# yum install -y httpd
[root@lss02 ~]# vi /etc/httpd/conf/httpd.conf
ServerName www.bb.com
[root@lss02 ~]# vi /var/www/html/index.html
<h1>Server bb </h1>
[root@lss02 ~]# service httpd restart
[root@lss02 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
GATEWAY=192.168.80.100
[root@lss02 ~]# service network restart

真机浏览器测试:
Vmnet1:192.168.80.88
Vmnet2:192.168.90.88

负载均衡群集LVS-DR 与 LVS-NAT

相关推荐