resin服务之一---安装及部署

参考网站:

http://caucho.com/

http://www.oschina.net/p/resin

http://caucho.com/resin-4.0/admin/starting-resin.xtp

 

一、resin产生背景

ResinCAUCHO公司(http://www.caucho.com/)的产品,是一个非常流行的支持servlets jsp的引擎,速度非常快。Resin本身包含了一个支持HTTP/1.1WEB服务器。虽然它可以显示动态内容,但是它显示静态内容的能力也非常强,速度直逼APACHE SERVER。许多站点都是使用该WEB服务器构建的。

Resin也可以和许多其他的WEB服务器一起工作,比如Apache serverIIS等。Resin支持Servlets 2.3标准和JSP 1.2标准。熟悉ASPPHP的用户可以发现用Resin来进行JSP编程是件很容易的事情。

Resin支持负载平衡(Load balancing),可以增加WEB站点的可靠性。方法是增加服务器的数量。比如一台SERVER的错误率是1%的话,那么支持负载平衡的两个Resin服务器就可以使错误率降到0.01%

 

二、resin环境准备及安装

resin环境安装准备

1)系统环境

2)软件需求

系统:centos5.8(x86_64)

   centos6.4(x86_64)

软件: jdk-6u34-fcs-bin-b04-linux-amd64-19_jul_2012.bin 或者 jdk-6u34-linux-x64.bin

 

版本需求:

Resin 3.1 needs Java before it can run.It needs JDK 1.5 or a later JDK.

Resin 3.1 needs Java before it can run.Resin requires JDK 6.0 or later.

http://www.caucho.com/resin-3.1/doc/starting.xtp

http://www.caucho.com/resin-4.0/admin/starting-resin.xtp

http://www.caucho.com/download/resin-3.1.13.tar.gz  ------》下载resin-3.1.13.tar.gz版本

httpd-2.2.23.tar.gz

 

地址:

http://www.caucho.com/download/

http://httpd.apache.org/download.cgi

http://java.sun.com/javase/downloads/index.jsp

http://www.oracle.com/technetwork/java/javase/archive-139210.html ---下载jdk-6u34-linux-x64.bin

 

安装JDK环境

1)下载JDK

登陆http://www.oracle.com/technetwork/java/javase/archive-139210.html 下载对应的jdk版本。

或者上传jdk-6u34-linux-x64.bin到/home/peng/tools

 

[root@data-1-1 tools]# ll jdk-6u34-linux-x64.bin

-rwxr-xr-x 1 root root 72036348 Jan  8  2016 jdk-6u34-linux-x64.bin

 

2)增加权限并安装

[root@data-1-1 tools]# chmod +x jdk-6u34-linux-x64.bin

[root@data-1-1 tools]# ./jdk-6u34-linux-x64.bin

[root@data-1-1 tools]# ls -ld jdk1.6.0_34/

drwxr-xr-x 8 root root 4096 Nov 29 00:48 jdk1.6.0_34/

安装完成后,会在当前目录下建立jdk1.6.0_34/的目录。

提示:JDK全称Java(TM) SE Development Kit 6 successfully installed.

 

3)配置JDK的安装路径

mkdir -p /application

cd  /home/peng/tools

mv jdk1.6.0_34/ /application/

ln -s /application/jdk1.6.0_34/  /application/jdk

ls -l /application/ |grep jdk

/application/jdk/bin/java –version

 

查看版本信息:

[root@data-1-1 tools]# /application/jdk/bin/java -version

java version "1.6.0_34"

Java(TM) SE Runtime Environment (build 1.6.0_34-b04)

Java HotSpot(TM) 64-Bit Server VM (build 20.9-b04, mixed mode)

 

4)设置JAVA变量

echo "#java start_config at 2016-1-7" >>/etc/profile

echo 'export JAVA_HOME=/application/jdk' >>/etc/profile

echo 'export PATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib'>>/etc/profile

echo 'export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin'>>/etc/profile

echo 'RESIN_HOME=/application/resin' >>/etc/profile

echo "#java env end config at 2016-1-7" >>/etc/profile

 

生效:

source /etc/profile

 

查看:

echo $JAVA_HOME

echo $CLASSPATH

echo $RESIN_HOME

echo $PATH

 

5)安装resin

[root@data-1-1 ~]# cd /home/peng/tools/

[root@data-1-1 tools]# wget http://www.caucho.com/download/resin-3.1.13.tar.gz

[root@data-1-1 tools]# tar -zxf resin-3.1.13.tar.gz

[root@data-1-1 tools]# mv resin-3.1.13  /application/

[root@data-1-1 tools]# ln -s /application/resin-3.1.13/ /application/resin

[root@data-1-1 tools]# ls -l /application/

lrwxrwxrwx  1 root root   26 Nov 29 01:39 resin -> /application/resin-3.1.13/

 

resin配置文件说明及修改

[root@data-1-1 ~]# cd /application/resin/conf

[root@data-1-1 conf]# diff resin.conf  resin.conf.orig

[root@data-1-1 ~]# vim +88 /application/resin/conf/resin.conf   -->删除默认配置文件的88-146行。加入如下内容

 

<!-- resin Configure at 2016-1-11 -->

<server id='peng' address='192.168.1.140' port='6911' watchdog-port="6921">

    <http address="*" port="8080"/>

    <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>

 

 

要删除的内容:

88        <server-default>

    89        <!-- The http port -->

    90        <http address="*" port="8080"/>

    91

    92        <!--

    93           - SSL port configuration:

    94           -

    95           - <http address="*" port="8443">

    96           -   <openssl>

    97           -     <certificate-file>keys/gryffindor.crt</certificate-file>

    98           -     <certificate-key-file>keys/gryffindor.key</certificate-key-file>

    99           -     <password>test123</password>

   100           -   </openssl>

   101           - </http>

   102          -->

   103

   104        <!--

   105           - The JVM arguments

   106          -->

   107        <jvm-arg>-Xmx256m</jvm-arg>

   108        <jvm-arg>-Xss1m</jvm-arg>

   109        <jvm-arg>-Xdebug</jvm-arg>

   110        <jvm-arg>-Dcom.sun.management.jmxremote</jvm-arg>

   111

   112        <!--

   113           - Uncomment to enable admin heap dumps

   114           - <jvm-arg>-agentlib:resin</jvm-arg>

   115          -->

   116

   117        <!--

   118           - arguments for the watchdog process

   119          -->

   120        <watchdog-jvm-arg>-Dcom.sun.management.jmxremote</watchdog-jvm-arg>

   121        <watchdog-port>6600</watchdog-port>

   122

   123        <!--

   124           - Configures the minimum free memory allowed before Resin

   125           - will force a restart.

   126          -->

   127        <memory-free-min>1M</memory-free-min>

   128

   129        <!-- Maximum number of threads. -->

   130        <thread-max>256</thread-max>

   131

   132        <!-- Configures the socket timeout -->

   133        <socket-timeout>65s</socket-timeout>

   134

   135        <!-- Configures the keepalive -->

   136        <keepalive-max>128</keepalive-max>

   137        <keepalive-timeout>15s</keepalive-timeout>

   138

   139        <!--

   140           - If starting bin/resin as root on Unix, specify the user name

   141           - and group name for the web server user.

   142           -

   143           - <user-name>resin</user-name>

   144           - <group-name>resin</group-name>

   145          -->

   146      </server-default>

 

以上参数说明如下:

!-- resin Configure at 2016-1-11 -->

<server id='peng' address='192.168.1.140' port='6911' watchdog-port="6921">

<http address="*" port="8080"/>

 

<!--最大堆大小>

     <jvm-arg>-Xmx1024M</jvm-arg>

 

<!—初始堆大小,在用户生产环境上一般将这Xmx和Xms设为相同,以减少运行期间系统在内存申请上所花的开销。-->

<jvm-arg>-Xms1024M</jvm-arg>

 

<!--Newsize和MaxNewSize在用户生产环境上一般设为相同,以减少运行期间系统在内存申请上所花的开销。-->

<jvm-arg>-XX:NewSize=512M</jvm-arg>

<jvm-arg>-XX:MaxNewSize=512M</jvm-arg>

 

<!—设置每个线程的stack大小-->

<jvm-arg>-Xss1024k</jvm-arg>

 

<!--年轻代和年老代的比值-->

     <jvm-arg>-XX:NewRatio=2</jvm-arg>

 

<!--设置最大永久区大小,永久保存区用于存放Class信息和元信息-->

     <jvm-arg>-XX:MaxPermSize=100M</jvm-arg>

 

<!--客户端连接rmi服务端,数据返回的超时时间,单位为毫秒-->

     <jvm-arg>-Dsun.rmi.transport.tcp.responseTimeout=5000</jvm-arg>

 

<!--当jvm的内存小于这个指定值,resin服务会gracefully重启,来释放泄露的内存空间-->

     <memory-free-min>1M</memory-free-min>

     <thread-max>800</thread-max>

 

<!--读写socket最大超时时间-->

     <socket-timeout>15s</socket-timeout>

 

<!--最大长连接数量-->

      <keepalive-max>256</keepalive-max>

 

<!--长连接超时时间-->

    <keepalive-timeout>5s</keepalive-timeout>

 

提示:可以把<http address="*" port="8080"/>里的8080改成80,把resin配置成独立的web server,就是可以不使用Apache,直接使用resin做为web服务器。官方宣称:resin web server性能很牛。

 

启动resin

[root@data-1-1 ~]# /application/resin/bin/httpd.sh -server peng start

[root@data-1-1 ~]# netstat -tunlp |egrep "6911|6921|8080"           

tcp        0      0 ::ffff:192.168.1.140:6911   :::*                        LISTEN      10298/java         

tcp        0      0 ::ffff:127.0.0.1:6921       :::*                        LISTEN      10269/java          

tcp        0      0 :::8080                     :::*                        LISTEN      10298/java    

提示:

8080 --->resin web server的端口,如果不需要resin做web server,可以关掉这个配置。

6921 --->watchdog的端口

6911 --->真正的resin端口,这个必须要起来,将来在Apache里就是把请求抛给这个端口解析的。

命令帮助:

[root@data-1-1 ~]# /application/resin/bin/httpd.sh -h

unknown argument '-h'

 

usage: java -jar resin.jar [-options] [status | start | stop | restart | kill | shutdown]

 

where options include:

   -conf <file>          : select a configuration file

   -log-directory <dir>  : select a logging directory

   -resin-home <dir>     : select a resin home directory

   -root-directory <dir> : select a root directory

   -server <id>          : select a <server> to run

   -watchdog-port <port> : override the watchdog-port

   -verbose              : print verbose starting information

 

浏览器查看页面

用http://hostip:8080访问resin的默认页面

192.168.1.140:8080/

http://192.168.1.140:8080/

查看的结果如下:

 

出现上面的页面显示,则说明resin服务配置OK了!

 

jsp文件默认路径存放在

[root@data-1-1 ~]# ll /application/resin/webapps/ROOT/

total 8

-rw-r--r-- 1 root root 1507 Nov  9  2012 index.jsp

drwxr-xr-x 5 root root 4096 Nov 29 04:30 WEB-INF

 

[root@data-1-1 ~]# echo '99+1=<%=99+1%>' >/application/resin/webapps/ROOT/test.jsp

[root@data-1-1 ~]# cat /application/resin/webapps/ROOT/test.jsp

99+1=<%=99+1%>

[root@data-1-1 ~]# curl http://192.168.1.140:8080/test.jsp

99+1=100

 

开发启动脚本

[root@data-1-1 ~]# cat /etc/init.d/resin-peng

#!/bin/bash

. /etc/init.d/functions

StartPath='/application/resin/bin/httpd.sh'

ResinLog=/app/logs/resinlog

[ ! -d $ResinLog ] && mkdir -p $ResinLog

resind () {

  #如果是多进程增加上面的配置段即可。

  for id in peng

   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 10

        netstat -lnt |egrep "80|69"

        echo "--------checkover-----"

        ;;

  stop)

        resind $1

        ;;

  restart)

         resind stop

         resind start

        ;;

    *)

       echo "Usage: $0 {start|stop|restart}"

       exit 1

  esac

   exit 0

赋予权限:

[root@data-1-1 ~]# chmod +x /etc/init.d/resin-peng

 

测试结果:

[root@data-1-1 ~]# /etc/init.d/resin-peng restart

stop peng resin...                                         [  OK  ]

start peng resin...                                        [  OK  ]

配置resin开机自启动说明

脚本如下:

[root@data-1-1 ~]# cat /etc/init.d/resin-peng

#!/bin/bash

#author at 20160111

#linux startup script for Resin

# chkconfig: 345 85 15

# description: Resin is a Java Web server.

#              

#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 () {

  #如果是多进程增加上面的配置段即可。

  for id in peng

   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 10

        netstat -lnt |egrep "80|69"

        echo "--------checkover-----"

        ;;

  stop)

        resind $1

        ;;

  restart)

         resind stop

         resind start

        ;;

    *)

       echo "Usage: $0 {start|stop|restart}"

       exit 1

  esac

   exit 0

 

加入到chkconfig中:

[root@data-1-1 ~]# chkconfig --add /etc/init.d/resin-peng

[root@data-1-1 ~]# chkconfig --list resin-peng

resin-peng      0:off   1:off   2:off   3:on    4:on    5:on    6:off

 

启动resin服务异常解决办法

[root@data-1-1 ~]# cat /app/logs/resinlog/resin_startup.log

Resin/3.1.13 started -server 'peng' for watchdog at 127.0.0.1:6921

Resin/3.1.13 stopped -server 'peng' for watchdog at 127.0.0.1:6921

Resin/3.1.13 started -server 'peng' for watchdog at 127.0.0.1:6921

提示:/app/logs/resinlog/resin_startup.log这个日志路径是启动脚本里定义的。

 

posted on 2018-09-26 14:51  五光十色  阅读(7030)  评论(0编辑  收藏

导航