如何在CentOS 7上安装Apache Tomcat 9

Formerly known as Jakarta Tomcat, Apache Tomcat is a free and open-source web server that was founded by Apache Foundation. Unlike traditional web servers such as Apache or Nginx, Apache Tomcat is used to serve Java-based web applications. Tomcat version 9 was released on December 6th, 2018. Some of the improvements include Support for Java Servlet 3.1, Java WebSocket 1.0 and JavaServer Pages 2.3 to mention just but a few. In this guide, we are going to discuss how to install Apache Tomcat 9 on CentOS 7.

Apache Tomcat(以前称为Jakarta Tomcat)是由Apache Foundation创建的免费开放源代码Web服务器。 与传统的Web服务器(例如Apache或Nginx)不同,Apache Tomcat用于服务基于Java的Web应用程序。 Tomcat 9是于2018年12月6日发布的。其中的一些改进包括对Java Servlet 3.1,Java WebSocket 1.0和JavaServer Pages 2.3的支持。 在本指南中,我们将讨论如何在CentOS 7上安装Apache Tomcat 9。

步骤1:安装和配置Java (Step 1: Install and configure Java)

Before proceeding to install Apache Tomcat 9, ensure that the Java is installed. To install Java 8, run the below command.

在继续安装Apache Tomcat 9之前,请确保已安装Java。 要安装Java 8,请运行以下命令。

# yum install java-1.8.0-openjdk-devel

Sample Output

样本输出

Once successfully installed, you can verify its version by running the command.

成功安装后,您可以通过运行命令来验证其版本。

# java -version

Sample Output

样本输出

步骤2:安装Apache Tomcat 9 (Step 2: Install Apache Tomcat 9)

After successful installation of Java, now its time to install the latest version of Tomcat. By the time of writing this guide, the latest version of Tomcat is Tomcat 9.0.2. To get the latest version, head out to Tomcat’s official page .

成功安装Java之后,现在该安装最新版本的Tomcat了。 在撰写本指南时,Tomcat的最新版本是Tomcat 9.0.2 。 要获取最新版本,请访问Tomcat的官方页面

To get started with installing Tomcat 9, navigate to /usr/local directory as shown.

要开始安装Tomcat 9,请导航至/usr/local目录,如图所示。

# cd /usr/local

Next download the latest Tomcat tarball file using wget command.

接下来,使用wget命令下载最新的Tomcat tarball文件。

# wget https://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.20/bin/apache-tomcat-9.0.20.tar.gz

Sample Output

样本输出

Extract the tarball file.

解压缩tarball文件。

# tar -xvf apache-tomcat-9.0.20.tar.gz

Sample Output

样本输出

Once you have extracted the tarball, you will have 2 files as shown.

提取完压缩包后,将显示2个文件。

For simplicity’s sake, rename the extracted folder to the latest Tomcat version, in this case tomcat9

为简单起见,将提取的文件夹重命名为最新的Tomcat版本,在本例中为tomcat9

# mv apache-tomcat-9.0.20 tomcat9

Next, configure CATALINA_HOME environment variable as shown.

接下来,如图所示配置CATALINA_HOME环境变量。

# echo "export CATALINA_HOME="/usr/local/tomcat9"" >> ~/.bashrc
# source ~/.bashrc

Sample Output

样本输出

At this point, we are now set to launch Apache Tomcat 9. Run the following commands to start Tomcat 9.

至此,我们现在已设置为启动Apache Tomcat9。运行以下命令以启动Tomcat 9。

# cd /usr/local/tomcat9/bin
# ./startup.sh

Sample Output

样本输出

To access the Tomcat server, open your web browser and browse your server’s IP.

要访问Tomcat服务器,请打开Web浏览器并浏览服务器的IP。

https://server-ip:8080/

https://server-ip:8080/

步骤3:设定Tomcat 9帐户 (Step 3: Setting up Tomcat 9 accounts)

At this stage, you can only access Tomcat’s default web page. To access the Server Status, Host Manager, and Manager App we need to configure user accounts for managers and admins. These settings are found in tomcat-users.xml file.

在此阶段,您只能访问Tomcat的默认网页。 要访问服务器状态主机管理器管理器应用程序,我们需要为管理器和管理员配置用户帐户。 这些设置位于tomcat-users.xml文件中。

Open the file using the full file path as shown.

如图所示,使用完整文件路径打开文件。

# vim /usr/local/tomcat9/conf/tomcat-users.xml

To add a user spikey with password Jupiter2030! with the role of manager-gui append the following lines.

要添加用户Jupiter和密码Jupiter2030! 带有manager-gui角色的行如下。

<role rolename="manager-gui">
<user username=""spikey" password="Jupiter2030!" roles="manager-gui">

Alternatively, you can add an admin user called admin with admin-gui role and with a password Magnum2030!.

另外,您可以添加一个名为admin的管理员用户,该用户具有admin-gui角色,密码为Magnum2030!

Finally, restart Tomcat and try accessing the Manager section. When asked for authentication, provide the credentials created in the above steps.

最后,重新启动Tomcat并尝试访问“管理器”部分。 当要求进行身份验证时,请提供在上述步骤中创建的凭据。

./shutdown.sh 
./startup.sh

结论 (Conclusion)

Apache Tomcat is the most popular web server for Java web applications and web services. We can install it easily on any server and run our Java applications.

Apache Tomcat是用于Java Web应用程序和Web服务的最受欢迎的Web服务器。 我们可以轻松地将其安装在任何服务器上并运行我们的Java应用程序。

翻译自: https://www.journaldev.com/29246/install-apache-tomcat-9-centos-7

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值