apache+resin的load balance应该如何配置?

我使用resin 2.1.8 + apache 1.3.26

想达到这个效果:
The plugin sends a session to the same backend srun.
http://www.caucho.com/resin/ref/balance.xtpSingle-Web-Server-Load-Balancing

按照这个文档的提示,配置如下:


<http-server>
<srun id='1' host='10.3.2.31' port='6810' srun-index='1'/>
<srun id='2' host='10.3.2.32' port='6810' srun-index='2'/>
<srun id='3' host='10.3.2.171' port='6810' srun-index='3'/>
<srun id='4' host='10.3.3.1' port='6810' srun-index='4'/>

<session-config>
<session-max>4096</session-max>
<session-timeout>30</session-timeout>
<enable-cookies>false</enable-cookies>
<enable-url-rewriting>true</enable-url-rewriting>
</session-config>

</http-server>

特意不配置resin的tcp-ring session。我之前就是用resin的tcp-ring来做的,不过现在有问题,所以就想达到同一个session的所有请求都由同一部resin来做。

并且这个配置文件从apache到4个resin都是一致的。


另外apache的配置文件中添加了如下配置:


LoadModule caucho_module /export/nfs/liusf/bin/aihttpd/libexec/mod_caucho.so
AddHandler caucho-request .do ;使用了struts
<IfModule mod_caucho.c>
CauchoConfigFile /export/nfs/liusf/bin/aihttpd/conf/resin.conf
<Location /caucho-status>
SetHandler caucho-status
</Location>
</IfModule>

现在的情况是第一次进入系统的时候,apache选择一个resin,生成页面成功,并且第一个页面也使用了struts,就是struts也运行成功的。然后就出问题了,apache还是按round robin的算法来处理我后续的请求,但是由于没有配置tcp-ring,所以第一个页面中生成了的session在其他resin无法处理,所以后续的页面就变成没有session了。我想配置为apache在页面有session的情况下,把这个页面的后续请求转发到生成这个session的resin来处理。如果我的理解没有错的话,上面resin的文档描述的就是这个功能。


请有过成功配置经验的人给点意见。

尝试了N久之后,仍然没有进展。不得已只好看源代码。

1.看apache的api文档,找到ap_log_error的用法
2.进入resin/src/c/plugin/apache,在文件mod_caucho.c的get_session_index函数中输出一些信息来看。

get_session_index函数的逻辑很清晰:
(1)先尝试从http头里面获取cookie,看看是否有jsessionid
(2)如果没有cookie,则再看是否在resin中配置了


<alternate-session-url-prefix>/~J=</alternate-session-url-prefix>
。如果配置了这项,尝试从url中获取jsessionid。这里指的是类似如下的url:http://xxx.xxx.xxx.xxx/~J=a1TdUzexjjB8/app1/xxx.do
(3)如果没有配置alternate-session-url-prefix,则使用apache传递过来的uri,尝试看看是否存在jsessionid。这里的url是类似如下的:http://xxx.xxx.xxx.xxx/app1/xxx.do;jsessionid=a1TdUzexjjB8

问题好像就出在这个url里面。apache传递过来的url中,是没有jsessionid的,所以resin的mod_caucho是没有办法从这个url中获取jsessionid的信息,也就没有办法知道应该连到哪个resin去。

另外应用程序要尽量保证在没有cookie的功能下也要能运行。

所以解决方法只有:使用alternate-session-url-prefix配置。

注意,alternate-session-url-prefix不是配置到


<session-config>
<session-max>4096</session-max>
<session-timeout>30</session-timeout>
<enable-cookies>false</enable-cookies>
<enable-url-rewriting>true</enable-url-rewriting>
<!--不是配置在这里
<alternate-session-url-prefix>/~jsessionid=</alternate-session-url-prefix>
-->
<!--
- Store sessions in the filesystem, so they can persist across
- servlet and class changes.
-
- Uncomment this during development.
-->
<!--
- <file-store>WEB-INF/sessions</file-store>
-->
</session-config>

而是配置到


<http-server>
<!--
- The root file directory of the server. Apache users will change
- this to /usr/local/apache/htdocs and IIS users will change it
- to d:\inetpub\wwwroot
-->
<doc-dir>doc</doc-dir>

<!-- the http port -->
<http port='8080'/>

<!--
- The srun port, read by both JVM and plugin
- 127.0.0.1 is the localhost
-->
<srun host='127.0.0.1' port='6802'/>

<!-- 请配置到这里 -->
<alternate-session-url-prefix>/~jsessionid=</alternate-session-url-prefix>

....
...