apache2resin 3.1.6 linux下的整合与负载均衡

<1> 安装apache

./configure --prefix=/opt/apache2 --enable-so  --enable-dav --enable-dav-fs --enable-mods-shared=most  
make 
make install
安装resin :
./configure --prefix=/opt/resin3.1.6 --with-apxs=/opt/apache2/bin/apxs  --with-apache=/opt/apache2
make 
make install
上述操作编译安装完后,会自动修改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 6800
CauchoConfigCacheDirectory /tmp
CauchoStatus yes 
如果没有自动修改,请自己手动添加,或者检查,是否配置正确。

1linux下使用resin的单服务器配置

使用单服务器方案,只要安装完毕,配置一下Resinresin.conf文件和app_default.xml文件就可以了,resin.conf文件中需要配置两处,
一是端口号,另一处是Web程序存放目录,app_default.xml内可配置默认首页的搜索顺序。
由于原网站使用多个端口配置,所以单服务器只能用于做单个站点的测试使用。
配置如下:
修改resin/conf/resin.conf 
 <server id="a" address="192.168.1.116" port="6800"/>
启动 /opt/resin/bin/httpd -server a start
如果使用如下命令默认启动,
/opt/resin/bin/httpd start
必须如下配置.默认 是id 为空
<server id="" address="192.168.1.116" port="6800"/>
启动 /opt/apache2/bin/apachectl start
访问 
http://localost/caucho-status 看是否成功.
==========================================================================================================
2
linux下使用resin的多服务器配置

 有时候需要运行多个服务器以在同一个IP上监听多个端口,这时候就需要使用单独的Resin服务器运行多个实例,以监听多个端口来部署多个Web站点。
这种方法为多次使用httpd.sh的参数指定配置文件和运行时的pid文件,实现多个实例的运行。
使用的命令行如下所示:
$RESIN_HOME/bin/httpd.sh -conf conf/resin2.conf -server b start/stop
解释:
 -conf
选项为选择此服务器实例所用的配置文件,在这个文件里面配置不同的端口和主目录。
具体配置如下:
配置一:
copy
一份resin.conf,命名为resin2.conf,找到   <http address="*" port="8080"/>
将其注释掉。修改为: <!--http address="*" port="8080"/-->.
添加<server id="b" address="192.168.1.166" port="6801"/>
修改apache配置文件 :
LoadModule caucho_module modules/mod_caucho.so
ResinConfigServer 192.168.1.166 6800
ResinConfigServer 192.168.1.166 6801
CauchoConfigCacheDirectory /tmp
CauchoStatus yes
然后用如下命令启动:
/opt/resin3.1.6/bin/httpd.sh -conf /opt/resin3.1.6/conf/resin2.conf -server b start
访问 
http://localost/caucho-status 看是否成功.

配置二:
copy
一份resin.conf,命名为resin3.conf,找到   <http address="*" port="8080"/>
将其注释掉。修改为: <!--http address="*" port="8080"/-->.
添加 
<server id='b' address='192.168.1.166' port='6802' watchdog-port="6602">
  <http port="8081"/>
</server>
这样配置,即启动了两套resin服务。优点是比较安全。缺点是 比较浪费系统资源。
修改apache配置文件 :
LoadModule caucho_module modules/mod_caucho.so
ResinConfigServer 192.168.1.166 6800
ResinConfigServer 192.168.1.166 6802
CauchoConfigCacheDirectory /tmp
CauchoStatus yes
然后用如下命令启动:
/opt/resin3.1.6/bin/httpd.sh -conf /opt/resin3.1.6/conf/resin3.conf -server b start
访问 
http://localost/caucho-status 看是否成功.
如果访问不了。接着添加如下配置到httpd.conf中。
<Location /caucho-status>
        SetHandler caucho-status
</Location>
============================================================================================================
<2> apache,resin
与虚拟主机
上面只是配好apacheresin的整合,其它很多企业应用中还涉及到配置apacheresin的虚拟主机的配置,
接着来说说如何利用apacheresin配置虚拟主机了,注意以下介绍的都是基于一个IP多个域名的虚拟主机的配法:
配置apache2:
NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot "/www/test1"
    ServerName 
www.test1.com
    ServerAlias 
www.test1.com
    ErrorLog "logs/test1_err.log"
    CustomLog "logs/test1_access.log" common
    ResinConfigServer 192.168.1.166 6800
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot "/www/test2"
    ServerName 
www.test2.com
    ServerAlias 
www.test2.com
    ErrorLog "logs/test2_error.log"
    CustomLog "logs/test2_access.log" common
    ResinConfigServer 192.168.1.166 6801
</VirtualHost>
修改apache 配置文件如下:

LoadModule caucho_module modules/mod_caucho.so
ResinConfigServer 192.168.1.166 6800
ResinConfigServer 192.168.1.166 6801
CauchoConfigCacheDirectory /tmp
CauchoStatus yes
<Location /caucho-status>
        SetHandler caucho-status
</Location>
也可以将 第二行和第三行注释掉。

添加目录访问权限:
<Directory "/www">
    Options Indexes FollowSymLinks
    Order allow,deny
    Allow from all
</Directory>
配置resin.conf ,添加如下:
<host id="
www.test1.com" root-directory=".">  
    <host-alias>www.test1.com</host-alias>  
    <web-app id="/" root-directory="/www/test1/"></web-app>  
</host> 
配置resin2.conf 添加如下内容:
<host id="
www.tet2.com" root-directory=".">  
    <host-alias>www.test2.com</host-alias>  
    <web-app id="/" root-directory="/www/test2/"></web-app>  
</host> 
注意,<host-alias>一定要和apache中的ServerAlias相对应。 
分别启动resin
/opt/resin3.1.6/bin/httpd.sh -server a start
/opt/resin3.1.6/bin/httpd.sh -conf /opt/resin3.1.6/conf/resin2.conf -server b start
分别在/www/test1 /www/test2/目录下建立test1.jsp test2.jsp测试,是否成功。如果访问成功。
说明配置成功。

以上是不同主机用不同的JVM,如果你只有一个虚拟host的话
可以在Apachehttpd.conf中这么这样设置
<Location /applicationA/*>
ResinConfigServer 192.168.1.166 6800
</Location>
<Location /applicationB/*>
ResinConfigServer 192.168.1.166 6801
</Location>
不同的模块,使用不同的jvm

 

 

 

 

 

举例,copy一份resin.conf,修改其中的两个端口,一个是http服务的端口<http address="*" port="8080"/>,一个是管理端口和服务名<server id="svrname" address="127.0.0.1" port="6800"/> 然后启动时指定配置文件:${resinhome}/bin/httpd.sh -conf ${resinhome}/conf/${svrname}.conf -server $svrnamesvrname是服务id和配置文件的名称(假设是相同的)。

为了区别不同服务的日志,还要改一个地方:
  <log name="" level="fine" path="stdout:" timestamp="[%H:%M:%S.%s] "/>
  <stdout-log path="${resin.home}/log/svrname.log"
    archive-format="svrname-%Y_%m_%d.log" 
    rollover-period="1D"
    rollover-size="1mb"/> 
  <stderr-log path="${resin.home}/log/svrname.log"
    archive-format="svrname-%Y_%m_%d.log"
    rollover-period='1D' 
    rollover-size='1mb'/>

进一步,可以写一个脚本改进resin的启动。先写一个newhttpd.sh
svrname=$1
action=$2
logaction=$3
resinhome="${HOME}/resin"
${resinhome}/bin/httpd.sh -conf ${resinhome}/conf/${svrname}.conf -server $svrname $action
if [ "${logaction}" == "tail" ] ; then
  echo ******start tailing log, press ^C leave tail.****** 
  tail -f ${resinhome}/log/${svrname}.log
fi

假设服务idreport和配置文件名为report.conf,再写一个report.sh
resinhome="${HOME}/resin"
${resinhome}/bin/newhttpd.sh report $1 $2

$1 及时 start/stop/restart之类的,$2就是需不需要在启动后跟踪log文件,意义不大,用不用随你了。