uiyujyht 发表于 2016-9-5 14:56:22

resin安装与配置

resin是CAUCHO公司的产品,是一个非常流行的支持servlets和jsp的引擎,速度非常快。resin本身包含了一个支持HTTP/1.1的WEB服务器。虽然它可以显示动态内容,但是它显示静态内容的能力也非常强,速度直逼nginx server。许多站点都是使用该web服务器构建的。    resin支持负载均衡,可以增加web站点的可靠性。方法是增加服务器的数量。比如一台server的错误率是1%的话,那么支持负载均衡的两个resin服务器就可以是错误率降到0.01%
resin官方网站:http://www.caucho.com
首先安装jdk,这里选择的是jdk7
curl -LO -H "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/7u75-b13/jdk-7u75-linux-x64.rpm" -k
rpm -ivh jdk-7u75-linux-x64.rpm
然后配置环境变量
vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/java/jdk1.7.0_75               
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
. /etc/profile.d/java.sh

jdk环境有了,于是安装resin,这里选择的版本为resin-4.0.44.tar.gz
wget http://caucho.com/download/resin-4.0.44.tar.gz
tar xf resin-4.0.44.tar.gz
cd resin-4.0.44
./configure --prefix=/usr/local/resin4.0.44 --with-java-home=/usr/java/jdk1.7.0_75/ --enable-64bit
make && make install
# ln -sv resin4.0.44/ /usr/local/resin
"/usr/local/resin" -> "resin4.0.44/"

配置resin环境变量
vim /etc/profile.d/resin.sh
export RESIN_HOME=/usr/local/resin
export PATH=${RESIN_HOME}/bin:$PATH
source /etc/profile.d/resin.sh
resin安装成功后各目录

备份好配置文件

# cp resin.xml resin.xml.bak
# cp resin.properties resin.properties.bak
启动resin服务:

# ../bin/resinctl start
Resin/4.0.44 launching watchdog at 127.0.0.1:6600
Resin/4.0.44 started -server 'app-0' with watchdog at 127.0.0.1:6600
查看java主要进程

# jps
28963 Resin
28997 Jps
28917 WatchdogManager
# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp      0      0 127.0.0.1:6800            0.0.0.0:*                   LISTEN      28963/java                  
tcp      0      0 127.0.0.1:6600            0.0.0.0:*                   LISTEN      28917/java         
tcp      0      0 :::8080                     :::*                        LISTEN      28963/java         
浏览器尝试访问如下图



配置resin-admin这个uri:

编辑配置文件vim resin.properties
# Access to /resin-admin and remote CLI is password restricted.
# Use "resinctl generate-password" and copy/paste here to set the admin
# admin_user : admin
# admin_password : {SSHA}xxxxxxxx
注释信息很详细,于是使用如下命令配置
# resinctl generate-password my-admin mypassword
admin_user : my-admin
admin_password : {SSHA}eZYiiZTQCO9XQbcrUfQq1Br57Q2zrCJQ
用户名:my-admin
密码:mypassword将生成的两行信息复制到配置文件中
修改完配置文件,然后重启
# /etc/init.d/resin restart
Stopping resin: .
Starting resin: .
观察日志信息,看是否报错

# ll
总用量 28
-rw-r--r--. 1 root root 8867 9月   4 20:47 access.log
-rw-r--r--. 1 root root154 9月   4 20:53 console.log
-rw-r--r--. 1 root root 6284 9月   4 20:53 jvm-app-0.log
-rw-r--r--. 1 root root 3470 9月   4 20:53 watchdog-manager.log
# pwd
/usr/local/resin/log

从日志中可以看出很多信息,方便进行查错
再次访问resin-admin,并输入账号密码

从管理界面可以看出很多内容,这里不详细介绍,自行查看

根据resin官方阐述,resin也能做web服务器,于是配置虚拟主机,看看效果
编辑配置文件vim resin.xml
<cluster id="app">
    <server-multi id-prefix="app-" address-list="${app_servers}" port="6800"/>
    <host-default>
      <web-app-deploy path="webapps"
                      expand-preserve-fileset="WEB-INF/work/**"
                      multiversion-routing="${webapp_multiversion_routing}"
                      path-suffix="${elastic_webapp?resin.id:''}"/>
    </host-default>
    <host-deploy path="hosts">
      <host-default>
      <resin:import path="host.xml" optional="true"/>
      </host-default>
    </host-deploy>
    <host id="" root-directory=".">
      <web-app id="/" root-directory="webapps/ROOT"/>
    </host>
    <resin:if test="${resin_doc}">
      <host id="${resin_doc_host}" root-directory="${resin_doc_host}">
      <web-app id="/resin-doc" root-directory="${resin.root}/doc/resin-doc"/>
      </host>
    </resin:if>
</cluster>
这里是摘出来的一段默认的cluster配置,这里大致介绍下配置参数的含义,更多详细内容参考官方文档
<cluster id="app">   cluster是标签,id是The cluster identifier.,cluster的标识符,下面的server标签中的id也是类似
<server-multi id-prefix="app-" address-list="${app_servers}" port="6800"/>
server-multi:相当于多个server组合,id-prefix:以某某为前缀的组合,这里是以app-
address-list="${app_servers}":指一个address列表,这里参考配置文件resin.properties中
app_servers      : 127.0.0.1:6800这个参数,当然也可以不使用宏定义,而以下面的方式
<server-multi id-prefix="app-" address-list="192.168.1.2 192.168.1.3" port="6800"/>
port="6800":指监听的tcp端口
<host id="" root-directory=".">      <web-app id="/" root-directory="webapps/ROOT"/></host>host id="" root-directory=".":这里的id指的是主机名域名,相当于是www.baidu.com,官方解释是primary host name
root-directory=".":Root directory for host files                parent directory
这里的.指的是resin的家目录
当然host标签还有其他参数:

regexp                                Regular expression based host matching        none
host-name                        Canonical host name                        none
host-alias                        Aliases matching the same host                        none
secure-host-name        Host to use for a redirect to SSL                        none

<web-app id="/" root-directory="webapps/ROOT"/>:这里的id指的是The url prefix selecting this application.,也就是uri这里就是www.baidu.com/最后的/
root-directory="webapps/ROOT":The root directory for the application, corresponding to a url of /id/. A relative path is relative to the <root-directory> of the containing <host>. Can use regexp replacement variables.我理解为网站的根目录
因为ROOT下面就是index,jsp也就是www.baidu.com/index.jsp

好了,接下来新增一个host主机名
<host id="www.hcstart.com" root-directory="/www">
      <!--
         - webapps can be overridden/extended in the resin.xml
      -->
      <web-app id="/" root-directory="html"/>
</host>
创建好网站目录,mkdir -p /www/html

编辑jsp文件,vim /www/html/index.jsp
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<html>
<head>
    <title>JSP Test Page</title>
</head>
<body>
    <%
        out.println("Hello world!");
    %>
</body>
</html>
然后重启resin服务,查看日志信息,观察浏览器信息


于是添加host信息成功

接下来为resin创建多实例,也就是绑定多个http port,这里介绍两种方式
1、注释掉配置文件resin.properties中的某些行,具体操作如下
app_servers      : 127.0.0.1:6800
app.http          : 8080
注释掉这两行
然后修改配置文件resin.xml
<cluster id="app">
      <server id="app-0" address="192.168.1.113" port="6800">
      <http port="80"/>
      </server>
      <host id="www.hcstart.com" root-directory="/www">
      <web-app id="/" root-directory="html"/>
      </host>
</cluster>
精简了配置文件,于是再为cluster中添加一个server,一个host,于是
<cluster id="app">
      <server id="app-0" address="192.168.1.113" port="6800">
      <http port="80"/>
      </server>
      <host id="www.hcstart.com" root-directory="/www">
      <web-app id="/" root-directory="html"/>
      </host>
      <server id="app-1" address="192.168.1.113" port="6801">
      <http port="8080"/>
      </server>   
      <host id="www.hcstart.com" root-directory="/www">
      <web-app id="/" root-directory="blog"/>
      </host>
</cluster>
然后重启resin服务,发现端口并没有如实出现,于是查看日志信息

从报错信息可以看出,一个cluster中不能支持多个server实例,要想支持必须使用商业版
于是做如下修改,增加cluster,并配置server以及host
<cluster id="app">
      <server id="app-0" address="192.168.1.113" port="6800">
      <http port="80"/>
      </server>
      <host id="www.hcstart.com" root-directory="/www">
      <web-app id="/" root-directory="html"/>
      </host>
</cluster>

<cluster id="mycluster">
      <server id="app-1" address="192.168.1.113" port="6801">
      <http port="8080"/>
      </server>
      <host id="www.hcstart.com" root-directory="/www">
      <web-app id="/" root-directory="blog"/>
      </host>
</cluster>
然后再次重启,查看端口
# netstat -tunlp|grep java
tcp      0      0 192.168.1.113:6800          0.0.0.0:*                   LISTEN      31066/java         
tcp      0      0 192.168.1.113:6801          0.0.0.0:*                   LISTEN      31074/java         
tcp      0      0 127.0.0.1:6600            0.0.0.0:*                   LISTEN      31015/java         
tcp      0      0 :::8080                     :::*                        LISTEN      31074/java         
tcp      0      0 :::80                     :::*                        LISTEN      31066/java
访问浏览器,比较端口80和8080的变化

至此一个主机多实例搞定,采用第二种方法
2、修改配置文件resin.properties
app_servers      : 127.0.0.1:6800
app1_servers      : 127.0.0.1:6801
app2_servers      : 127.0.0.1:6802

app.http          : 8080
app1.http          : 8081
app2.http          : 8082
然后修改配置文件resin.xml,如下

<cluster id="app1">   这里的cluster要和resin.properties配置文件那里定义好的ip和端口要一致
      <server-multi id-prefix="${app1.http}" address-list="${app1_servers}" port="6801"/>
      <host id="www.hcstart.com" root-directory="/www">
      <web-app id="/" root-directory="html"/>
      </host>
</cluster>
<cluster id="app2">   这里的cluster要和resin.properties配置文件那里定义好的ip和端口要一致
      <server-multi id-prefix="${app2.http}" address-list="${app2_servers}" port="6802"/>
      <host id="www.hcstart.com" root-directory="/www">
      <web-app id="/" root-directory="blog"/>
      </host>
</cluster>
查看端口状态

# netstat -tunlp|grep java
tcp      0      0 127.0.0.1:6801            0.0.0.0:*                   LISTEN      33991/java         
tcp      0      0 127.0.0.1:6802            0.0.0.0:*                   LISTEN      33999/java         
tcp      0      0 127.0.0.1:6600            0.0.0.0:*                   LISTEN      33943/java         
tcp      0      0 :::8081                     :::*                        LISTEN      33991/java         
tcp      0      0 :::8082                     :::*                        LISTEN      33999/java   
查看浏览器效果



结合nginx做负载均衡,还是在一个服务器上做实验
安装nginx:yum -y install nginx
配置nginx:vim /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_namewww.hcstart.com;
配置修改:vim /etc/nginx/nginx.conf
upstream www.hcstart.com {
      server 192.168.1.113:8081 weight=1;
      server 192.168.1.113:8082 weight=1;
    }
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# service nginx start
正在启动 nginx:                                           [确定]
观察浏览器效果:


当然也可以结合nginx做动态分离,但resin服务也支持静态页面,所以这个改如何设计架构还是得看业务模式,这里只是简单的介绍了resin的使用,更多信息查看官网
http://caucho.com/resin-4.0/admin/config-resin-xml.xtp

页: [1]
查看完整版本: resin安装与配置