操作系统:CentOS release 6.10 (Final)
实战任务:发布Jsp程序
环境要求:安装配置JAVA、Tomcat环境
操作步骤:
1.下载JDK
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
#wget https://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.tar.gz
实战技巧:一般通过wget下载,当软件包比较大的时候,并不能完整下载,解压缩时会报错,建议先下载到终端,然后上传到Linux服务器。
2.安装配置JDK
[root@sky9890 src]# tar -zxvf jdk-8u191-linux-x64.tar.gz
[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
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"%>
JSP测试页面
<% int x=100,y=500,z;
z=x+y;
%>
x+y=<%=z%>
成功测试页面如下图所示: