如何架设LVS集群服务器

    LVS,即linux virtual server, 就是Linux环境下架设集群服务器的一种实现方式,目的是通过多个服务器一起提供高性能的服务。很适合大型网站的接入。 

    LVS可以通过3种方式搭建:分别为NAT,IP tunneling,和Direct routing. 其中NAT方式性能较差,其它两种都差不多。详情见官方网站:http://www.linuxvirtualserver.org

 

下面以IP tunneling具体实例,来介绍如果搭建LVS.

1. Installation:

   Install  ipvs module at Load Balancer,  the following modules must be installed at least:
/root/modules/ipvs # lsmod
Module                  Size  Used by    Tainted: G 
ip_vs_ftp               7560  0
ip_vs_rr                2560  1
ip_vs                  85184  5 ip_vs_ftp,ip_vs_rr

 

   and then install configuration tool "ipvsadm".

 

2. configuration:
Definition:
Load Balancer: 192.168.1.249
real server1: 192.168.1.252
real server2: 192.168.1.253
virtual address: 192.168.1.110

   In my example, I setup a virtual server 192.168.1.110:3000.

    1).For load banlancer:
ifconfig eth0:0 192.168.1.110 netmask 255.255.255.255 broadcast 192.168.1.110 up
route add -host 192.168.1.110 dev eth0:0

ipvsadm -A -t 192.168.1.110:3000 -s rr
ipvsadm -a -t 192.168.1.110:3000 -r 192.168.1.252 -i -w 1
ipvsadm -a -t 192.168.1.110:3000 -r 192.168.1.253 -i -w 1

    2). For real server #1 and #2:
#install ip tunnel module
modprobe ipip
#setup ip tunnel address
ifconfig tunl0 192.168.1.110 netmask 255.255.255.255 broadcast 192.168.1.110 up
route add -host 192.168.1.110 dev tunl0

#disable arp reply
echo 8 > /proc/sys/net/ipv4/conf/tunl0/arp_ignore

3. Setup service in real server side.
For my example, http is running at the real server #1 and #2, port 3000.


How does it works?
    When issue a http request to load balancer 192.168.1.110:3000, the load balancer will
select a workable server, and use ipip to encapsulate and send the ipip packet to the realserver.
    The realserver ipip module will decode the ipip packet, and issue the encapsulated data to
network layer. The network layer will deliver the packet to the httpd, because it's listening on the
port 3000.
    From httpd side view, the packet is come from client machine directly!
So httpd processes and send the packet to client. And then the client get data.

你可能感兴趣的:(linux,集群,server,Module,服务器,NetWork)