一般网站使用java语言都是用tomcat,今天给大家介绍下用resin来支持java.Resin是CAUCHO公司的产品,是一个非常流行的application server,对servlet和JSP提供了良好的支持,性能也比较优良,resin自身采用JAVA语言开发!
系统:centos 5.8
需要的软件:Resin/4.0.36.tar.gz
1.安装前准备
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype \
freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel \
bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 \
krb5-devellibidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap \
openldap-clients openldap-servers libtool libtool-devel
1、卸载服务器自带的jdk软件包
java -version #查看服务器是否安装过jdk
rpm -qa |grep gcj #查看服务器安装的jdk软件包信息,如下图所示
yum -y remove java-1.4.2-gcj-compat-1.4.2.0-40jpp.115 #卸载软件包
下载rpm的安装包:
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2Ftechnetwork%2Fjava%2Fjavase%2Fdownloads%2Fjdk-7u3-download-1501626.html" http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586-rpm.bin
jdk-6u45-linux-i586-rpm.bin
./jdk-6u45-linux-i586-rpm.bin
百度网盘:http://pan.baidu.com/s/1jGLvh46(32位)
百度网盘:http://pan.baidu.com/s/1mg0Yq5i(64位)http://pan.baidu.com/s/1mgNsV48
设置环境变量
vi /etc/profile
加入如下环境变量:
export JAVA_HOME=/usr/java/jdk1.6.0_45
export CLASS_PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
注:查看java版本
java -version
2、安装并配置Resin:
wget http://www.caucho.com/download/resin-4.0.36.tar.gz
tar zxvf resin-4.0.36.tar.gz
cd resin-4.0.36/
./configure --prefix=/usr/local/resin
make
make install
启动resin:
/usr/local/resin/bin/resin.sh start
设置resin开机自启动:
cp -r init.d/resin /etc/init.d/resin
chmod +x /etc/init.d/resin
chkconfig --add resin
chkconfig --level 2345 resin on
四、Nginx、Resin整合和测试
1、将resin的默认目录与nginx的目录相同:
vi /usr/local/resin/conf/resin.xml
把下面:
修改成:
2、创建一个JSP测试文件
vi /data/www/webnginx/index.jsp
3 + 6 = <%= 3 + 6 %>
修改nginx配置文件
配置如下:
user www www;
worker_processes 8;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/nginx.pid;
#使用Tcmalloc优化nginx性能
google_perftools_profiles /var/tmp/tcmalloc;
注:Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
#工作模式及连接数上限
events
{
use epoll;
worker_connections 65535;
}
#设定http服务器,利用它的反向代理功能提供负载均衡支持
http
{
#设定mime类型
include mime.types;
default_type application/octet-stream;
#charset gb2312;
#设定请求缓冲
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
#设置客户端能够上传文件大小的限制
client_max_body_size 300m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
server_tokens off;
client_body_buffer_size 512k;
proxy_connect_timeout 5;
proxy_send_timeout 60;
proxy_read_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
#fastcgi_connect_timeout 300;
#fastcgi_send_timeout 300;
#fastcgi_read_timeout 300;
#fastcgi_buffer_size 64k;
#fastcgi_buffers 4 64k;
#fastcgi_busy_buffers_size 128k;
#fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
#定义访问日志的写入格式
log_format wwwlog '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /data/logs/www_nginx.log wwwlog;
#设定访问日志的存放路径
#禁止通过ip访问站点
server{
server_name _;
return 404;
}
server
{
listen 80;
server_name www.xsdou.com;
index index.html index.htm index.jsp index.do;
#设定访问的默认首页地址
root /home/wwwroot/;
#设定网站的资源存放路径
#limit_conn crawler 20;
if (-d $request_filename)
{
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}
#所有jsp的页面均交由resin处理
location ~ .(jsp|jspx|do|action)?$ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://db.ci:8080;
#转向resin处理
}
location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
#设定访问静态文件直接读取不经过resin
{
expires 30d;
}
location ~ .*.(js|css)?$
{
expires 1h;
}
}
server
{
listen 80;
server_name status.www.xsdou.com;
location / {
stub_status on;
access_log off;
}
}
}
7.测试
vi /home/wwwroot/index.jsp
2 + 2 = <%= 2 + 2 %>
重启下resin和nginx
service resin restart
service nginx restart
最后重启服务器,必须的
reboot
8、安装tomcat
wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.41/bin/apache-tomcat-7.0.41.tar.gz
tar zxvf apache-tomcat-7.0.41.tar.gz
cd apache-tomcat-7.0.41
mv apache-tomcat-7.0.41 /usr/local/tomcat
编辑profile文件,加入:
export CATALINA_HOME=/usr/local/tomcat
export CLASSPATH=.:$JAVA_HOME/lib:$CATALINA_HOME/lib
export PATH=$PATH:$CATALINA_HOME/bin
9、修改tomcat配置文件
cp /usr/local/tomcat/conf/server.xml /usr/local/tomcat/conf/server.xmlbak #备份原有配置文件
vi /usr/local/tomcat/conf/server.xml #编辑
:wq! #保存退出
/usr/local/tomcat/bin/shutdown.sh #关闭tomcat
/usr/local/tomcat/bin/startup.sh #启动tomcat
扩展阅读
vi /usr/local/tomcat/conf/web.xml #编辑,可以更改目录文件访问顺序
index.html
index.htm
index.jsp
五、添加tomcat为系统服务,实现开机自启动
cd /etc/rc.d/init.d #进入目录
vi tomcat #编辑,添加一些内容
#
# chkconfig: 345 80 15
# description: Tomcat is a Servlet+JSP Engine.
# Enter the jdk installation directory
jdk_File=/usr/java/jdk1.6.0_45
# Enter the tomcat installation directory
tomcat_File=/usr/local/tomcat
export JAVA_HOME=$jdk_File
# Source function library.
. /etc/rc.d/init.d/functions
start(){
if [ -z $(/sbin/pidof java) ]; then
echo "Starting tomcat"
$tomcat_File/bin/startup.sh
touch /var/lock/subsys/tomcat
else
echo "tomcat allready running"
fi
}
stop(){
if [ ! -z $(/sbin/pidof java) ]; then
echo "Shutting down tomcat"
$tomcat_File/bin/shutdown.sh
until [ -z $(/sbin/pidof java) ]; do :; done
rm -f /var/lock/subsys/tomcat
else
echo "tomcat not running"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
$tomcat_File/bin/catalina.sh version
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
esac
exit 0
chmod 755 /etc/rc.d/init.d/tomcat #添加执行权限
chmod +x -R /usr/local/tomcat/bin/
chkconfig --add tomcat #添加服务
chkconfig tomcat on #设置开机启动
service tomcat stop #停止
service tomcat start #启动
service tomcat restart #重启
service tomcat status #查看状态信息
8、注册为服务
chkconfig --add tomcat
chkconfig tomcat on