LVS之VS/NAT搭建web集群实战!!!

项目背景

利用lvs的vs/NAT技术实现一个由负载调度器和两个web服务器组成的架构!



试验环境

vmware workstation 11

centos6.5的系统下

load balance:ip:192.168.0.32   vip:192.168.1.32   关闭iptables  setenforce0      

user:ip:192.168.1.39   关闭iptables  setenforce0      

real_server01:192.168.0.10  gw:192.168.0.32 关闭iptables  setenforce0  

real_server02:192.168.0.36  gw:192.168.0.36 关闭iptables  setenforce0  

SecureCRT (ssh远程连接软件)


架构图:



LVS之VS/NAT搭建web集群实战!!!_第1张图片




实验过程:

一、在load balance上面安装ipvsadm   

直接用yum安装

因为我已经安装成功了,所以显示已安装!

二、在load balance上面执行脚本

[root@Load_Balancer ~]# cat lvs.sh 

#!/bin/sh 


#set ip_forward ON for vs-nat director (1 on, 0 off). 

cat /proc/sys/net/ipv4/ip_forward 

echo "1" >/proc/sys/net/ipv4/ip_forward 


#director is gw for realservers 

#turn OFF icmp redirects (1 on, 0 off) 

echo "0" >/proc/sys/net/ipv4/conf/all/send_redirects 

cat /proc/sys/net/ipv4/conf/all/send_redirects 

echo "0" >/proc/sys/net/ipv4/conf/default/send_redirects 

cat /proc/sys/net/ipv4/conf/default/send_redirects 

echo "0" >/proc/sys/net/ipv4/conf/eth0/send_redirects 

cat /proc/sys/net/ipv4/conf/eth0/send_redirects 


#clear ipvsadm tables 

/sbin/ipvsadm -C 

#install LVS services with ipvsadm 

#add telnet to VIP with rr sheduling 

/sbin/ipvsadm -A -t 192.168.1.32:80 -s rr 

#first realserver 

/sbin/ipvsadm -a -t 192.168.1.32:80 -r 192.168.0.10:80 -m -w 1 

#second realserver 

#forward telnet to realserver 192.168.0.36 using LVS-NAT (-m), with weight=1 

/sbin/ipvsadm -a -t 192.168.1.32:80 -r 192.168.0.36:80 -m -w 1 

#list ipvsadm table 

/sbin/ipvsadm 

三、在real server01上面执行脚本

[root@real_server01 ~]# cat real_server01.sh 

#!/bin/sh 

#show routing table 

/bin/netstat -rn 


#set_realserver_ip_forwarding to OFF (1 on, 0 off). 

echo "0" >/proc/sys/net/ipv4/ip_forward 

cat /proc/sys/net/ipv4/ip_forward 

四、在real server02上执行脚本

[root@real_server02 ~]# cat real_server02.sh 

#!/bin/sh 

#show routing table 

/bin/netstat -rn 

#set_realserver_ip_forwarding to OFF (1 on, 0 off). 

echo "0" >/proc/sys/net/ipv4/ip_forward 

cat /proc/sys/net/ipv4/ip_forward 

五、测试,在user上打开浏览器输入vip 192.168.1.32

LVS之VS/NAT搭建web集群实战!!!_第2张图片

LVS之VS/NAT搭建web集群实战!!!_第3张图片

可以看到,我在user服务器上访问load balance上面的vip,可以访问到后端的web集群。



总结:VS/NAT技术是我们呢常用的构建lvs集群的技术,当然你可以在后端部署十几台或者几十台服务器。希望大家都有所得

你可能感兴趣的:(LVS,web集群,VS/NAT,负载调度器)