Apache + resin 配置集群(负载均衡)

来源:互联网 发布:seo排名优化服务 编辑:程序博客网 时间:2024/05/22 05:30

原文:http://hi.baidu.com/mygia/blog/item/c3b53da8e336cfa6ca130cb2.html

Apache 是一个出色的 http 服务器, 跟resin和tomcat这些web服务器不同,它不能解释动态页面,但作为服务器来解释html、js等静态文件比web服务器有效得多。而且apache还提供多方面的管理。Apache 可以整合resin或tomcat,当作高效又稳定的web server。

1 配置 Apache(one) + resin (one)
Apache 2.0.55 resin 3.0.19
配置 Apache + resin 当web 服务器要比单独用resin来做web server优秀的多。Resin的帮助文档也提供和Apache整合的资料。
首先,必先确保你的resin 和 Apache可以单独运行。Resin的安装和测试这里省略。Apache的安装非常简单。只需要默认安即可,中间只需要填写你的email。(我安装的是Apache 2.0.55)Apache安装后默认端口是80 。安装好测试http://localhost/, 若安装成功将显示成功测试的页面。确保你的resin 和 Apache可以单独运行后,修改Apache配置文件 conf/httpd.conf ,在后面加上如下一段。

LoadModule caucho_module <%resin_home%>/win32/apache-2.0/mod_caucho.dll

ResinConfigServer 192.169.100.15 6802

<locationcaucho-status="">
SetHandler caucho-status
</location>

注:&lt;%resin_home%&gt;代表resin安装目录,到时请将具体目录替代它。

这段的意思是为Apache加上一个插件,Apache以LoadModule ****_module语法加载插件。****_module为插件的名字,后面的是插件的文件地址。caucho_module这个插件就是resin提供的,是Apache和resin通讯的中间件,一般放在resin安装目录下的win32/apache-x.x/下(resin 3.0.19),apache-x.x目录一般有多个,你只要选择符合你的acpache版本的就可以。
或者你可以将相应的apache-x.x目录下的mod_caucho.dll文件复制到apche的插件文件夹内(&lt;%apache_home%&gt;/modules/)。然后使用相对路径。如
LoadModule caucho_module modules/mod_caucho.dll
而下一句中“192.169.100.15 ”代表的是resin所在机器的IP,“6802”是默认端口。然后修改resin的配置文件conf/resin.conf。找到这几行:
<cluster>
<srunserver-id=""host="127.0.0.1"port="6802">
</srun>
如果它们已经被注释,去掉注释符号,且务必要使这里的端口(如: port="6802")与刚才在resin配置文件中的ResinConfigServer 192.169.100.15 6802 这句话里配置的端口一致,如果你没有使用6802这个默认端口的话。192.169.100.15也应该与127.0.0.1相对应,它们都是指resin所在机器的IP,如果resin与apache同在一部机器,且<srunserver-id=""host="127.0.0.1"port="6802">这里使用127.0.0.1那么在ResinConfigServer 192.169.100.15 6802中应该将192.169.100.15改为localhost或127.0.0.1。就是说如果用了具体的IP如192.169.100.15,那么两个地方都要用具体的IP。
配置成功后打开http://localhost/caucho-status 可看到服务器的配置详细结果。
Apache (one)+ resin (one) 工作流程图如下:


这时访问apache就可访问到resin里配置的项目。Apache负责项目里的静态文件,resin则充当jsp/servlet解释服务器。像项目里这样的http://localhost/tianyacity/js/pageFunc.js (或html文件)则默认由apache 来解释,它将在apache里配置的项目和默认访问路径&lt;%apache_home%&gt;/htdocs/里查找http://localhost/tianyacity/js/pageFunc.js这个路径,它不会到resin里配置的项目里查找。所以要在&lt;%apache_home%&gt;/htdocs/里加上这个目录/tianyacity/js/pageFunc.js 又或者在apache配置文件httpd.conf里配置一个项目:

Alias /tianyacity/ "D:/workspace2006/tianyaCity/web/"

<directoryd:=""workspace2006=""tianyacity=""web="">
Options Indexes
AllowOverride None
Order allow,deny
Allow from all
</directory>
Alias /tianyacity/ 这里的/tianyacity/是访问路径名,与在resin配置的项目tiayacity的访问最好一致。


2 配置 Apache(one)+ resin (many)集群
Apache 2.0.55 resin 3.0.19

配置 Apache + resin 集群只需要在Apache(one)+ resin (one)的基础上修改Apache 和 resin的配置文件。

修改Resin 配置文件如下:


<httpserver-id="pan"host="*"port="8010">
<!--
- SSL port configuration:
-
- <http port="8443">
- <openssl>
- <certificate-file>keys/gryffindor.crt</certificate-file>
- <certificate-key-file>keys/gryffindor.key</certificate-key-file>
- <password>test123</password>
- </openssl>
- </http>
-->


<!--
- The local cluster, used for load balancing and distributed
- backup.
-->

<cluster>
<srunserver-id="pan"host="192.169.100.15"port="6802"index="”1”/">
<srunserver-id="he"host="192.169.100.16"port="6802"index="”2”/">
</srun>
………..

<srunserver-id="pan"host="192.169.100.15"port="6802"index="”1”/">
<srunserver-id="he"host="192.169.100.16"port="6802"index="”1”/">这样表示将IP为15和16的两台服务器作为一个集群。集群内的server-id不能相同。而本机的server-id 必须与配置文件中<httpserver-id="pan"host="*"port="8010">中的server-id 一致。因为resin默认的server-id为空(server-id=“”)所以修改后要加 –server 参数才能正确启动resin。在命令窗口(cmd)中去到resin安装目录,打入:
httpd.exe –server “pan”
将可正确启动resin。

修改Apache配置文件如下:

LoadModule caucho_module modules/mod_caucho.dll

ResinConfigServer 192.169.100.15 6802
ResinConfigServer 192.169.100.16 6802

<locationcaucho-status="">
SetHandler caucho-status
</location>

只需要在原来配置的基础上加上这一行
ResinConfigServer 192.169.100.16 6802
表示将16号机器上的resin也注册到apache中。这时涉及到两台服务器,在这里最好将Apache 和 resin的通讯插件复制到apche的插件文件夹内(&lt;%apache_home%&gt;/modules/)。
其实apche只需要知道一台主resin服务器即可,所以Apache配置文件在原来配置的基础上可以不用修改,由主resin服务器负责找到其他resin服务器。不过这样如果主resin服务器坏掉,将引发其它问题。所以推荐将所有resin服务器都注册到apache上。
配置完成后,打开http://localhost/caucho-status 可看到服务器的配置详细结果。所有注册到apache上的resin服务器都可以看到,没有注册到apache上的将不会显示。


 

原创粉丝点击