有两年多没有使用resin了,最近打算在机器上安装一个web container跑点java web app,同时也可能需要支持php,原本打算用apache + tomcat,apache可以加载php模块来提供php支持,tomcat作为java web container。但突然想到resin,似乎是可以直接支持php的,而且resin的速度也是稍微快于tomcat,于是跑到resin的官网看了一下,恩,新出了4.0版本(惭愧,两年前用的是3.0或者3.1)。
决定用resin试试,老朋友了。但是在安装过程中,发现了一系列问题,尤其是设置开机自动启动,记录下来提供大家参考。
家里有台服务器,原来安装的是ubuntu 9.10的desktop版本,主要是考虑到ubuntu在作为桌面时非常不错,顺便做服务器。
(1) 下载
从resin的官网 下载到最新的linux版本4.0.5:
http://www.caucho.com/download/resin-4.0.5.tar.gz。
(2) 安装
先解压缩,然后重名为resin
问题1. ubuntu下JAVA_HOME出错
在这里遇到一个特别奇怪的问题,我明明设置了JAVA_HOME而且肯定路径是有效的,但是resin就是报错:
检查env:
再看目标路径/ usr / local / java / jdk1. 6 ,没有问题。有点郁闷,莫名其妙,于是找到resin官网的说明文档resin installation quick start ,发现一句话,"On Unix, set the JAVA_HOME variable or link /usr/java to the java home."。 好吧,试试/usr/java这个办法,
再执行configure就不再出错了(补充,这个问题只在ubuntu 9.10出现,后来在suse sles11上没有出现,sles只要JAVA_HOME正确就可以了),接着
安装完成,但是报错,应该是没有/etc/init.d/resin的写权限,这样就无法实现开机自动启动resin。
启动resin,然后用浏览器访问http://192.168.0.40:8080/,成功。
(3) 快捷设置
1. 为了方便使用resin,编辑.profile文件,加入一些别名:
#resin
RESIN_HOME=/work/soft/resin
alias cd_resin="cd $RESIN_HOME"
alias resin_start="$RESIN_HOME/bin/resin.sh start"
alias resin_stop="$RESIN_HOME/bin/resin.sh stop"
alias resin_restart="$RESIN_HOME/bin/resin.sh restart"
执行 source .profile导入。
(4) 开机自动运行
问题2: ubuntu 下开机自动运行设置无效
以前install / etc / init.d / resin失败, 只好自己动手了,将resin/init.d/resin(make 后生成) 这个文件复制过去:
重启之后,发现resin没有启动起来。反复检查init.d/rc.d的设置,google了n多文档,实验了很多次,始终都是无效!!极其郁闷。
后来看到一些说法,ubuntu在很多设置上和一般常见的linux发行版本不大相同,比如没有chkconfig,需要使用update - rc.d等,考虑一般也不怎么用linux桌面,ubuntu在server上用的比较少。手头又正好有个suse sles 11的安装盘,于是一时冲动,决定换个linux版本,以后用suse好了。(从后面的情况,问题不在ubuntu上,算是我冤枉ubuntu了)。
suse安装的过程不提,后面会有单独的文章做安装记录。安装好之后,直奔主题,安装jdk和resin。一路顺风,直到再次执行到安装resin的开启启动
问题3. suse slse 11 下启动自动运行设置无效
上面算是标准的resin开机启动设置了,结果重启后发现无效。很郁闷,linux版本都换了,还是同样结果。
试着直接使用/ etc / init.d / resin来启动resin,模拟开机时的系统调用:
意外发现上面的错误提示,打开/ etc / init.d / resin ,以下是启动的脚本片段:
从这个if语句看,如果/ lib / lsb / init - functions存在就载入 / lib / lsb / init - functions的内容,否则就自己定义相关的两个函数。vi打开 / lib / lsb / init - functions,发现问题:里面根本没有 log_daemon_msg() / log_end_msg()两个方法!
解决的方法简单,删除掉这个if,直接使用自定义的函数好了。
之后重新执行,resin正常启动,resin的初始化页面可以访问。
很高兴的重启suse,结果还是发现有问题,resin没有起来!继续,ps看进程发现resin 的watchdog进程启动了,但是resin的进程没有起来。找到resin的log,发现在watchdog-manager.log中有大量的异常:
怀疑是这个造成的,watch dog 启动resin时遭遇异常,因此resin没有启动,而watch dog的进程在,和ps的结果符合。实验了一下,删除所有log文件。使用/etc/init.d/resin start命令直接启动resin,成功,查看日志文件没有异常。
再次清空日志文件,重启resin,启动后ps看进程,并查看watchdog-manager.log,上面的现象重现。问题就应该在这里了,"www - data is an unknown user ",用命令看了一下的确系统中不存在所谓的www-data用户,因此问题聚焦到,www-data是哪里冒出来的?很明显直接启动resin时是不会遇到这个问题的。
google "www-data resin"有所发现:在caucho的wiki发现对此的描述:
http://wiki.caucho.com/Migrating_from_Resin_3.0_to_Resin_4.0
问题应该在这里了,如果当前用户是root(开机启动时当然只能是root),resin就会使用这里设置的user/group,resin配置文件中默认是www-data/www-data,而这www-data/www-data肯定是不会默认存在的,因此造成上述resin无法启动的问题。
打开resin/conf/resin.xml,找到以下内容:
修改user-name/gourp-name为有效user/group,保存。重启suse,这次resin终于正常的启动了,不容易啊。这个www-data的问题估计是resin4.0版本之后带入的,因为以前用3.0版本没有发现类似问题。奇怪的是,resin的安装文档中绝口不提这个东东,呵呵,浪费我不少时间。