Java教程

阿里云 linux centos7安装tomcat

本文主要是介绍阿里云 linux centos7安装tomcat,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

安装Tomcat之前要安装JDK

1、下载tomcat8

wget https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.73/bin/apache-tomcat-8.5.73.tar.gz --no-check-certificate

2、解压

tar -zxvf apache-tomcat-8.5.73.tar.gz

删除安装文件

rm –rf apache-tomcat-8.5.73.tar.gz

3、启动tomcat

进入bin目录下

cd apache-tomcat-8.5.73/bin
./startup.sh

结果如下:

Using CATALINA_BASE:   /root/apache-tomcat-8.5.73
Using CATALINA_HOME:   /root/apache-tomcat-8.5.73
Using CATALINA_TMPDIR: /root/apache-tomcat-8.5.73/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /root/apache-tomcat-8.5.73/bin/bootstrap.jar:/root/apache-tomcat-8.5.73/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.

看到上图内容,说明tomcat启动成功了。

关闭tomcat

./shutdown.sh

4、查看tomcat是否关闭

ps -ef|grep java

如果显示以下相似信息,说明Tomcat还没有关闭

root     18627     1  0 21:34 pts/0    00:00:03 /usr/bin/java -Djava.util.logging.config.file=/root/apache-tomcat-8.5.73/conf
/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 
-Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 
-Dignore.endorsed.dirs= -classpath /root/apache-tomcat-8.5.73/bin/bootstrap.jar:/root/apache-tomcat-8.5.73/bin/tomcat-juli.jar 
-Dcatalina.base=/root/apache-tomcat-8.5.73 -Dcatalina.home=/root/apache-tomcat-8.5.73 
-Djava.io.tmpdir=/root/apache-tomcat-8.5.73/temp org.apache.catalina.startup.Bootstrap start

5、使用curl命令来查看下localhost:8080

curl localhost:8080

结果如下:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title>Apache Tomcat/8.5.73</title>
        <link href="favicon.ico" rel="icon" type="image/x-icon" />
        <link href="tomcat.css" rel="stylesheet" type="text/css" />
    </head>

    <body>
        <div id="wrapper">
            <div id="navigation" class="curved container">
                <span id="nav-home"><a href="https://tomcat.apache.org/">Home</a></span>
                <span id="nav-hosts"><a href="/docs/">Documentation</a></span>
                <span id="nav-config"><a href="/docs/config/">Configuration</a></span>
                <span id="nav-examples"><a href="/examples/">Examples</a></span>
                <span id="nav-wiki"><a href="https://wiki.apache.org/tomcat/FrontPage">Wiki</a></span>
                <span id="nav-lists"><a href="https://tomcat.apache.org/lists.html">Mailing Lists</a></span>
                <span id="nav-help"><a href="https://tomcat.apache.org/findhelp.html">Find Help</a></span>
                <br class="separator" />
            </div>
            <div id="asf-box">
                <h1>Apache Tomcat/8.5.73</h1>
            </div>
            <div id="upper" class="curved container">
                <div id="congrats" class="curved container">
                    <h2>If you're seeing this, you've successfully installed Tomcat. Congratulations!</h2>
                </div>
                <div id="notice">
                    <img id="tomcat-logo" src="tomcat.svg" alt="[tomcat logo]" />
                    <div id="tasks">
                        <h3>Recommended Reading:</h3>
                        <h4><a href="/docs/security-howto.html">Security Considerations How-To</a></h4>
                        <h4><a href="/docs/manager-howto.html">Manager Application How-To</a></h4>
                        <h4><a href="/docs/cluster-howto.html">Clustering/Session Replication How-To</a></h4>
                    </div>
                </div>

可以看到默认站点的html代码,说明访问成功。

打开浏览器,在地址栏中输入http://ip:8080,结果如下

 

 

6、开放8080端口

默认情况下,tomcat使用8080端口。

firewall-cmd --zone=public --add-port=8080/tcp --permanent

查看放开的端口

firewall-cmd --list-port

7、重启防火墙

firewall-cmd --reload

打开防火墙

systemctl start firewalld

查看防火墙状态

systemctl status firewalld

8、修改tomcat默认端口为80

进入conf目录

vim server.xml

将8080端口改为80端口

 <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

使用下面的命令将80端口以tcp协议开放,

firewall-cmd --zone=public --add-port=80/tcp --permanent

 浏览器访问:http://ip/,效果如下:

 

这篇关于阿里云 linux centos7安装tomcat的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!