准备文件如下:
1.jdk-7u67-linux-x64.rpm
2.apache-tomcat-7.0.88.tar.gz
安装步骤如下:
一、安装JDK
java -version bash: java: command not found #rpm -ivh /soft/jdk-7u67-linux-x64.rpm Preparing... ########################################### [100%] 1:jdk ########################################### [100%] Unpacking JAR files... rt.jar... jsse.jar... charsets.jar... tools.jar... localedata.jar... jfxrt.jar... #java -version java version "1.7.0_67" Java(TM) SE Runtime Environment (build 1.7.0_67-b01) Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode) # cd /usr/java # ls default jdk1.7.0_67 latest
二、安装Tomcat
wget http://mirrors.shu.edu.cn/apache/tomcat/tomcat-7/v7.0.88/bin/apache-tomcat-7.0.88.tar.gz tar zxvf /soft/apache-tomcat-7.0.88.tar.gz mv /apache-tomcat-7.0.88 /usr/local/tomcat7 chmod -R +x /usr/local/tomcat7/bin
三、设置环境变量
执行vim /etc/profile命令,添加环境变量代码如下
#jdk config export JAVA_HOME=/usr/java/jdk1.7.0_67 export CALSSPATH=$JAVA_HOME/lib/*.* #tomcat config export TOMCAT_HOME=/usr/local/tomcat7 export CATALINA_HOME=/usr/local/tomcat7 #path config export PATH=$PATH:$JAVA_HOME/bin:$TOMCAT_HOME/bin
执行指令
source /etc/profile #刷新环境变量
四、启动Tomcat
sh /usr/local/tomcat7/bin/startup.sh
在浏览器中打开网址http://localhost:8080测试
关闭Tomcat命令
sh /usr/local/tomcat7/bin/shutdown.sh
五、开机启动Tomcat脚本
1、执行指令vi /etc/rc.d/init.d/tomcat生成脚本文件,内容如下
#!/bin/bash # # /etc/rc.d/init.d/tomcat # init script for tomcat precesses # # processname: tomcat # description: tomcat is a j2se server # chkconfig: 2345 86 16 # description: Start up the Tomcat servlet engine. if [ -f /etc/init.d/functions ]; then . /etc/init.d/functions elif [ -f /etc/rc.d/init.d/functions ]; then . /etc/rc.d/init.d/functions else echo -e "\atomcat: unable to locate functions lib. Cannot continue." exit -1 fi RETVAL=$? CATALINA_HOME="/usr/local/tomcat7" #tomcat安装目录 case "$1" in start) if [ -f $CATALINA_HOME/bin/startup.sh ]; then echo $"Starting Tomcat" $CATALINA_HOME/bin/startup.sh fi ;; stop) if [ -f $CATALINA_HOME/bin/shutdown.sh ]; then echo $"Stopping Tomcat" $CATALINA_HOME/bin/shutdown.sh fi ;; *) echo $"Usage: $0 {start|stop}" exit 1 ;; esac exit $RETVAL
2、添加权限chmod 755 /etc/rc.d/init.d/tomcat,使得脚本文件可执行
3、运行:chkconfig add tomcat #将其加到服务中
六、配置tomcat虚拟主机
只需要添加host节点即可,下面是参考
<Host name="www.sulao.cn" debug="0" appBase="/data/www/sulao.cn" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="."/> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="sulao.cn_access_log." suffix=".txt" pattern="common" resolveHosts="false"/> <Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="sulao.cn_log." suffix=".txt" timestamp="true"/> </Host>