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> #→在此行前加入上面三行