前言:前段时间,对公司前台多机分布方案的做了一些探索,总结了一些东西,贴出来分享。类似内容网上比较多,但是都不够详细,我第一次弄时费力不少,希望后来人可以更方便一些。

一. 编译安装apache
1) 从apache官网上下载apache最新的 release版本2.2.6
unix版本取httpd-2.2.6.tar.gz
2) 解开包
gunzip httpd-2.2.6.tar.gz
tar xvf httpd-2.2.6.tar
3) 编译安装
进入解压后的目录httpd-2.2.6,依次执行
./configure --prefix=/*要安装apache的目录*/ --enable-so
make
make install
成功后apache就安装到前面指定的目录了

二) 启动apache
进入apache安装目录
1) 修改apache/conf/httpd.conf
Listen 80 修改80为需要的端口如 11280
2) 启动
进入apache/bin/执行: ./apachectl start
3) 打开浏览起访问
http://ip: 11280

三) 编译安装resin

./configure --prefix=/data/aoxj/artest/resin --with-apxs=/data/aoxj/artest/apache/bin/apxs --with-apache=/data/aoxj/artest/apache
make
make install
上述操作除了编译安装resin外(其实不做这些操作,resin本身也是可以跑起来的),还会修改apache,包括:
1. copy mod_caucho.so到apache目录(就是前面指定的--with-apache=/data/aoxj/artest/apache)的modules
2. 修改apache的配置文件conf/httpd.conf,自动增加以下内容
LoadModule caucho_module ***/modules/mod_caucho.so
ResinConfigServer localhost 6802
CauchoConfigCacheDirectory /tmp
CauchoStatus yes

四)配置resin
需要修改resin.conf文件

<cluster>
<srun server-id="a" host="192.168.0.1" port="6802"/>
<srun server-id="a" host="192.168.0.1" port="6802"/>
</cluster>

五)启动resin
运行resin/bin/httpd.sh
注意一定要加-server,否则resin启动后是监听80/8080这样的端口,而不是上面cluster设置里面的6802
./httpd.sh -server a start
这样resin才会监听6802,建议手工telnet确认一下。如果resin启动不正确,后面apache启动后访问resin就会失败,然后在页面报503错误。
以后stop/restart 时也需要加-server

六) 配置apache
确认conf/httpd.conf文件中的以下内容
1) LoadModule caucho_module ***/modules/mod_caucho.so
检查mod_caucho.so是否存在
2) ResinConfigServer localhost 6802
这个ResinConfigServer只能出现一行,如果resin有多台,请在这里指定的那台resin配置文件中的<cluster>中配置其他机器的ip/port
3) CauchoConfigCacheDirectory /tmp
4)CauchoStatus yes

最后修改的配置为:

LoadModule caucho_module "/data/aoxj/artest/apache/modules/mod_caucho.so"
ResinConfigServer 192.168.0.1 6802
AddHandler caucho-request .action
CauchoConfigCacheDirectory /tmp
CauchoStatus yes

八)web访问
启动apache
用浏览器访问apache的端口,注意不是访问resin的端口