其实resin和tomcat类似,都是Java应用容器,现在的主流依旧是tomcat,用resin的比较少,他和tomcat比较起来没有很大的差别,我们这里大多数用的都是resin,tomcat也有,但是很少,resin专业版是收费的,当然也有破解jar包,支持负载均衡,个人感觉resin用起来比tomcat简单一些,还有就是要在一台服务器上运行多个实例会麻烦一些,不像tomcat复制一份改端口即可。下面是一些基础的配置和实现多实例的方法。
resin软件版本:resin-pro-4.0.47
jdk版本:jdk1.7.0_79
安装阶段
1.首先安装JAVA,并配置环境变量
[root@iZ2ze97fdsfodnhh1iuz4xZ ~]# tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local/ #解压
[root@iZ2ze97fdsfodnhh1iuz4xZ ~]# cat >>/etc/profile<<OEF
> export JAVA_HOME=/usr/local/jdk1.7.0_79/
> export PATH=\$JAVA_HOME/bin:\$PATH
> export CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:/lib/tools.jar
> OEF
[root@iZ2ze97fdsfodnhh1iuz4xZ ~]# source /etc/profile #使配置生效
2.查看是否配置成功
[root@iZ2ze97fdsfodnhh1iuz4xZ ~]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
3.开始安装resin
下面是我的一些编译参数,仅供参考
[root@iZ2ze97fdsfodnhh1iuz4xZ software]# tar zxf resin-pro-4.0.47.tar.gz
[root@iZ2ze97fdsfodnhh1iuz4xZ software]# cd resin-pro-4.0.47
[root@iZ2ze97fdsfodnhh1iuz4xZ resin-pro-4.0.47]# ./configure --prefix=/usr/local/resin --with-java-home=/usr/local/jdk1.7.0_79/ --with-resin-log=/www/resin1/jvm-log/ --with-resin-init-d=/etc/init.d/res
in
[root@iZ2ze97fdsfodnhh1iuz4xZ resin-pro-4.0.47]# make
[root@iZ2ze97fdsfodnhh1iuz4xZ resin-pro-4.0.47]# make install
4.启动resin 并查看日志,是否正常启动,看到以下内容,则正常启动
配置阶段
1.编辑配置文件,resin.xml,以下是一个配置模板,仅供参考
<!--
- Resin 4.0 configuration file.
-->
<resin xmlns="http://caucho.com/ns/resin"
xmlns:resin="urn:java:com.caucho.resin">
<!-- property-based Resin configuration -->
<resin:properties path="${__DIR__}/resin.properties" optional="true"/>
<resin:if test="${properties_import_url}">
<resin:properties path="${properties_import_url}"
optional="true" recover="true"/>
</resin:if>
<!-- Logging configuration for the JDK logging API -->
<log-handler name="" level="all" path="stdout:"
timestamp="[%y-%m-%d %H:%M:%S.%s]"
format=" {${thread}} ${log.message}"/>
<!--
- Alternative pseudo-TTCC log format
-
- <log-handler name="" level="all" path="stdout:"
- timestamp="%y-%m-%d %H:%M:%S.%s"
- format=" [${thread}] ${log.level} ${log.shortName} - ${log.message}"/>
-->
<!--
- level='info' for production
- 'fine' or 'finer' for development and troubleshooting
-->
<logger name="" level="${log_level?:'info'}"/>
<logger name="com.caucho.java" level="config"/>
<logger name="com.caucho.loader" level="config"/>
<!--
- Default configuration applied to all clusters, including
- HTTP, HTTPS, and /resin-admin configuration.
-->
<resin:import path="${__DIR__}/cluster-default.xml"/>
<!--
- health configuration
-->
<resin:import path="${__DIR__}/health.xml"/>
<!--
- Remote management requires at least one enabled admin user.
-->
<resin:AdminAuthenticator>
<user name="${admin_user}" password="${admin_password}"/>
<resin:import path="${__DIR__}/admin-users.xml" optional="true"/>
</resin:AdminAuthenticator>
<!--
- For clustered systems, create a password in as cluster_system_key
-->
<cluster-system-key>${cluster_system_key}</cluster-system-key>
<!--
- For production sites, change dependency-check-interval to something
- like 600s, so it only checks for updates every 10 minutes.
-->
<dependency-check-interval>${dependency_check_interval?:'2s'}</dependency-check-interval>
<!-- For resin.properties dynamic cluster joining -->
<home-cluster>${home_cluster}</home-cluster>
<home-server>${home_server}</home-server>
<elastic-server>${elastic_server}</elastic-server>
<elastic-dns>${elastic_dns}</elastic-dns>
<!--
- Configures the main application cluster. Load-balancing configurations
- will also have a web cluster.
-->
<cluster id="app">
<!-- define the servers in the cluster -->
<server-multi id-prefix="app-" address-list="${app_servers}" port="6800">
<jvm-arg-line>${jvm_argsa}</jvm-arg-line>
</server-multi>
<host-default>
<!-- creates the webapps directory for .war expansion -->
<web-app-deploy path="webapps"
expand-preserve-fileset="WEB-INF/work/**"
multiversion-routing="${webapp_multiversion_routing}"
path-suffix="${elastic_webapp?resin.id:''}"/>
</host-default>
<!-- auto virtual host deployment in hosts/foo.example.com/webapps -->
<host-deploy path="hosts">
<host-default>
<resin:import path="host.xml" optional="true"/>
</host-default>
</host-deploy>
<!-- the default host, matching any host name -->
<!-- <host id="blog.rj-bai.com" root-directory="/www/resin1/app">
<web-app id="/" root-directory="/www/resin1/default/webapps/rj-bai"> #虚拟主机,注释状态
</web-app>
</host> -->
<host id="" root-directory="/www/resin1/default"> #将网站根目录移动到/www/resin1/
<web-app id="/" root-directory="webapps/ROOT"/>
</host>
</cluster>
</resin>
2.编辑配置文件 resin.properties ,修改主要参数,以下仅供参考,别照搬。
dev_mode : false #调试模式关了
resin_doc : false #自带文档,不需要
app_servers : 10.10.47.88:6800 #app集群通讯占用端口,现在还没做集群
home_cluster : app
app.http : 8080 #app访问端口
setuid_user : www-data #程序运行用户
setuid_group : www-data #程序运行组
# Arg passed directly to the JVM
jvm_args : -Djsse.enableSNIExtension=false -d64 -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -XX:+UseParallelGC -XX:ParallelGCThreads=4 -XX:+UseParallelOldGC -XX:+UseCodeCacheFlushing
jvm_argsa : -Xms4096m -Xmx4096m -Xmn1024m -XX:MaxPermSize=768M -Xss1m -Xloggc:log/gc-aresin.log -XX:ReservedCodeCacheSize=96m
jvm_argsw : -Xms768m -Xmx768m -Xmn196m -XX:MaxPermSize=320M -Xss256k -Xloggc:log/gc-wresin.log
jvm_mode : -server #配置内存
port_thread_max : 2560 #调整线程池的最大线程数
accept_thread_max : 32
accept_thread_min : 8
tcp_cork : true #tcp速度优化
sendfile : true
keepalive_select_enable : true
因为之前运行用户的属主属组为root,所以现在要改变安装目录及根目录权限。
[root@iZ2ze97fdsfodnhh1iuz4xZ ~]# chown www-data.www-data -R /usr/local/resin/
[root@iZ2ze97fdsfodnhh1iuz4xZ ~]# chown www-data.www-data -R /www/resin1/
然后将代码放置/www/resin1/default/webapps/即可访问。
多实例安装方法
1.只需修改编译参数,把上面的1改成2即可
[root@iZ2ze97fdsfodnhh1iuz4xZ resin-pro-4.0.47]# ./configure --prefix=/usr/local/resin2 --with-java-home=/usr/local/jdk1.7.0_79/ --with-resin-log=/www/resin2/jvm-log/ --with-resin-init-d=/etc/init.d/resin2
[root@iZ2ze97fdsfodnhh1iuz4xZ resin-pro-4.0.47]# make
[root@iZ2ze97fdsfodnhh1iuz4xZ resin-pro-4.0.47]# make install
2.修改resin.xml
<server-multi id-prefix="app-" address-list="${app_servers}" port="6801"> #端口号+1
<watchdog-port>6601</watchdog-port> #添加
然后改掉根目录,使用vim批量替换即可,把resin1换成resin2即可。:%s/resin1/resin2/g
3.修改resin.properties
app_servers : 10.10.47.88:6801
app.http : 8081
端口号+1,最后修改属主属组即可。
[root@iZ2ze97fdsfodnhh1iuz4xZ ~]# chown www-data.www-data -R /usr/local/resin2/
[root@iZ2ze97fdsfodnhh1iuz4xZ ~]# chown www-data.www-data -R /www/resin2/
[root@iZ2ze97fdsfodnhh1iuz4xZ ~]# /etc/init.d/resin2 start