公司的业务平台采用Resin做web前端程序.下面简单介绍一下Resin:(摘自百度百科)

 

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

 

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

 

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

配置安装resin非常简单

 

首先需要安装JDK,在Sun网站下载一个自解压包.jdk-6u3-linux-i586.bin 然后设为可执行

#chmod 700 jdk-6u3-linux-i586.bin

#./jdk-6u3-linux-i586.bin

阅读完长长的许可协议后输入yes同意,就开始解压缩了,然后把解压缩生成的目录移动到/usr下

#mv jdk1.6.0_03/ /usr/jdk1.6

接下来需要设置java的环境变量JAVA_HOME等.

#vi /etc/profile

在最后加入

export JAVA_HOME=/usr/jdk1.6

export  PATH=$JAVA_HOME/bin:$PATH

export CLASSPATH=.:$JAVA_HOME/lib/rt.jar:$JAVA_HOME/lib/tools.jar

然后执行

#source /etc/profile

看一下我们设置的环境变量是否生效

#export

[root@www ~]# export

declare -x CLASSPATH=".:/usr/jdk1.6/lib/rt.jar:/usr/jdk1.6/lib/tools.jar"

declare -x CVS_RSH="ssh"

declare -x G_BROKEN_FILENAMES="1"

declare -x HISTSIZE="1000"

declare -x HOME="/root"

declare -x HOSTNAME="[url]www.cooler.com[/url]"

declare -x INPUTRC="/etc/inputrc"

declare -x JAVA_HOME="/usr/jdk1.6"

declare -x LANG="zh_CN.UTF-8"

declare -x LANGUAGE="en_US"

declare -x LESSOPEN="|/usr/bin/lesspipe.sh %s"

declare -x LOGNAME="root"

declare -x LS_COLORS="no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:"

declare -x MAIL="/var/spool/mail/root"

declare -x OLDPWD="/root/resin-pro-3.1.3"

declare -x PATH="/usr/jdk1.6/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"

declare -x PWD="/root"

declare -x SHELL="/bin/bash"

declare -x SHLVL="1"

declare -x SSH_ASKPASS="/usr/libexec/openssh/gnome-ssh-askpass"

declare -x SSH_CLIENT="192.168.1.109 3665 22"

declare -x SSH_CONNECTION="192.168.1.109 3665 192.168.1.119 22"

declare -x SSH_TTY="/dev/pts/0"

declare -x TERM="vt100"

declare -x USER="root"

可以看到,新的变量已经加上了.

接下来看看jdk的版本

#java -version

java version "1.6.0_03"

Java(TM) SE Runtime Environment (build 1.6.0_03-b05)

Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)

看到以上提示说明jdk安装好了.

#configure --prefix=/usr/local/resin

#make

#make install

测试一下我们安装的resin

#java -jar /usr/local/resin/lib/resin.jar

或者resin/bin/httpd.sh

接下来访问[url]http://localhost:8080[/url]

如果能看到页面,ok,装好了

 

到这里,只是一个开始,作为生产环境,我们还需要进行一些调整

1.创建一个用户来运行Resin(例如resin或者其他的非root用户)

 

When deploying, it's a good idea to create a bit of structure to make Resin and website upgrades easier and more maintainable.

Create a user to run Resin (e.g. resin or another non-root user)

Link /usr/local/share/resin to the current Resin version. This is $RESIN_HOME.

Create a deployment root, e.g. /var/www, owned by the resin user. This is $RESIN_ROOT.

Put the modified resin.conf in /etc/resin/resin.conf

Put the site documents in /var/www/webapps/ROOT.

Put any .war files in /var/www/webapps.

Put any virtual hosts in /var/www/hosts/www.foo.com.

Output logs will appear in /var/www/log.

Create a startup script and configure the server to start it when the machine reboots.

start/stop and the watchdog process

In a deployment environment, Resin will be started with "start", "stop", and "restart" arguments to the resin.jar, e.g.

 

 

上次的文章中,学习了resin的初步配置
RESIN除了可以配置为独立的WEB SERVER,还能和apache整合起来,由apache处理静态的内容,由resin处理jsp,selvet
英语好的可以直接去看官方文档
[url]http://www.caucho.com/resin-3.1/doc/install-apache.xtp[/url]
本文以RESIN3.0.25为例,需要如下步骤:
1.编译apache
如果apache已经安装,需要检查apache是否支持DSO,用如下命令来检查
# /usr/local/apache/bin/httpd -l
Compiled-in modules:
  ...
  mod_so.c
  ...
如果有mod_so.c,说明支持DSO.
如果不支持,或者想重新安装一个新apache,可以用源码来重新编译一个
# ./configure --prefix=/usr/local/apache --enable-module=so
# make
# make install
2.编译mod_caucho.so模块
解压缩resin的源码,(编译RESIN前需要安装JDK,并设置好JDK)
# ./configure --with-apxs=/usr/local/apache/bin/apxs
# make
# make install
如果不知道apxs的路径可以用# ./configure --with-apache=/usr/local/apache
指定apache的路径也可以
完成后,应该在apache的modules目录下生成mod_caucho.so这个模块文件
3.设置环境变量
resin的运行需要设置JAVA_HOME,RESIN_HOME和CLASSPATH可以不设
修改~/.profile or /etc/profile
vi ~/.profile
# Java Location
JAVA_HOME=/<installdir>/jdk1.4
export JAVA_HOME
# Resin location (optional).  Usually Resin can figure this out.
RESIN_HOME=/<installdir>/resin-3.1.2
export RESIN_HOME
# If you're using additional class libraries, you'll need to put them
# in the classpath.
CLASSPATH=
4.设置resin.conf
编译resin的配置文件.修改粗体部分
#vi conf/resin.conf
    <cluster>      <srun server-id="" host="127.0.0.1" port="6802"/>    </cluster>
server-id 可以自己定义,resin如果不和apache在同一台机器,host后改为resin的ip,port
将resin的默认文档目录与apache的DocumentRoot设为一致的目录
<host id="">
      <web-app id='/' document-directory="/usr/local/apache/htdocs"/>
</host>
启动resin
# bin/httpd.sh
编写一个jsp文件来测试resin是否正常
创建一个文件#vi /usr/local/apache/htdocs/test.jsp
2 + 2 = <%= 2 + 2 %>
在浏览器中浏览[url]http://localhost:8080/test.jsp[/url]如果能看到2 + 2 = 4
说明resin正常 修改apache设置编译resin成功后会自动修改apache的httpd.conf,加入如下内容,
如果没有自动添加,应该手动添加如下内容
LoadModule caucho_module libexec/mod_caucho.so
ResinConfigServer localhost 6802
<Location /caucho-status>
  SetHandler caucho-status
</Location>
5.重启apache和后端resin再次测试jsp文件和html文件,[url]http://localhost/test.jsp[/url]如果可以看到页面,说明配置成功了.

本文出自 “风吹云动” 博客,请务必保留此出处http://coolerfeng.blog.51cto.com/133059/54422