RH linux AS4+JDK6U2+Tomcat6.0.14最新安装配置教程

JSP环境安装步骤一般包括两步:安装配置JDK和安装配置TOMCAT。随着版本的改进,相关配置越来越简单,只配置一个环境变量JAVA_HOME即可。 

一、安装JDK 
1.下载最新的JDK版本,目前为JDK6U1.下载地址: 

http://java.sun.com/javase/downloads/index.jsp 

下载那个rpm的bin包,即jdk-6u1-linux-i586-rpm.bin。 

2.上传安装文件到服务器上,并COPY到/usr/local目录下,执行安装 

#cd /usr/local 
# chmod +x jdk-6u1-linux-i586-rpm.bin 
#./jdk-6u1-linux-i586-rpm.bin 

然后会提示是否确认安装,这是输入yes,确认即可。 

3.配置JAVA环境变量
# vi /etc/profile
在最后添加以下三行
export JAVA_HOME=/usr/java/jdk1.6.0_01
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH

4.重启机器让环境变量生效
#reboot

5.验证JDK安装成功

# java -version
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)

# javac -version
javac 1.6.0_01
二、安装配置TOMCAT 
1.下载安装包apache-tomcat-6.0.13.tar.gz,下载地址: 

http://tomcat.apache.org 

2.上传安装包到服务器,并COPY到/usr/local目录下,执行安装 

#tar -zxvf apache-tomcat-6.0.13.tar.gz 

3.启动和关闭tomcat的命令

在/usr/local/apache-tomcat-6.0.13/bin目录下有两个shell文件startup.sh和shutdown.sh,分别是启动和关闭tomcat的批处理SHELL。

4.添加TOMCAT到系统开机自动启动 

#vi /etc/rc.d/rc.local 

在文件最后添加这一句 

/usr/local/apache-tomcat-6.0.13/bin/startup.sh 

重新启动机器或者不重启机器直接运行/usr/local/apache-tomcat-6.0.13/bin/startup.sh启动TOMCAT。访问http://localhost:8080,可以看到TOMCAT的缺省页面出来了。 

在/usr/local/apache-tomcat-6.0.13/webapps/ROOT目录下写一个helloworld.jsp文件: 

<html> 
<head> 
</head> 
<body> 
<% 
out.println("hello world!"); 
%> 
</body> 
</html> 

访问http://localhost:8080/helloworld.jsp,如果成功看到hello world就表明TOMCAT安装成功,否则检查防火墙等设置是否正确。
三、配置管理角色和用户

修改/usr/local/apache-tomcat-6.0.13/conf目录下的tomcat-users.xml文件,修改后文件内容为:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
   <role rolename="manager"/>
   <role rolename="admin"/>
   <user username="admin" password="adminpwd" roles="admin,manager"/>
</tomcat-users>

重启TOMCAT

#/usr/local/apache-tomcat-6.0.13/bin/shutdown.sh 
#/usr/local/apache-tomcat-6.0.13/bin/startup.sh
五、配置TOMCAT为多个JSP虚拟主机 

假设域名分别为www.aaa.com和www.bbb.com 

1.复制/usr/local/apache-tomcat-6.0.13/webapps目录为aaa和bbb 

#cd /usr/local/apache-tomcat-6.0.13 
#cp -r webapps aaa 
#cp -r webapps bbb 

2.修改/usr/local/apache-tomcat-6.0.13/conf/server.xml文件的最后HOST那一段的开头这一句 

<Host name="www.aaa.com" appBase="aaa" 
unpackWARs="true" autoDeploy="true" 
xmlValidation="false" xmlNamespaceAware="false"> 
............................. 
............................. 

</Host> 

复制HOST段,追加到HOST后面配置第二个域名 

<Host name="www.bbb.com" appBase="bbb" 
unpackWARs="true" autoDeploy="true" 
xmlValidation="false" xmlNamespaceAware="false"> 
............................. 
............................. 

</Host> 


其余依此类推。

3.重启TOMCAT 
#/usr/local/apache-tomcat-6.0.13/bin/shutdown.sh 
#/usr/local/apache-tomcat-6.0.13/bin/startup.sh

4.验证

删除aaa/ROOT和bbb/ROOT目录下的所有文件,将helloworld.jsp的输出语句分别改为hello aaa和hello bbb,分别用http://www.aaa.com:8080/helloworld.jsp和http://www.bbb.com:8080/helloworld.jsp访问,页面内容成功分开。
六、tomcat加入服务并随开机自动启动 

Tomcat启动可以用自带的jsvc来实现: 

jsvc本来要从 http://jakarta.apache.org 下载,不过tomcat6 已经自己带了一个,在apache-tomcat-6.0.13/bin目录下有一个jsvc.tar.gz包,解压,编译: 

#tar -xzvf jsvc.tar.gz 
#cd jsvc-src 
#sh support/buildconf.sh 
#./configure --with-java=/usr/java 
#make 

查看/usr/local/apache-tomcat-6.0.13/bin/jsvc-src/native目录下有两个脚本 Tomcat.sh 和 Tomcat5.sh ,分别用作tomcat5前后版本的启动和停止tomcat的脚本。 
由于每台机器的配置不尽相同,因此需要修改启动脚本的参数。 

这里以tomcat6为例,因此修改Tomcat5.sh。修改后的文件如下: 

#!/bin/sh 
############################################################################## 
# 
#   Copyright 2004 The Apache Software Foundation. 
# 
#   Licensed under the Apache License, Version 2.0 (the "License"); 
#   you may not use this file except in compliance with the License. 
#   You may obtain a copy of the License at 
# 
#      http://www.apache.org/licenses/LICENSE-2.0 
# 
#   Unless required by applicable law or agreed to in writing, software 
#   distributed under the License is distributed on an "AS IS" BASIS, 
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
#   See the License for the specific language governing permissions and 
#   limitations under the License. 
############################################################################## 
# 
#chkconfig: 2345 85 15 
#description: apache-tomcat.6 
# 
# Small shell script to show how to start/stop Tomcat using jsvc 
# If you want to have Tomcat running on port 80 please modify the server.xml 
# file: 
# 
#     <!-- Define a non-SSL HTTP/1.1 Connector on port 80 --> 
#     <Connector className="org.apache.catalina.connector.http.HttpConnector" 
#               port="80" minProcessors="5" maxProcessors="75" 
#               enableLookups="true" redirectPort="8443" 
#               acceptCount="10" debug="0" connectionTimeout="60000"/> 
# 
# That is for Tomcat-5.0.x (Apache Tomcat/5.0) 
# 
# Adapt the following lines to your configuration 
JAVA_HOME=/usr/java/jdk1.6.0_01 
CATALINA_HOME=/usr/local/apache-tomcat-6.0.13 
DAEMON_HOME=/usr/local/apache-tomcat-6.0.13/bin 
TOMCAT_USER=tomcat 
# for multi instances adapt those lines. 
TMP_DIR=/var/tmp 
PID_FILE=/var/run/jsvc.pid 
CATALINA_BASE=/usr/local/apache-tomcat-6.0.13 
#CATALINA_OPTS="-Djava.library.path=/home/jfclere/jakarta-tomcat-connectors/jni/native/.libs" 
CATALINA_OPTS= 
CLASSPATH=\ 
$JAVA_HOME/lib/tools.jar:\ 
$CATALINA_HOME/bin/commons-daemon.jar:\ 
$CATALINA_HOME/bin/bootstrap.jar 
case "$1" in 
   start) 
     # 
     # Start Tomcat 
     # 
    $DAEMON_HOME/jsvc-src/jsvc \ 
     -user $TOMCAT_USER \ 
     -home $JAVA_HOME \ 
     -Dcatalina.home=$CATALINA_HOME \ 
     -Dcatalina.base=$CATALINA_BASE \ 
     -Djava.io.tmpdir=$TMP_DIR \ 
     -wait 10 \ 
     -pidfile $PID_FILE \ 
     -outfile $CATALINA_HOME/logs/catalina.out \ 
     -errfile '&1' \ 
     $CATALINA_OPTS \ 
     -cp $CLASSPATH \ 
     org.apache.catalina.startup.Bootstrap 
     # 
     # To get a verbose JVM 
     #-verbose \ 
     # To get a debug of jsvc. 
     #-debug \ 
     exit $? 
     ;; 
   stop) 
     # 
     # Stop Tomcat 
     # 
    $DAEMON_HOME/jsvc-src/jsvc \ 
     -stop \ 
     -pidfile $PID_FILE \ 
     org.apache.catalina.startup.Bootstrap 
     exit $? 
     ;; 
   *) 
     echo "Usage tomcat.sh start/stop" 
     exit 1;; 
esac 

修改完成后,将Tomcat5.sh拷贝到 /etc/rc.d/init.d/目录下将命名为tomcat 
#cp /usr/local/apache-tomcat-6.0.13/bin/jsvc-src/native/Tomcat5.sh /etc/rc.d/init.d/tomcat 

添加进系统服务 
#chkconfig --add tomcat 
用--list看一下是否系统已有tomcat启动文件 
#ckhconfig --list 
即可把tomcat 添加为系统服务自动随系统启动了。这个脚本会在runlevel 2/3/4/5三种模式自动启动。

PS:
系统服务脚本必须有这下面这两行
#chkconfig: 2345 85 15         (注:在运行级2/3/4/5中加入服务,启动顺序85,停止顺序15)
#description: apache-tomcat.6

你可能感兴趣的:(java,apache,tomcat,linux,配置管理)