tomcat服务器
linux下tomcat的安装与配置
步骤:
一、安装Tomcat和JDK
Tomcat是稳固的独立的Web服务器与Servlet Container,不过,其Web服务器的功能则不如许多更健全的Web
服务器完整,如Apache Web服务器(举例来说,Tomcat没有大量的选择性模块)。
1、安装JDK
下载 jdk-7-linux-i586.rpm
http://java.sun.com/javase/downloads/index.jsp
# rpm �Civh jdk-7-linux-i586.rpm
# vi ~/.bash_profile
JAVA_HOME=/usr/java/jdk1.7.0
CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib
PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
export PATH CLASSPATH JAVA_HOME
使环境变量立刻生效
# source ~/.bash_profile
# source /etc/profile
# java -version (jdk的版本为jdk1.4.2则表示jdk已成功安装)。
2、安装Tomcat
下载apache-tomcat-6.0.10.tar.gz
http://jakarta.apache.org/tomcat
# tar zxf apache-tomcat-6.0.10.tar.gz -C /usr/src
# mv /usr/src/apache-tomcat-6.0.10 /usr/src/tomcat
# /usr/src/tomcat/bin/startup.sh (启动tomcat)
或
# /usr/src/tomcat/bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TEMDIR: /usr/local/tomcat/temp
Using JAVA_HOME: /usr/java/jdk1.6.0_01
# /usr/src/tomcat/bin/catalina.sh start/stop (启动/关闭tomcat)
到此tomcat已经安装完成,现在使用浏览器访问 http://localhost:8080,出现tomcat默认页面,
系统重启后自动启动Tomcat:
[root@tpwb ~]# vi /etc/rc.d/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don’t
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
export JDK_HOME=/usr/java/jdk1.7.0
export JAVA_HOME=/usr/java/jdk1.7.0
/usr/src/tomcat/bin/catalina.sh start
设置虚拟主机:
# vi /usr/src/tomcat/conf/server.xml
<Host name="www.benet.com" debug="0" appBase="/usr/src/tomcat/webapps/ROOT" unpackWARs="true"
autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="." debug="0" reloadable="true" crossContext="true"/>
<Valve className="org.apache.catalina.vales.AccessLogValve" directory="logs"
prefix="www.benet.com_access_log." pattern="common" suffix=".txt"
timestamp="true"/>
</Host>
或
<Host name="www.benet.com" debug="0" appBase="/usr/src/tomcat/webapps" unpackWARs="true"
autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="ROOT" debug="0" reloadable="true" crossContext="true"/>
<Valve className="org.apache.catalina.vales.AccessLogValve" directory="logs"
prefix="www.benet.com_access_log." pattern="common" suffix=".txt"
timestamp="true"/>
</Host>
一个jsp页面:
# vi index.jsp
<% out.println("Hello World!"); %>
:wq
修改tomcat log格式(去日期)
# vi /var/lib/tomcat6/conf/server.conf (加上rotatable="false")
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt" pattern="common" resolveHosts="false" rotatable="false"/>
默认为:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt" pattern="common" resolveHosts="false" />
注:
1、有时tomcat无法启动,可以用netstat -ntpl 查看是否8080依然还在,在的话用kill -9杀掉即可
2、有时tomcat无法启动,可以用netstat -ntpl查看是否8005端口存在,在的话用kill -9杀掉即可
3、tomcat默认log文件路径:/var/lib/tomcat6/logs/