lvs_nat 配置_落英缤纷(原创)
LVS-NAT配置(原创)LVS,即Linux Virtual Server,是一款由章文嵩博士开发的开源软件,可以实现Linux 下面的负载均衡。LVS 各个组成部分为:Director Server,Real Server,shared Storage.
目前我使用的是平台为:WIN7 + VMWARE 9.0, DirectorServer,Real Server 均使用虚拟机中的Linux,具体为CentOS 6.3, 详细配置如下:
Windows7 :
ip:192.168.2.102
netmask:255.255.255.0
gateway:192.168.2.1
Director Server:
ip:192.168.12.10 (这个ip在内网使用,所以可以不用配置子网掩码和网关)
vip:192.168.2.111 #虚拟IP
netmask:255.255.255.0
gateway:192.168.2.1
Real Server 1:
ip:192.168.12.3
netmask:255.255.255.0
gateway:192.168.12.10#注意这里要指向Director Server
vip:192.168.2.111
Real Server 2:
ip:192.168.12.4
netmask:255.255.255.0
gateway:192.168.12.10#注意这里要指向Director Server
vip:192.168.2.111
下面是各服务器配置步骤:
1,配置Director Server(关闭防火墙)
首先这台服务器工作在NAT 模式,所以需要两张网卡,我们在虚拟机中可以再增加一个。我们可以把虚拟机中默认的第一个网卡设置为自定义,选择vmnet2。第二张网卡(也就是我们刚刚增加的一张网卡)配置为NAT 模式。
进入CentOS,
#vi/etc/sysctl.conf
修改里面其中一行net.ipv4.ip_forward = 0 改为net.ipv4.ip_forward = 1
这样ip转发就开启了。可以通过命令sysctl -p查看。
#cd /etc/sysconfig/network-scripts
#vi ifcfg-Auto_eth1
这里将IP 设置为192.168.2.111,子网掩码为255.255.255.0,网关为192.168.2.1
#vi ifcfg-Auto_eth2
这里将IP设置为192.168.12.10
#vi /etc/resolv.conf 这里加上DNS:202.103.24.68,202.103.44.150
#service network restart
因为我们的物理机Windows7 已经通过有线联网,这里我们可以
ping www.163.com
发现Director Server已经可以联网了。
#yum –y install ipvsadm //安装ipvsadm
#yum –erase httpd //如果此机安装有apache,移除该软件。
查看ipvs 系统内核是否支持
#grep –I ip_vs /boot/config-2.6.32-279.el6.i686
#lsmod |grep ip_vs
2,配置Real Server1
#vi /etc/sysctl.conf
在net.ipv4.ip_forward = 0后面再增加两行:
net.ipv4.conf.all.hidden= 1
net.ipv4.conf.lo.hidden= 1
增加虚拟IP:
#cd /etc/sysconfig/network-scripts
#cp ifcfg-lo ifcfg-lo:0
#vi ifcgf-lo:0
按照以下来修改:
DEVICE=lo:0
IPADDR=192.168.2.111
NETMASK=255.255.255.255
ONBOOT=YES
…
#vi /etc/sysconfig/networscripts/ifg-eth0
设置IP为:192.168.12.3 netmask:255.255.255.0gateway:192.168.12.10
#yum –y install httpd //安装apache web服务器
#vi /var/www/html/index.html //建立web首页
写入:This is Server 1
#service httpd restart //重启下web
查看网页是否正常打开:#firefox:http://localhost/
配置Real Server2
#vi /etc/sysctl.conf
在net.ipv4.ip_forward = 0后面再增加两行:
net.ipv4.conf.all.hidden= 1
net.ipv4.conf.lo.hidden= 1
增加虚拟IP:
#cd /etc/sysconfig/network-scripts
# cp ifcfg-lo ifcfg-lo:0
#vi ifcgf-lo:0
按照以下来修改:
DEVICE=lo:0
IPADDR=192.168.2.111
NETMASK=255.255.255.255
ONBOOT=YES
…
#vi /etc/sysconfig/networscripts/ifg-eth0
设置IP为:192.168.12.4 netmask:255.255.255.0gateway:192.168.12.10
#yum –y install httpd //安装apache web服务器
#vi /var/www/html/index.html //建立web首页
写入:This is Server 2
#service httpd restart //重启下web
查看网页是否正常打开:# firefox http://localhost/
3,在Director Server 上面配置ipvsadm
先分别
ping 192.168.12.10
ping 192.168.2.111
ping 192.168.12.3
ping 192.168.12.4
发现均能ping通
#ipvsadm –A –t 192.168.2.111 –s rr //rr为轮询调度
#ipvsadm –a –t 192.168.2.111 –r 192.168.12.13 –m–w 1
#ipvsadm –a –t 192.168.2.111 –r 192.168.12.14 –m –w 2
#service ipvsadm save //保存ipvsadm
查看ipvsadm :
#ipvsadm –L –n
可以看到已经有RealServer的信息了。
在WIN 7 上打开浏览器,访问:http://192.168.2.111
修改调度算法为wlc:
#ipvsadm –E –t 192.168.2.111 –s wlc
#service ipvsadm save
在WIN 7 上打开浏览器,访问:http://192.168.2.111
现在刷新第一次为This is Server 1,刷新第二次第三次均为This is Server 2 了。
页:
[1]