`
haohappy2
  • 浏览: 315177 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

loadbalance apache3

 
阅读更多

Usually a single AMP system is enough to serve - let's say - around 500 concurrent users. Sometimes more, sometimes less, strongly depending on the particular web application, the overall architecture of your system, of course the hardware itself, and how you define "concurrent users".

Nevertheless, if your server gets too slow, you'll need to take actions. You may upgrade your server up to the maximum (aka vertical scaling), optimize your software (aka refactoring), and finally add more servers (aka horizontal scaling). The whole process of horizontal scaling is quite complex and far too much for a single blog post, but here's a first shot. Others will follow.

Today I'll focus on one single aspect of horizontal scaling: an HTTP load balancer.

loadbalancer1bsc.jpg

On the left: a whole crowd of people ready to visit our web site. On the right: our server farm (called workers). And in the middle: our current hero, the load balancer. The purpose of the load balancer (in this case an HTTP load balancer) is to distribute all incoming requests to our backend web servers. The load balancer hides all our backend servers to the public, and from the outside it looks like a single server doing all of the work.

The Recipe

Okay, let's start. Step by step.

  1. Since version 2.2 the Apache web server ships a load balancer module called mod_proxy_balancer. All you need to do is to enable this module and the modules mod_proxy and mod_proxy_http:

    LoadModule proxy_module mod_proxy.so
    LoadModule proxy_http_module mod_proxy_http.so
    LoadModule proxy_balancer_module mod_proxy_balancer.so

    Please don't forget to load mod_proxy_http, because you wouldn't get any error messages if it's not loaded. The balancer just won't work.

  2. Because mod_proxy makes Apache become an (open) proxy server, and open proxy servers are dangerous both to your network and to the Internet at large, I completely disable this feature:

    	ProxyRequests Off
    	<Proxy \*>
    		Order deny,allow
    		Deny from all
    	</Proxy>
    

    The load balancer doesn't need this feature at all.

  3. Now I need to make sure all my backend web servers have the same content:

    serverA htdocs% cat index.html
    This is A.
    serverB htdocs% cat index.html
    This is B.
    serverC htdocs% cat index.html
    This is C.
    serverD htdocs% cat index.html
    This is D.

    Okay, in this case the content differs, but I need this to show how the load balancer works.

  4. And here's the actual load balancer configuration:

    	<Proxy balancer://clusterABCD>
    		BalancerMember http://serverA
    		BalancerMember http://serverB
    		BalancerMember http://serverC
    		BalancerMember http://serverD
    		Order allow,deny
    		Allow from all
    	</Proxy>
    	ProxyPass / balancer://clusterABCD/
    

    The <Proxy>...</Proxy> container defines which backend servers belong to my balancer. I chose the name clusterABCD for this server group, but you are free to choose any name you want.

    And the ProxyPass directive instructs the Apache to forward all incoming requests to this group of backend servers.

  5. That's all? Yes, that's all. Here's the prove:

    # repeat 12 lynx -source http://loadbalancer
    This is A.
    This is B.
    This is C.
    This is D.
    This is A.
    This is B.
    This is C.
    This is D.
    This is A.
    This is B.
    This is C.
    This is D.

    Each request to the load balancer is forwarded to one of the backend servers. By default Apache simply counts the number of requests and makes sure every backend server gets the same amount of requests forwarded.

    If you want to know more about available balancing algorithms please refer to Apache's mod_proxy_balancer manual.

Did you ever imagine setting up a load balancer would be this easy? Of course, there is more to say about (HTTP) load balancing and much more about vertical scaling too, but this is only a blog posting and not a place for such an expansive reference. If time and space allows I'll go into further details on this in the near future.

分享到:
评论

相关推荐

    apache+tomcat 负载平衡

    web负载平衡 用于解决读取文件速度慢得问题 apache+tomcat 负载平衡

    Apache安装及jboss部署说明文档

    本文档描述了apache web服务器安装以及常用的编译模式;描述了apache+jboss3.2.6做负载均衡(load balance)的部署细节以及一些常见错误说明;描述了部署jboss3.2.3/3.2.6时一些心得、常用配置项。

    Apache+Tomcat负载平衡设置方法详细解析

    每个Tomcat worker是一个服务于web server、等待执行servlet的Tomcat实例。例如我们经常使用像Apache之...本文详细介绍了如何配置各种类型worker和loadbalance,并说明了各种类型worker的特性和loadbalance配置的原理。

    Apache安装及JBOSS部署说明文档.rar

    描述了apache jboss3.2.6做负载均衡(load balance)的部署细节以及一些常见错误说明;描述了部署jboss3.2.3/3.2.6时一些心得、常用配置项。 目 录 1 .Apache2.0及连接器jk1.2的编译部署 4 1.1下载相关软件包 ...

    apache安装过程

    本文档描述了apache web服务器安装以及常用的编译模式;描述了apache+jboss3.2.6做负载均衡(load balance)的部署细节以及一些常见错误说明;描述了部署jboss3.2.3/3.2.6时一些心得、常用配置项。

    thrift-zookeeper-rpc

    3.关于Failover/LoadBalance,由于zookeeper的watcher,当服务端不可用是及时通知客户端,并移除不可用的服务节点,而LoadBalance有很多算法,这里我们采用随机加权方式,也是常有的负载算法,至于其他的算法介绍...

    Jboss集群配置指南

    1. WEB Loadbalance 3 2. HTTP Session复制 3 3. JNDI 3 4. EJB 3 第二部分 集群物理实现 4 1. 物理架构 4 2. 机器网址分配 4 3. 软件环境 4 第三部分 集群配置 5 1. Apache 配置 5 2. Tomcat配置 6 3. Jboss配置 6 ...

    loadbalancer:使用Vagrant在VirtualBox环境上构建负载平衡基础结构(NGNIX和APACHE服务器); 建立服务及其依赖关系; 部署简单的Web应用程序(Ansible)

    先决条件 流浪汉 Vagrant是用于在单个工作流程中构建和管理虚拟机环境的工具。 请按照的说明进行安装。 VirtualBox提供者 并安装Virtual Box作为虚拟化提供程序。 拓扑结构 主机名 ... 现在,从控制V

    jboss jms参考资料包

    本文档描述了apache web服务器安装以及常用的编译模式;描述了apache+jboss3.2.6做负载均衡(load balance)的部署细节以及一些常见错误说明;描述了部署jboss3.2.3/3.2.6时一些心得、常用配置项

    lvs+keepalives部署.txt

    简介 Keepalived的作用是检测服务器的...主要用作RealServer的健康状态检查以及LoadBalance主机和BackUP主机之间failover的实现。 高可用web架构: LVS+keepalived+nginx+apache+php+eaccelerator(+nfs可选 可不选)

    Nginx From Beginner to Pro(Apress,2016)

    How to load balance Nginx and use it as a highly available web platform. How to monitor traffic and automate common administrative tasks. How to use scripts to perform routine checks for health issues...

    Getting Started with ownCloud

    Load balance ownCloud components Log ownCloud for debugging Approach This is a standard, precise, and short tutorial for setting up ownCloud and includes advanced topics like encryption, user ...

    Cassandra 3.x High Availability(PACKT,2ed,2016)

    Use replication and tunable consistency levels to balance consistency, availability, and performance Set up multiple data centers to enable failover, load balancing, and geographic distribution Add ...

    Cassandra.3.x.High.Availability.2nd.Edition.1786462109

    Use replication and tunable consistency levels to balance consistency, availability, and performance Set up multiple data centers to enable failover, load balancing, and geographic distribution Add ...

    httpd2.2.12.tar

    The Apache HTTP Server project must balance two competing and disjoint objectives: maintain stable code for third party authors, distributors and most importantly users so that bug and security fixes ...

    03开源NewSql数据库TiDB-Deep Dive into TiDB

    TiSpark 1.0 版本组件提供了针对 TiDB 上的数据使用 Apache Spark 进行分布式计算的能力。更新包括: 1.提供了针对 TiKV 读取的 gRPC 通信框架 2.提供了对 TiKV 组件数据的和通信协议部分的编码解码 3.提供了计算...

Global site tag (gtag.js) - Google Analytics