LVS topic: NAT and Dr Model for Web load Balancing
Objective:
in the previous article we talked about the basic concepts of LVS and the experimental principles and processes of the corresponding model, this article we mainly use lvs
provide load balancing for Web services
NAT implements the experimental topology
650) this.width=650; "src=" Http://www.178linux.com/ueditor/php/upload/image/20160405/1459866820924273.png "title= "1459866820924273.png" alt= "Blob.png" style= "height:auto;vertical-align:middle;border:0px;"/>
Experimental environment
Host |
IP Address |
function |
Director.anyisalin.com |
172.16.1.2,172.16.2.2 |
Lvs-director |
Rs1.anyisalin.com |
172.16.2.3 |
Real Server |
Rs2.anyisalin.com |
172.16.2.3 |
Real Server |
注意: 本文实验中所有主机SElinux和iptables都是关闭的
Experimental steps
Real Server Configuration
[[email protected] ~]# yum install httpd -y &> /dev/null && echo success | | echo failure #RS1安装httpdsuccess #安装成功 [[email protected] ~]# route add default gw 172.16.2.2 #设置默认网关为Director的DIP [[email protected] ~]# echo "Director ConfigurationIP地址配置的过程就不写了
[[email protected] ~]# curl 172.16.2.3 #可以访问RS1 Test650) this.width=650; "src=" Http://www.178linux.com/ueditor/php/upload/image/20160405/1459867232480476.gif "title= "1459867232480476.gif" style= "height:auto;vertical-align:middle;border:0px;" alt= "1459867232480476.gif"/>
Dr Implementation of the experimental topology650) this.width=650; "src=" Http://www.178linux.com/ueditor/php/upload/image/20160405/1459866843413812.png "title= "1459866843413812.png" alt= "Blob.png" style= "height:auto;vertical-align:middle;border:0px;"/>
Experimental environment
Host |
IP Address |
function |
director.anyisalin.com |
172.16.2.2,172.16.2.5 |
lvs-director |
rs1.anyisalin.com |
172.16.2.3,172.16.2.5 |
|
rs.anyisalin.com |
172.16.2.4,172.16.2.5 |
注意: 本文实验中所有主机SElinux和iptables都是关闭的
Experimental steps
Because the Lvs-nat mode is more complex, so the configuration is more troublesome, if the LVS-DR mode is not very understanding can see my previous blog
Director Configuration[[Email protected] ~]# ifconfig eth1:0 172.16. 2. 5/ broadcast 172.16. 2 . 5 up #配置VIP地址
[[Email protected] ~]# route Add-host 172.16. 2. 5 Dev eth1:0 #添加一条路由避免地址冲突
[[Email protected] ~]# ipvsadm-a-T 172.16. 2. 5:-S RR
[[Email protected] ~]# ipvsadm-a-T 172.16. 2. 5:-R 172.16. 2. 3 -G
[[Email protected] ~]# ipvsadm-a-T 172.16. 2. 5:-R 172.16. 2 . 4- G
Real Server Configuration# #修改内核参数, to be permanently active modify the configuration file
[[Email protected] ~]# echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore
[[Email protected] ~]# echo 1 >/proc/sys/net/ipv4/conf/eth0/arp_ignore
[[Email protected] ~]# echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce
[[Email protected] ~]# echo 2 >/proc/sys/net/ipv4/conf/eth0/arp_announce
[[Email protected] ~]# ifconfig lo:0 172.16. 2. 5/ broadcast 172.16. 2 . 5 up #配置VIP到lo:0
[[Email protected] ~]# route Add-host 172.16. 2. 5 Dev Lo:0
[[Email protected] ~]# yum Install httpd-y &>/dev/null && echo Success | | echo Failure #RS1安装httpd
Success#安装成功
[[Email protected] ~]# route Add default GW 172.16. 2. 2 #设置默认网关为Director的DIP
[[Email protected] ~]# echo " >/var/www/html/index.html #添加网页
[[Email protected] ~]# service httpd start &>/dev/null && echo Success #启动httpd服务
Success#启动成功
# #以下操作在rs2中执行
[[Email protected] ~]# echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore
[[Email protected] ~]# echo 1 >/proc/sys/net/ipv4/conf/eth0/arp_ignore
[[Email protected] ~]# echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce
[[Email protected] ~]# echo 2 >/proc/sys/net/ipv4/conf/eth0/arp_announce
[[Email protected] ~]# ifconfig lo:0 172.16. 2. 5/ broadcast 172.16. 2 . 5 up #配置VIP到lo:0
[[Email protected] ~]# route Add-host 172.16. 2. 5 Dev Lo:0
[[Email protected] ~]# yum Install httpd-y &>/dev/null && echo Success | | echo Failure #RS1安装httpd
Success#安装成功
[[Email protected] ~]# route Add default GW 172.16. 2. 2 #设置默认网关为Director的DIP
[[Email protected] ~]# echo " >/var/www/html/index.html #添加网页
[[Email protected] ~]# service httpd start &>/dev/null && echo Success #启动httpd服务
Success#启动成功
Test
650) this.width=650; "src=" Http://www.178linux.com/ueditor/php/upload/image/20160405/1459867232454992.gif "title= "1459867232454992.gif" style= "height:auto;vertical-align:middle;border:0px;" alt= "1459867232454992.gif"/>
Summarize:
This article describes how to use LVS to load balance multiple servers, but there are many cases are not described in this article, such as Tun, Fullnat, and so on, there will be a chance to share with you, after two days may write the use of Keepalive+lvs to achieve the high availability of director, Please expect
Anyisalin qq:1449472454
Thank you: mageedu
This article is from the "The Anyisalin blog" blog, please be sure to keep this source http://anyisalin.blog.51cto.com/10917514/1760752
LVS topic: NAT and Dr Model for Web load Balancing