resin是一个非常流行的web引用服务器,对servlet和jsp提供了良好的支持,自身采用java开发,支持集群,还支持PHP。
resin分为普通版和专业版,主要区别是专业版支持缓存和负载均衡。
一、配置安装
1、安装jdk
# tar -xf jdk-8-linux-x64.tar.gz -C /application/
方法一、
# sed -i.ori '$a export JAVA_HOME=/application/jdk\nexport PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH\nexport CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar' /etc/profile
方法二、
# echo '#java env config ' >>/etc/profile
生效及检查版本
# source /etc/profile
2、安装resin
# cd /home/nulige/tools/
3、配置resin
# ls /application/resin/conf
app-default.xml development.conf fine.conf minimal.conf resin.conf resin.conf.orig
从88行开始删除到146行,(快整跳到88行,用快捷键:88gg) 再用快捷键:59dd (删除59行内容)
#再添加下面代码到删除的地方,并注意:server id= xxx,是指启动时指定的标签,地址就是本机网卡地址,端口不用改。
添加代码如下:
4、启动resin
# /application/resin/bin/httpd.sh -server oldboy start
# netstat -lntup|egrep "6911|6921|8080"
tcp 0 0 :::8080 :::* LISTEN 2373/java
tcp 0 0 ::ffff:192.168.1.139:6911 :::* LISTEN 2373/java
tcp 0 0 ::ffff:127.0.0.1:6921 :::* LISTEN 2345/java
5、配置站点目录
# cd /application/resin/webapps/ROOT/
# echo '<99+1=<%=99+1>' >/application/resin/webapps/ROOT/test.jsp
6、配置启动方式
1)系统自带的启动脚本
# cp /application/resin/contrib/init.resin.in /etc/init.d/resind
2)自己写一个启动脚本,放在启动目录
resind启动脚本
#!/bin/sh
#chkconfig:345 85 15
#To install, configure this file as needed and copy init.resin
#to /etc/rc.d/init.d as resin. Then use "# /sbin/chkconfig resin reset"
. /etc/init.d/functions
StartPath='/application/resin/bin/httpd.sh'
ResinLog=/app/logs/resinlog
[ ! -d $ResinLog ] && mkdir -p &ResinLog
resind()
{
#如果是多进程增加下面的配置段:oldboy后面空格再接标签名即可
for id in oldboy
do
$StartPath -server $id $1 >> $ResinLog/resin_startup.log
if [ $? -eq 0 ]
then
action "$1 $id resin…"/bin/true
else
action "$1 $id resin…"/bin/false
fi
done
}
case "$1" in
start)
resind $1
echo '------checking-------'
sleep 15
netstat -lnt|egrep "80|69"
echo '------check over------'
;;
stop)
resind $1
;;
restart)
resind stop
resind start
;;
*)
echo "Usage: $0{start|stop|restart}"
exit 1
esac
exit 0
#dos2unix处理一下
# dos2unix /home/tom/init.d/resind
# chmod +x /home/tom/init.d/resind
7、添加开机自启动
# chkconfig --add resind
二、整合 appche + resin
1、安装appche
# yum -y install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel
--enable-deflate \
--enable-headers \
--enable-modules=so \
--enable-so \
--with-mpm=worker \
--enable-rewrite
2、为apache编译resin mod_caucho 模块
# cd /application/resin-3.1.13
mod_caucho.so
提示:这个模块很类似Apache+php结合的PHP模块一样,Apache就是通过这个mod_caucho.so模块调用resin解析Java程序的
# tail -9 /application/apache/conf/httpd.conf
#mod_caucho Resin Configuration
LoadModule caucho_module /application/apache2.2.23/modules/mod_caucho.so
ResinConfigServer 192.168.1.8 6911
CauchoConfigCacheDirectory /tmp
CauchoStatus yes
3、测试
echo "apache" /var/www/a.html
echo "<%resin=99+1%>" /application/resin/webapps/ROOT/a.jsp
curl http://192.168.1.8/a.html
curl http://192.168.1.8/a.jsp
默认情况:
Apache:解析静态网页,resin:解析动态网页
ResinConfigServer 192.168.1.8 6921
SetHandler caucho-reques
SetHandler caucho-reques是转发作用,由Apache把所有的请求转给resin。
三、Apache虚拟主机+resin
1、配置虚拟主机
# cd /application/apache/conf/extra/
DocumentRoot "/var/www"
DirectoryIndex index.html index.jsp index.php
ServerName www.abc.com
ErrorLog "logs/abc-error_log"
CustomLog "logs/abc-access_log" common
<Directory "/var/www">
Options -Indexes +FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
#Resin Configuration
ResinConfigServer 192.168.1.8 6921
2、修改Apache主配置文件内容:
# vim /application/apache/conf/httpd.conf
395 # Virtual hosts
396 Include conf/extra/httpd-vhosts.conf ---此行注释要打开
#mod_caucho Resin Configuration
LoadModule caucho_module /application/apache2.2.23/modules/mod_caucho.so
#ResinConfigServer 192.168.1.8 6911 ---这里注释掉!
#SetHandler caucho-request
CauchoConfigCacheDirectory /tmp
CauchoStatus yes
3、测试
# echo "Apache" >/var/www/a.html
Apache
resin=100
四、Apache多虚拟主机+ resin多虚拟主机
1、配置Apache虚拟主机
# cat /application/apache/conf/extra/httpd-vhosts.conf
NameVirtualHost *:80
DocumentRoot "/var/www"
DirectoryIndex index.html index.php index.jsp
ServerName www.abc.com
ErrorLog "logs/abc-error_log"
CustomLog "logs/abc-access_log" common
#Resin Configuration
ResinConfigServer 192.168.1.140 6911
SetHandler caucho-request
###########################
DocumentRoot "/var/blog"
DirectoryIndex index.html index.php index.jsp
ServerName www.abc.org
ErrorLog "logs/org-error_log"
CustomLog "logs/org-access_log" common
#Resin Configuration
ResinConfigServer 192.168.1.140 6912
#SetHandler caucho-request
2、配置resin多虚拟机
配置主配置 /application/resin/conf/resin.conf
<jvm-arg>-Xmx256m</jvm-arg>
<jvm-arg>-Xss1m</jvm-arg>
<jvm-arg>-Xdebug</jvm-arg>
<jvm-arg>-Dcom.sun.management.jmxremote</jvm-arg>
<memory-free-min>1M</memory-free-min>
<thread-max>256</thread-max>
<socket-timeout>65s</socket-timeout>
<keepalive-max>128</keepalive-max>
<keepalive-timeout>15s</keepalive-timeout>
</server>
#######################################
<jvm-arg>-Xmx256m</jvm-arg>
<jvm-arg>-Xss1m</jvm-arg>
<jvm-arg>-Xdebug</jvm-arg>
<jvm-arg>-Dcom.sun.management.jmxremote</jvm-arg>
<memory-free-min>1M</memory-free-min>
<thread-max>256</thread-max>
<socket-timeout>65s</socket-timeout>
<keepalive-max>128</keepalive-max>
<keepalive-timeout>15s</keepalive-timeout>
</server>
</web-app>
<web-app id="/resin-admin-abc.org" root-directory="${resin.home}/php/admin">
<character-encoding>utf8</character-encoding>
<prologue>
<resin:set var="resin\_admin\_external" value="true"/>
<resin:set var="resin\_admin\_insecure" value="true"/>
</prologue>
<security-constraint>
<web-resource-collection>
<url-pattern>/\*</url-pattern>
</web-resource-collection>
</security-constraint>
</web-app>
<stderr-log path='/app/log/resinlog/www\_stderr.log'
rollover-period='1W'/>
<stdout-log path='/app/log/resinlog/www\_stdout.log'
rollover-period='1W'/>
</host>
##################################
</web-app>
<web-app id="/resin-admin-abc.org" root-directory="${resin.home}/php/admin">
<character-encoding>utf8</character-encoding>
<prologue>
<resin:set var="resin\_admin\_external" value="true"/>
<resin:set var="resin\_admin\_insecure" value="true"/>
</prologue>
<security-constraint>
<web-resource-collection>
<url-pattern>/\*</url-pattern>
</web-resource-collection>
</security-constraint>
</web-app>
<stderr-log path='/app/log/resinlog/blog\_stderr.log'
rollover-period='1W'/>
<stdout-log path='/app/log/resinlog/blog\_stdout.log'
rollover-period='1W'/>
</host>
注释掉resin主配置中虚拟主机中的http端口内容:
90 2024 .