Linux Network Load Balance

简介:

在现行的许多Web应用中,有时一台服务器往往不能满足大量客户端的访问要求,此时只能通过增加服务器来解决问题。使用一些负载均衡软件可以实现网络负载平衡群集来解决问题。本文将介绍Linux下的实现方法。 

    This test used Redhat Enterprise 5.0 update3.

    Network link environment:

    PC1(virtual server):
      double NIC, eth0 IP1=192.168.0.254, eth1 IP2=10.0.0.254
      eth0 acts as outside address, the Virtual IP Address.
      eth1 acts as inside address, makes a lan with PC1 and PC2.
    PC2(also named real server):
      single NIC, eth0 IP1=10.0.0.1
    PC3(also named real server as PC2):
      single NIC, eth0 IP1=10.0.0.3

    Soft:
    ipvsadm software package,download url:http://www.linuxvirtualserver.org
    ‘ipvs’ means IP Virtual Server.

    Installing virtual server, at PC1:

    1,create a soft link to /usr/src/kernels/2.6.18-53.el5-i686 directory。
      Run command: ln -s /usr/src/kernels/2.6.18-128.el5-i686 /usr/src/linux
      Comment: /usr/src/linux is used by compiler. ‘linux’ directs to the Linux kernel directory.
      Compiler search some lib in kernel directory along the linux path.

    2,install ipvsadm software:
      tar -zxvf ipvsadm-1.24
      cd ipvsadm-1.24
      make all
      make install

      OK! To see version infomation, run command: ipvsadm –version
      The following info will got:
      pvsadm v1.24 2005/12/10 (compiled with popt and IPVS v1.2.1)

    3,configure:
      run below commands:
      echo “1″>/proc/sys/net/ipv4/ip_forward   //start IP forward function. MUST!
      ipvsadm -C   //clear ipvsadm table
      ipvsadm -A -t 192.168.0.254:80 -s rr   //install LVS service
      ipvsadm -a -t 192.168.0.254:80 -r 10.0.0.1:80 -m -w 1    //add the 1st server
      ipvsadm -a -t 192.168.0.254:80 -r 10.0.0.3:80 -m -w 1    //add the 2nd server
      (NOTE: it’s 1 after -w, NOT l)

      Then:
      Configure the IP property of PC2 and PC3, set the default gateway to 10.0.0.254, the inside port of virtual server.
      Start up the web server of PC2 and PC3.

      In fact, we can also add a rule:
      ipvsadm -a -t 192.168.0.254:80 -r 10.0.0.254:80 -m -w 1

      then the virtual serevr also acts as a real server.

    Test:
      Visit the url http://192.168.0.254 at another pc in the lan with vitual server. we can get the page of PC2 OR PC3 (or PC1).
      Virtual server roundly gets the content from PC2 OR PC3 and gives us, but we consider the info is from PC1.
      Then, the Network Load Balance(NLB) is realized.

      the following is the test result(10.0.0.254 also work):

      [root@localhost ~]# ipvsadm
      IP Virtual Server version 1.2.1 (size=4096)
      Prot LocalAddress:Port Scheduler Flags
        -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
      TCP  192.168.0.254:http rr
        -> 10.0.0.254:http              Local   1      0          28
        -> 10.0.0.3:http                Masq    1      0          28
        -> 10.0.0.1:http                Masq    1      0          28









本文转自网眼51CTO博客,原文链接:http://blog.51cto.com/itwatch/286434,如需转载请自行联系原作者

相关实践学习
部署高可用架构
本场景主要介绍如何使用云服务器ECS、负载均衡SLB、云数据库RDS和数据传输服务产品来部署多可用区高可用架构。
负载均衡入门与产品使用指南
负载均衡(Server Load Balancer)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
相关文章
|
20天前
|
监控 Unix Linux
Linux操作系统调优相关工具(四)查看Network运行状态 和系统整体运行状态
Linux操作系统调优相关工具(四)查看Network运行状态 和系统整体运行状态
39 0
|
20天前
|
存储 监控 网络协议
【Linux】文件服务NFS(Network File System)
【Linux】文件服务NFS(Network File System)
126 0
|
11月前
|
Linux 调度
Linux系统Load Average解析
很多小伙伴在遇到某一接口服务性能问题时,比如说,TPS上不去、响应时间拉长、应用系统出现卡顿,某一请求出现超时等等现象,往往显得苍白无力,无从下手。 针对系统负载性能,很大一部分人潜意识会认为CPU使用率等同系统负载,或者直接反应系统负载情况,这种理解对吗?本文将从2个纬度合理进行分析系统负载以及CPU与Load Average之间的关联。
91 0
|
11月前
|
安全 Ubuntu Linux
嵌入式Linux开发环境搭建之十一 --- Putty连接虚拟机Centos出现:Network error:Connection refused的解决方法
嵌入式Linux开发环境搭建之十一 --- Putty连接虚拟机Centos出现:Network error:Connection refused的解决方法
330 0
|
11月前
|
Linux
linux虚拟机network服务显示active(exited)
linux虚拟机network服务显示active(exited)
1140 0
|
12月前
|
Linux Shell
【Linux网络配置实战】服务器Network静态路由配置
【Linux网络配置实战】服务器Network静态路由配置
394 1
|
Linux
Linux重新启动后提示 Failed to load SELinux policy. Freezing系统hung住
重新启动之前修改了selinux的配置,disable selinux,估计多半是修改的时候哪里改错了。
142 0
|
弹性计算 算法 Java
一文说清linux system load averages
深入浅出阐释linux system load averages的语义,算法和计算流程,并分享了实际load飙高问题的排查经验和心得。
一文说清linux system load averages
|
Linux
Linux操作系统下proj4库编译与安装及ERROR 6: Unable to load PROJ.4 library (libproj.so)问题解决
Linux操作系统下proj4库编译与安装及ERROR 6: Unable to load PROJ.4 library (libproj.so)问题解决
759 0
|
Linux
Linux系统之Network静态路由配置
Linux系统之Network静态路由配置
341 0
Linux系统之Network静态路由配置