NAT模型
NAT模型:地址转换模型,主要是做地址转换,类似与iptables的DNAT类型,它通过多目标地址
转换,来实现负载均衡,一个Director最多负载提供10个real server 主机
1.LVS上面需要双网卡:DIP 和 VIP
2.内网的real server 主机的IP 必须和DIP 再同一个网络中,并且要求他的网关必须指向DIP的地址
3.RIP 都是私有IP地址,仅用于各个节点之间的通信
4.Director位于client和real server 之间 ,负责处理所有的进站出战通信
5.支持端口映射
6.通常应用再较大规模的应用场景中,但Director容易成为整个架构的瓶颈。
实验环境:
Server1(调度器):双网卡:eth0(对外):172.25.5.105 eth1(对内):172.25.5.1
Realserver:
Server2(服务器):172.25.5.2
Server3(服务器):172.25.5.3
Client:172.25.254.7
一、在server1中设置如下:
1.sever1作为vs (双网卡) ,sever2、sever3作为rs
Server1的第二块网卡,添加ip为172.25.254.103
在server1中:配置yum源
vim /etc/yum.repos.d/rhel-source.repo
[rhel6.5]
name=rhel6.5
baseurl=http://172.25.5.250/rhel6.5
gpgcheck=0
[HighAvailability]
name=HighAvailability
baseurl=http://172.25.5.250/rhel6.5/HighAvailability
gpgcheck=0
[LoadBalancer]
name=LoadBalancer
baseurl=http://172.25.5.250/rhel6.5/LoadBalancer
gpgcheck=0
[ScalableFileSystem]
name=ScalableFileSystem
baseurl=http://172.25.5.250/rhel6.5/ScalableFileSystem
gpgcheck=0
[ResilientStorage]
name=ResilientStorage
baseurl=http://172.25.5.250/rhel6.5/ResilientStorage
gpgcheck=0
2.yum install ipvsadm -y ###安装ipvsadm
/etc/init.d/ipvsadm start
打开内部路由设置:
vim /etc/sysctl.conf net.ipv4.ip_forward = 1 ##0=关闭 1=开启
sysctl -p
3.添加ipvsadm规则
[email protected]: ~]# ipvsadm -A -t 172.25.254.103:80 -s rr
[[email protected]: ~]# ipvsadm -a -t 172.25.254.103:80 -r 172.25.5.2:80 -m
[[email protected]: ~]# ipvsadm -a -t 172.25.254.103:80 -r 172.25.5.3:80 -m
[[email protected]: ~]# ipvsadm -L -n
二 、在server2中:
下载http服务 yum install httpd -y
[[email protected] ~]# cat /var/www/html/index.html
<h1>www.westos.org--server2</h1>
/etc/init.d/httpd restart
配置RS的网关指向vs
cat /etc/sysconfig/network-scripts/ifcfg-eth0
如果网关设置成功,ping 172.25.254.103测试
三、在server3中:
下载httpd服务
yum install httpd -y
[[email protected] ~]# cat /var/www/html/index.html
<h1>www.westos.org--server3</h1>
/etc/init.d/httpd restart
配置RS的网关指向vs
cat /etc/sysconfig/network-scripts/ifcfg-eth0
(和server2类似配置和测试)
测试:真机
Curl 172.25.254.103 出现轮询就好了