1、安装Tomcat,安装之前必须先安装Java,先安装java
下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html
(1):解压安装java
tar zxvf jdk-8u151-linux-x64.tar.gz
(2):配置java
mv jdk1.8.0_151/ /usr/local/java vim /etc/profile.d/java.sh #写入 export JAVA_HOME=/usr/local/java export PATH=$PATH:$JAVA_HOME/bin #保存退出
(3):导入环境变量,查看Java版本
source /etc/profile.d/java.sh #导入环境变量 java -version #查看JAVA版本
2、下载安装Tomcat
下载地址:https://tomcat.apache.org/download-90.cgi
(1):下载解压Tomcat
wget http://mirrors.shuosc.org/apache/tomcat/tomcat-9/v9.0.2/bin/apache-tomcat-9.0.2.tar.gz
tar zxvf apache-tomcat-9.0.2.tar.gz
(2):配置、启动Tomcat
mv apache-tomcat-9.0.2 /usr/local/tomcat9 /usr/local/tomcat9/bin/startup.sh Using CATALINA_BASE: /usr/local/tomcat9 Using CATALINA_HOME: /usr/local/tomcat9 Using CATALINA_TMPDIR: /usr/local/tomcat9/temp Using JRE_HOME: /usr/local/java Using CLASSPATH: /usr/local/tomcat9/bin/bootstrap.jar:/usr/local/tomcat9/bin/tomcat-juli.jar Tomcat started.
(3):查看Tomcat端口
[root@localhost /]# netstat -anpt | grep 8080 tcp 0 0 :::8080 :::* LISTEN 3350/java
(4):防火墙允许8080端口通过,Tomcat默认端口是8080
vim /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT #添加 #保存脱出 service iptables restart
(5):访问浏览器测试,http://127.0.0.1:8080,如果出现下图,则说明Tomcat成功启动
(6):如果想关闭Tomcat
/usr/local/tomcat9/bin/shutdown.sh