- 浏览: 3506604 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
wanglf1207:
EJB的确是个不错的产品,只是因为用起来有点门槛,招来太多人吐 ...
weblogic-ejb-jar.xml的元素解析 -
qwfys200:
总结的不错。
Spring Web Flow 2.0 入门 -
u011577913:
u011577913 写道也能给我发一份翻译文档? 邮件437 ...
Hazelcast 参考文档-4 -
u011577913:
也能给我发一份翻译文档?
Hazelcast 参考文档-4 -
songzj001:
DbUnit入门实战
Apache: Creating A Session-Aware Loadbalancer Using mod_proxy_balancer (Debian E
- 博客分类:
- 服务器
Since Apache 2.1, a new module called mod_proxy_balancer is available which lets you turn a system that has Apache installed into a loadbalancer. This loadbalancer retrieves requested pages from two or more backend webservers and delivers them to the user's computer. Users get the impression that they deal with just one server (the loadbalancer) when in fact there are multiple systems behind the loadbalancer that process the users' requests. By using a loadbalancer, you can lower the load average on your webservers. One important feature of mod_proxy_balancer is that it can keep track of sessions which means that a single user always deals with the same backend webserver. Most websites are database-driven nowadays with user logins etc., and you'd get weird results if a user logs in on one backend webserver, and then his next request goes to another backend webserver, meaning he'd get logged out again. You can avoid this by using mod_proxy_balancer 's session-awareness.
I do not issue any guarantee that this will work for you!
1 Preliminary Note
It should be noted that a loadbalancer can lower the load on your backend webservers, but it doesn't provide high-availability (as long as you use only one loadbalancer)! A single loadbalancer is a single point of failure (SPOF). If you need high-availability, you should use at least two loadbalancers (e.g. one as a hot-standby).
I will use three servers in this example: one loadbalancer with the address www.example.com / example.com , and two backend servers with the addresses http1.example.com and http2.example.com .
All three servers use Debian Etch as their operating system, and all three systems have Debian's Apache2 installed (its version is 2.2.3, so it comes with mod_proxy_balancer by default). On http1.example.com and http2.example.com I have installed a database-driven web application: phpBB2 , a famous forum software. Both phpBB2 installations are identical and use the same database. For debugging purposes, I've built-in a small difference in both installations: if the page is delivered by http1.example.com , it shows http1.example.com in the header:
And if it's delivered by http2.example.com , it shows http2.example.com :
That way I can control if sessions are handled correctly by mod_proxy_balancer . Of course, on a production system both pages would be the same.
Session-tracking is a bit tricky in mod_proxy_balancer because it expects a certain cookie format, and the name of the session variable can differ from application to application. Fortunately I've found this page: http://www.markround.com/archives/33-Apache-mod_proxy-balancing-with-PHP-sticky-sessions.html which has a great and easy solution for this problem that I'm going to use here.
2 Preparing The Backend Servers
First we must prepare our backend webservers http1.example.com and http2.example.com . We enable mod_rewrite like this:
http1.example.com / http2.example.com:
a2enmod rewrite
/etc/init.d/apache2 force-reload
Then we open the Apache vhost configuration of our phpBB2 site on http1.example.com and add the following lines to it:
http1.example.com:
[...] RewriteEngine On RewriteRule .* - [CO=BALANCEID:balancer.http1:.example.com] [...] |
(Make sure that you replace http1 and .example.com according to your needs!)
Restart Apache afterwards:
http1.example.com:
/etc/init.d/apache2 restart
Now we do the same on http2.example.com :
http2.example.com:
[...] RewriteEngine On RewriteRule .* - [CO=BALANCEID:balancer.http2:.example.com] [...] |
(Make sure that you replace http2 and .example.com according to your needs!)
Restart Apache afterwards:
http2.example.com:
/etc/init.d/apache2 restart
That's all we have to configure on the backend servers.
3 Configuring The Loadbalancer
On our loadbalancer www.example.com we must enable a few Apache modules:
www.example.com:
a2enmod proxy
a2enmod proxy_balancer
a2enmod
proxy_http
a2enmod status
and then restart Apache:
/etc/init.d/apache2 force-reload
I'm assuming that we don't run any other websites on the loadbalancer, so we can use Debian's default document root /var/www for our loadbalancer.
mod_proxy_balancer comes with a "Balancer Manager", a small web interface where you can tweak a few settings. We create the directory /var/www/balancer-manager for it which we password-protect so that only we have access to it:
mkdir /var/www/balancer-manager
htpasswd -c /var/.htpasswd
admin
(You can replace admin with any username you like.)
vi /var/www/balancer-manager/.htaccess
AuthType Basic AuthName "Members Only" AuthUserFile /var/.htpasswd <limit GET PUT POST> require valid-user </limit> |
Now we come to the vhost configuration of the loadbalancer. Apache's default vhost configuration on Debian Etch is located in /etc/apache2/sites-available/default , so we replace that with our own configuration:
cp /etc/apache2/sites-available/default
/etc/apache2/sites-available/default_orig
cat /dev/null >
/etc/apache2/sites-available/default
vi
/etc/apache2/sites-available/default
NameVirtualHost * <VirtualHost *> ServerName www.example.com ServerAlias example.com DocumentRoot /var/www/ ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass /balancer-manager ! ProxyPass / balancer://mycluster/ stickysession=BALANCEID nofailover=On ProxyPassReverse / http://http1.example.com/ ProxyPassReverse / http://http2.example.com/ <Proxy balancer://mycluster> BalancerMember http://http1.example.com route=http1 BalancerMember http://http2.example.com route=http2 ProxySet lbmethod=byrequests </Proxy> <Location /balancer-manager> SetHandler balancer-manager Order deny,allow Allow from all </Location> </VirtualHost> |
It is very important that you set all slashes (/) EXACTLY as shown in this example, especially the trailing slashes!
Please make sure that the value of stickysession is the name of the cookie (BALANCEID ) in our rewrite rules from chapter 2. Also, the values of route in the BalancerMember lines must be the respective value that we set in the rewrite rules (http1 or http2 ). The stickysession and route values take care of the correct session handling of mod_proxy_balancer .
It's also important that you have as many ProxyPassReverse lines as you have BalancerMember lines (one ProxyPassReverse line for each BalancerMember ).
The ProxyPass /balancer-manager ! line makes sure that requests to www.example.com/balancer-manager aren't routed to the backend servers.
You can find more details about all settings and further fine-tuning options on http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass and http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html .
Now that we've finished the configuration, we must restart Apache:
/etc/init.d/apache2 restart
4 Testing Our Setup
Our setup is now ready to be used. To test if sessions are handled correctly, I open two different browsers (because of the cookies), e.g. Firefox and Internet Explorer, and go to http://www.example.com or http://example.com . In both cases, you should see the phpBB2 forum, delivered by one of the backend servers (which you don't see, you should always have www.example.com or just example.com in the browser's address bar).
It's possible that the pages in both browsers are delivered by the same backend server - if that's the case, delete the cookies in your browsers or open another browser (Opera, Seamonkey, ...) and try again until you see that the pages in your two different browsers come from different backend servers (I can see it because I changed the header, as described in chapter 1). Then log in with two different users (e.g. falko and till ) that you have created before and browse the forum with these two different users. In my case falko 's content is always delivered by http1.example.com :
Whereas till 's content comes from http2.example.com :
So sessions are handled correctly by mod_proxy_balancer !
5 The Balancer Manager
Direct your browser to http://www.example.com/balancer-manager or http://example.com/balancer-manager . You will be prompted for a username and password (the username and password you've created in chapter 3).
After the login you will see a simple web interface for managing the loadbalancer:
You can find an overview of possible configuration options on http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass .
6 Links
- Apache: http://httpd.apache.org
- mod_proxy: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
- mod_proxy_balancer: http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html
- Apache mod_proxy balancing with PHP sticky sessions: http://www.markround.com/archives/33-Apache-mod_proxy-balancing-with-PHP-sticky-sessions.html
- Debian: http://www.debian.org
发表评论
-
collectd
2011-08-03 14:27 2284collectd是一个守护(daemon)进程,用来收集系 ... -
HP ASR(Automatic Server Recovery)机制
2011-04-15 14:24 3561ASR(Automatic Server Re ... -
LINUX下用HP的IML工具查看服务器的日志信息
2011-04-14 16:40 4903LINUX下用HP的IML工具查看 ... -
LINUX做服务器的无盘系统
2011-01-26 18:19 1926客户端是支持PXE方式启 ... -
简易搭建一个私有云平台
2010-11-17 18:30 3227众说周知Amazon EC2是一个公共云的计算平台,属于Iaa ... -
[HA]利于heartbeat构建Oracle高可用
2010-09-17 12:41 477710月 24th, 2008 @ Kevin.yuan ... -
服务部署--IP SAN潜在的关键应用
2010-08-26 09:38 2104IP SAN可以说是近几年来存储领域的关键技术之一, ... -
通过HAProxy构建开源负载均衡架构平台
2010-08-09 00:07 50281. 目的 通过此作业指导书,知道如何使用ubu ... -
MySQL负载均衡
2010-08-08 23:39 47111. 添加监控MySQL状态的端口 # vi /etc/se ... -
Ha-proxy 学习
2010-08-08 23:08 8968什么是ha-proxy ... -
SQL Server 各版本的区别
2010-08-08 17:49 4052SQL Server 2005 Enterprise Ed ... -
Oracle数据库11g版本介绍
2010-08-08 17:44 3480无论您是独立开发者、中小企业还是大型企业,这些世界一 ... -
tpmC简单计算法
2010-07-29 18:59 17973计算原则: 以单台服务器性能进行计算,即确保单台服务器工作的时 ... -
KVM遥控服务器群
2010-07-07 15:54 2153众所周知,所谓KVM,就是键盘(Keyboard)、显示器 ... -
数据存储配置参考
2010-07-02 10:07 1793型号 配 置 数量 ... -
More Numbers (OpenDS and a hint at ApacheDS)
2010-04-29 23:45 2479Some more numbers have come in. ... -
利用Copssh在windows下搭建ssh服务
2010-03-09 01:04 13435现在远程维护基本上用ssh连接,linux系 ... -
Taking a load off: Load balancing with balance
2010-03-05 16:00 1785A server is limited in how man ... -
Software Based Load Balancers
2010-03-05 15:57 1847keyword:Load Balance ref: http ... -
SAN,NAS,DAS及其架构之间区别
2010-02-26 14:11 1712随着计算机技术的发展 ...
相关推荐
Wi-Fi Aware™ Specification Version 3.2 Wi-Fi Aware™ Specification Version 3.2 是 Wi-Fi Alliance 发布的一份技术规范文档,主要介绍 Wi-Fi Aware™ 技术的详细规范和实现细节。下面是该规范的详细解读: ...
城市规模上下文感知出租车调度使用深度强化学习 摘要——主动的出租车调度对于平衡城市不同地点的出租车需求与供应差距至关重要。近年来,主要依赖深度强化学习(DRL)直接学习最优调度策略。然而,这些方法在效率...
"Awareness at Scale: Creating Risk-Aware Cultures in Big Companies"这一主题聚焦于如何在大型公司内部建立风险意识文化,以应对日益复杂的安全挑战。这场讨论由多位业界专家参与,包括国际货币基金组织的资深...
7. **考虑弹性的轨迹优化方法**:"An-optimization-based-approach-for-elasticity-aware-trajectory-_2021_Mechatr.pdf" 文件可能探讨了在考虑系统弹性因素的情况下,如何使用Matlab进行轨迹规划优化,这对于机器人...
《Context-aware Visual Tracking》是2009年发表在Pattern Analysis and Machine Intelligence (PAMI) 上的一篇重要论文,该文深入探讨了上下文感知在视觉跟踪中的应用。上下文感知(Context-aware)技术在计算机...
Wi-Fi_CERTIFIED_Passpoint_Industry Wi-Fi_CERTIFIED_Passpoint_Industry Wi-Fi_CERTIFIED_Passpoint_Industry Wi-Fi_CERTIFIED_Passpoint_Industry
《Context-Aware-S-Policy.rar_Aware_异构网络》这一压缩包文件主要涉及的是一个名为"Context-Aware Security Policy"的概念,它在异构网络环境中的应用与扩展。在这个系统中,广义角色基访问控制(GRBAC,...
本项目"location-aware-publish-subscribe-master.zip_Aware_directionm98_索"聚焦于构建一个高效的位置感知发布订阅系统,该系统利用空间索引技术处理地理文本数据,并提供智能查询功能。下面将详细介绍这个系统的...
为了解决这个问题,本文提出了一种位置偏置感知学习框架(Position-bias Aware Learning,简称PAL),用于CTR预测。PAL框架旨在减少因位置偏置引起的预测误差,并提高推荐系统的在线性能。我们分析了位置偏置对CTR...
【标题】"Tidal-Traffic-Aware-Routing - 弹性光网络_traffic_源码"涉及的是在光网络中实现流量感知路由(Tidal Traffic-Aware Routing)的技术,特别是针对弹性光网络(Elastic Optical Networks, EONs)的优化策略。...
本文档标题为"Fusion-Aware Point Convolution for Online Semantic 3D Scene Segmentation",由Jiazhao Zhang、Chenyang Zhu、Lintao Zheng和Kai Xu联合撰写。文档探讨了如何实现实时RGB-D重建配合在线语义三维场景...
多视图立体三维重建MVS论文
Lamps 系统的设计与实现 - Location-Aware Moving Top-k Pub/Sub 系统 在当前的信息时代,geo-tagged 数据的增长速度非常快,例如 geo-tagged tweets、位置感知的社交媒体应用等。这类数据的增长对许多应用程序产生...
code for modulation in communication system
Content-Aware Unsupervised Deep Homography Estimation and Its Extensions 本资源讨论了图像对齐中的基本方法—Homography estimation。在传统方法中,Homography estimation通常通过稀疏特征点的提取和匹配来...
globe_with_meridians_Jekyll_is_a_blog-aware,_sta_jekyll
在“Tidal-Traffic-Aware-Routing-and-Spectrum-Allocation-in-Elastic-Optical-Networks-master”这个压缩包中,很可能包含了项目的源代码、实验数据、算法描述文档等资源。通过深入研究这些文件,可以详细了解潮汐...
may contain objects of multiple categories, are widely involved in many image retri systems. However, in most existing hashing methods for images, the semantic similarities are defined at image level,...