负载均衡(1)mod_jk

The Apache  mod_jk   module is a plug-in that handles communication between Tomcat and the HP-UX Apache-based Web server.

Figure 3-3   illustrates load balancing with  mod_jk . The  mod_jk   module load balances between several application servers. In most cases, the web server handles the static data and distributes dynamic content to the application servers.

Figure 3-3 Load Balancing With  mod_jk

Load Balancing With mod_jk

 

http://docs.hp.com/en/5992-5286/ch03s02.html

When configuring  mod_jk   load balancing, you can do the following:

  • Ensure that requests are not routed to a server that is not responding.

  • Set up round-robin, or weighted round-robin to route requests to a server.

  • Route all requests from the same session to the same server (sticky session).

【问题1】负载均衡棘手的问题:会话状态
(办法1)
sticky session   就是要保证隶属同一个会话的所有http请求被固定分发到同一个tomcat (route all requests from the same session to the same server)。 可以猜测或许tomcat的AJP connector 会将session相关信息(sessionid和服务器端保留的状态信息)告诉mod_jk,以便mod_jk在收到新的http请求时,能够判断出该请求是否隶属前面的某个session,以决定是否固定路由到曾今的tomcat。 但是还有个问题,如果此时这个被固定路由的tomcat宕了,mod_jk别无选择,不得不将请求分发到另外的tomat,但是问题是该tomcat却不具有session信息。那mod_jk是不是需要将自己从先前tomcat冗余来的session信息复制到新的tomcat上呢?似乎不是这么回事?(下图)

archi2
The term "session replication" is used when the current service state is being replicated across multiple application instances. (差不多实时复制,那还需要sticky session?) Session replication occurs when the information stored in an HttpSession is replicated from, in this example, one servlet engine instance to another.  This could be almost any type of data, such as items contained in a shopping cart or information being entered on an insurance application.  Anything being stored in the session must be replicated for the service to failover without a disruption.


(办法2)
各个tomcat放弃局部于本tomcat的session,改用分布式session容器,session容器以一个单独的服务存在,状态信息集中保存在该session服务器上,各个tomcat通过特定的客户端访问session服务器,以使sesssion服务器的信息为所有tomcat共享。具体实现可以采用memcache或干脆简单点写到DB中去。



参考资料:
(1) http://docs.hp.com/en/5992-5286/ch03s02.html    mod_jk与AJP Connector通信结构图
(2) http://hwmind.blog.163.com/blog/static/18407862200931825630160/ 
  apache httpd和tomcat整合,可以使用mod_jk,也可以使用mod_proxy(http_proxy和ajp_proxy)。
其中:mod_jk 比较稳定,已经被大量实践;   mod_proxy配置简单,使用方便,但是用的相对少。
Apache HTTP Server 与 Tomcat 的三种连接方式介绍

(4)ApacheTomcat整合教程    (提供下载)
(5)http://www.javaworld.com/javaworld/jw-02-2005/jw-0228-pippo.html?page=2 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值