操做系統:CentOS release 6.10 (Final)html
實戰任務:發佈Jsp程序java
環境要求:安裝配置JAVA、Tomcat環境linux
操做步驟:apache
1.下載JDKbootstrap
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.htmlvim
#wget https://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.tar.gz tomcat
實戰技巧:通常經過wget下載,當軟件包比較大的時候,並不能完整下載,解壓縮時會報錯,建議先下載到終端,而後上傳到Linux服務器。
bash
2.安裝配置JDK
服務器
[root@sky9890 src]# tar -zxvf jdk-8u191-linux-x64.tar.gzoracle
[root@sky9890 src]# mkdir /usr/local/java
[root@sky9890 src]# mv jdk1.8.0_191/ /usr/local/java/
[root@sky9890 java]# vim /etc/profile
export JAVA_HOME=/usr/local/java/jdk1.8.0_191
export CLASSPATH=.:JAVA_HOME/lib/dt.jar;$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
[root@sky9890 java]# source /etc/profile
bash: /usr/local/java/jdk1.8.0_191/lib/tools.jar: 權限不夠
解決過程:
[root@sky9890 src]# vim /etc/profile
export JAVA_HOME=/usr/local/java/jdk1.8.0_191
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar #加一個'$',將分號改爲冒號
export PATH=$PATH:$JAVA_HOME/bin
[root@sky9890 src]# source /etc/profile
[root@sky9890 java]# java -version #測試JDK是否安裝成功
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
3.下載Tomcat 8
https://tomcat.apache.org/download-80.cgi
[root@sky9890 src]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.37/bin/apache-tomcat-8.5.37.tar.gz
--2018-12-24 14:56:20-- http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.37/bin/apache-tomcat-8.5.37.tar.gz
正在解析主機 mirror.bit.edu.cn... 114.247.56.117
正在鏈接 mirror.bit.edu.cn|114.247.56.117|:80... 已鏈接。
已發出 HTTP 請求,正在等待迴應... 200 OK
長度:9653382 (9.2M) [application/octet-stream]
正在保存至: 「apache-tomcat-8.5.37.tar.gz」
[root@sky9890 src]# tar -zxvf apache-tomcat-8.5.37.tar.gz
[root@sky9890 src]# mkdir /usr/local/tomcat
[root@sky9890 src]# mv apache-tomcat-8.5.37 /usr/local/tomcat
[root@sky9890 bin]# pwd
/usr/local/tomcat/apache-tomcat-8.5.37/bin
[root@sky9890 bin]# ./startup.sh #啓動tomcat服務
Using CATALINA_BASE: /usr/local/tomcat/apache-tomcat-8.5.37
Using CATALINA_HOME: /usr/local/tomcat/apache-tomcat-8.5.37
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-8.5.37/temp
Using JRE_HOME: /usr/local/java/jdk1.8.0_191
Using CLASSPATH: /usr/local/tomcat/apache-tomcat-8.5.37/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-8.5.37/bin/tomcat-juli.jar
Tomcat started.
實戰技巧:
Tomcat默認是8080端口,目前80、8080端口已佔用,只有修改爲其餘端口,例如:9090
[root@sky9890 conf]# pwd
/usr/local/tomcat/apache-tomcat-8.5.37/conf
[root@sky9890 conf]# vi server.xml
<Connector port="9090" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
2.配置防火牆:開放9090端口
[root@sky9890 conf]# vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 9090 -j ACCEPT #添加9090端口
3.配置tomcat自動啓動服務
[root@sky9890 sky9890]# vi /etc/rc.local
/usr/local/tomcat/apache-tomcat-8.5.37/bin/startup.sh
4.測試成功頁面以下:
測試代碼:test.jsp
<%@page contentType="text/html;charset=utf-8"%>
<html>
<body bgcolor=cyan>
<font size=4>
<p>JSP測試頁面
<% int x=100,y=500,z;
z=x+y;
%>
<p>x+y=<%=z%>
</font>
</body>
</html>
成功測試頁面以下圖所示: