zoukankan      html  css  js  c++  java
  • resion 学习笔记

    resin是一个非常流行的web引用服务器,对servlet和jsp提供了良好的支持,自身采用java开发,支持集群,还支持PHP。

    resin分为普通版和专业版,主要区别是专业版支持缓存和负载均衡。

    一、配置安装

    1、安装jdk

    # tar -xf jdk-8-linux-x64.tar.gz -C /application/    
    # ln -s  /application/jdk1.8.0_60   /application/jdk 

    方法一、

    # sed -i.ori '$a export JAVA_HOME=/application/jdk
    export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
    export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar' /etc/profile

    方法二、

    # echo '#java env  config ' >>/etc/profile
    # echo 'export JAVA_HOME=/application/jdk' >>/etc/profile
    # echo 'export CLASSPATH=$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 'export RESON_HOME=/application/resin' >>/etc/profile

    生效及检查版本

    # source /etc/profile 
    # java -version

    2、安装resin

    # cd /home/nulige/tools/
    # tar xf resin-3.1.13.tar.gz
    # mv resin-3.1.13 /application/
    # ln -s /application/resin-3.1.13/ /application/resin
    # ls -l /application/resin/

    3、配置resin 

    # ls   /application/resin/conf
    app-default.xml development.conf fine.conf minimal.conf resin.conf resin.conf.orig 
    # vim   /application/resin/conf/resin.conf

    从88行开始删除到146行,(快整跳到88行,用快捷键:88gg) 再用快捷键:59dd (删除59行内容)

    #再添加下面代码到删除的地方,并注意:server id= xxx,是指启动时指定的标签,地址就是本机网卡地址,端口不用改。

    <http address="*" port="8080"/> #如果做web服务用,就把端口修改成80。

    添加代码如下:

    <!-- resin Configure  -->
    <server id='oldboy' address='10.0.0.8' port='6911' watchdog-port="6921"> # 6911:真正resin端口,6921:watchdog端口
    <http address="*" port="8080"/>   #8080:resin web server端口
    <jvm-arg>-Xmx256m</jvm-arg>       #最大堆大小
    <jvm-arg>-Xss1m</jvm-arg>         #初始堆大小,一般xmx和xss值是相同的,避免运行时内存不足,系统在内存申请的花销
    <jvm-arg>-Xdebug</jvm-arg>
    <jvm-arg>-Dcom.sun.management.jmxremote</jvm-arg>
    <memory-free-min>1M</memory-free-min>        #当jvm的内存小于这个指定值,resin服务会gracefully重启,来释放泄露的内存空间
    <thread-max>256</thread-max>
    <socket-timeout>65s</socket-timeout>         #读写socket最大超时时间
    <keepalive-max>128</keepalive-max>           #最大长连接数量
    <keepalive-timeout>15s</keepalive-timeout>   #长连接超时时间
    </server>

    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 # ps -ef|grep java

    5、配置站点目录

    # cd   /application/resin/webapps/ROOT/
    # echo '<99+1=<%=99+1>' >/application/resin/webapps/ROOT/test.jsp # cat /application/resin/webapps/ROOT/test.jsp # curl http://192.168.1.8:8080/test.jsp

    6、配置启动方式

    1)系统自带的启动脚本

    # cp /application/resin/contrib/init.resin.in   /etc/init.d/resind
    # chmod +x /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
    # chkconfig resind on
    # chkconfig --list resind
    # echo “/home/tom/init.d/resind  start ” >>/etc/rc.local

     二、整合 appche + resin

    1、安装appche

    # yum -y install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel 
    # ./configure --prefix=/application/apache2.2.23
    --enable-deflate 
    --enable-headers 
    --enable-modules=so 
    --enable-so 
    --with-mpm=worker 
    --enable-rewrite
    # make && make install

    2、为apache编译resin mod_caucho 模块

    # cd /application/resin-3.1.13
    # ./configure --with-apxs=/application/apache2.2.23/bin/apxs
    # cd /application/resin/modules/c/src/
    # make  && make install
    # ls -l  /application/apache/modules/
    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:解析动态网页
    # vim /application/apache/conf/httpd.conf 到结尾,修改内容
    ResinConfigServer 192.168.1.8 6921
    SetHandler caucho-reques
    SetHandler caucho-reques是转发作用,由Apache把所有的请求转给resin。

    三、Apache虚拟主机+resin

    1、配置虚拟主机

    # cd /application/apache/conf/extra/
    # vim  httpd-vhosts.conf
    <VirtualHost *:80>
        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    
    </ViretualHost>

    2、修改Apache主配置文件内容:

    # vim /application/apache/conf/httpd.conf
    395  # Virtual hosts
    396  Include conf/extra/httpd-vhosts.conf     ---此行注释要打开
    
    # 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           ---这里注释掉!
    #SetHandler caucho-request
    CauchoConfigCacheDirectory /tmp
    CauchoStatus yes

     3、测试

    # echo "Apache"  >/var/www/a.html
    # echo "<%Apache=99+1%>"  >/var/www/a.jspApache
    # echo "<%resin=99+1%>"  >/application/resin/webapps/ROOT/a.jsp
    # curl www.abc.com/a.html
    Apache # curl www.abc.com
    /a.jsp
    resin=100

    四、Apache多虚拟主机+ resin多虚拟主机

    1、配置Apache虚拟主机

    # cat /application/apache/conf/extra/httpd-vhosts.conf
    NameVirtualHost *:80
    <VirtualHost *: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
     
       <Directory "/var/www">
       Options -Indexes  FollowSymLinks
       AllowOverride None
       Order allow,deny
       Allow from all
       </Directory>
    #Resin Configuration
    ResinConfigServer 192.168.1.140 6911
    SetHandler caucho-request
    </VirtualHost>
    ###########################
    <VirtualHost *:80>
        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
     
       <Directory "/var/blog">
       Options -Indexes  FollowSymLinks
       AllowOverride None
       Order allow,deny
       Allow from all
       </Directory>
    #Resin Configuration
    ResinConfigServer 192.168.1.140 6912
    #SetHandler caucho-request
    </VirtualHost>

    2、配置resin多虚拟机

    配置主配置     /application/resin/conf/resin.conf 

    <!-- resin Configure at 2018-1-11 -->
    <server id='abc' address='192.168.1.8' 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>
    
    #######################################
    <!-- resin Configure at 2018-1-11 -->
    <server id='abc01' address='192.168.1.8' port='6912' watchdog-port="6922">
    #   <http address="*" port="8081"/>
        <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>
    <!--Create first virtual hosts at 20180112.-->
      <host id="www.abc.com" root-directory="/application/resin/webapps">
        <host-alias>blog.abc.com</host-alias>
    <!--
      - configures an explicit root web-app matching the
      - webapp's ROOT
      -->
        <web-app id="/" root-directory="/application/resin/webapps/ROOT">
         <session-config cookie-domain="pp.org" reuse-session-id="true">
          <session-timeout>5</session-timeout>
          <session-max>12000</session-max>
           </session-config>
           <servlet-mapping servlet-class='com.caucho.servlets.ResinStatusServlet'>
            <url-pattern>/resin-status-abc.org</url-pattern>
             <init enable="read"/>
            </servlet-mapping>
             <error-page error-code='404' location='/tips/404.html'/>
       
        </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>
    ##################################
    <!--Create first virtual hosts at 20180112.-->
      <host id="www.abc.org" root-directory="/application/resin/webapps">
        <host-alias>blog.abc.org</host-alias>
    <!--
      - configures an explicit root web-app matching the
      - webapp's ROOT
      -->
        <web-app id="/" root-directory="/application/resin/webapps/org">
         <session-config cookie-domain="pp.org" reuse-session-id="true">
            <session-timeout>5</session-timeout>
            <session-max>12000</session-max>
             </session-config>
             <servlet-mapping servlet-class='com.caucho.servlets.ResinStatusServlet'>
               <url-pattern>/resin-status-abc.org</url-pattern>
                 <init enable="read"/>
             </servlet-mapping>
                 <error-page error-code='404' location='/tips/404.html'/>
    
         </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      <!-- <http address="*" port="8080"/> -->
    104     <!-- <http address="*" port="8081"/> -->

    3、测试

    # echo "<%com=99+1%>"   /application/resin/webapps/ROOT/a.jsp
    # echo "www.abc.com"    /application/resin/webapps/ROOT/a.html
    # echo "<%org=99+1%>"   /application/resin/webapps/org/a.jsp
    # echo "www.abc.org"    /application/resin/webapps/ROOT/a.html
    # echo "<%com=99-1%>"   /var/www/a.jsp
    # echo "apache www"     /var/www/a.html
    # echo "<%com=99-1%>"   /var/blog/a.jsp
    # echo "apache blog"    /var/blog/a.html
    # curl www.abc.cc/a.jsp
    com=100 # curl www.abc.cc
    /a.html
    www.abc.com # curl www.abc.org
    /a.jsp
    org=100 # curl www.abc.org
    /a.html
    apache blog

     4、理想结构图

  • 相关阅读:
    人民币格式化 ,分割
    解决IE下页面空白或者报错:[vuex] vuex requires a Promise polyfill in this browser
    js生成图片
    适用于iview的表格转Excel插件
    js金额转大写数字
    webstorm vue cli 热更新不起作用解决办法
    纯css实现 switch开关
    vue 时间戳转 YYYY-MM-DD h:m:s
    Simple2D-20(重构)
    Simple2D-19(音乐播放器)播放器的源码实现
  • 原文地址:https://www.cnblogs.com/wuhg/p/9698641.html
Copyright © 2011-2022 走看看