apache tomcat 安装
1、安装jdk (java development kit)
jdk下载 http://download.oracle.com/otn-pub/java/jdk
tar -zxvf jdk-8u121-linux-x64.tar.gz
mv jdk1.8.0_121 /usr/local/jdk1.8.0_121
添加环境变量
vim /etc/profile.d/java.sh
JAVA_HOME=/usr/local/jdk1.8.0_121
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME PATH CLASSPATH
source /etc/profile.d/java.sh
测试:
#java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
2、安装tomcat
cd /usr/local/src
wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.0.41/bin/apache-tomcat-8.0.41.tar.gz
tar zxvf apache-tomcat-8.0.41.tar.gz
mv apache-tomcat-8.0.41.tar.gz /usr/local/tomcat-8.0.41
4、设置环境变量
vim /etc/profile.d/tomcat.sh
CATALINA_HOME=/usr/local/tomcat-8.0.41
export CATALINA_HOME
source /etc/profile.d/tomcat.sh
5、service管理tomcat脚本
vim /etc/init.d/tomcat
#!/bin/bash #Tomcat init script for Linux. # #chkconfig: 2345 96 14 #description:The Apache Tomcat servlet/JSP container. #JAVA_OPTS='-Xms64m-Xmx128m' JAVA_HOME=/usr/local/jdk1.8.0_121 CATALINA_HOME=/usr/local/tomcat-8.0.41 export JAVA_HOME CATALINA_HOME case $1 in start) exec $CATALINA_HOME/bin/catalina.sh start ;; stop) exec $CATALINA_HOME/bin/catalina.sh stop ;; restart) $CATALINA_HOME/bin/catalina.sh stop sleep 2 exec $CATALINA_HOME/bin/catalina.sh start ;; configtest) exec $CATALINA_HOME/bin/catalina.sh configtest ;; *) exec $CATALINA_HOME/bin/catalina.sh * ;; esac
chmod +x /etc/init.d/tomcat
启动 service tomcat start
关闭 service tomcat stop
重启 service tomcat restart
配置文件检测 service tomcat configtest
6、tomcat目录介绍
#tree -L 1 /usr/local/tomcat-8.0.41/
/usr/local/tomcat-8.0.41/
├── bin // 用以启动、关闭Tomcat或者其它功能的脚本(.bat文件和.sh文件)
├── conf // 用以配置Tomcat的XML及DTD文件
├── lib // 存放web应用能访问的JAR包
├── LICENSE
├── logs // Catalina和其它Web应用程序的日志文件
├── NOTICE
├── RELEASE-NOTES
├── RUNNING.txt
├── temp //临时文件
├── webapps // Web应用程序根目录
└── work // 用以产生有JSP编译出的Servlet的.java和.class文件
7、修改tomcat监听地址
vim /usr/local/tomcat-8.0.41/conf/server.xml
<Connector port="8080" address="192.168.1.118" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
8、tomcat管理
Tomcat管理功能用于对Tomcat自身以及部署在Tomcat上的应用进行管理的web应用。在默认情况下是处于禁用状态的。如果需要开启这个功能,就需要配置管理用户,即配置前面说过的tomcat-users.xml。
[root@tomcat ~]# vim /usr/local/
tomcat-8.0.41/conf/tomcat-users.xml
…………
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui,admin-gui"/>
</tomcat-users> #→在此行前加入上面三行