在Ubuntu 18.04系统上安装Tomcat的详细指南
本文目录导读:
- <"http://#id1" title="准备工作" "">准备工作
- <"http://#id2" title="安装Java" "">安装Java
- <"http://#id3" title="下载Tomcat" "">下载Tomcat
- <"http://#id4" title="解压Tomcat" "">解压Tomcat
- <"http://#id5" title="配置环境变量" "">配置环境变量
- <"http://#id6" title="启动Tomcat" "">启动Tomcat
- <"http://#id7" title="关闭Tomcat" "">关闭Tomcat
- <"http://#id8" title="设置防火墙规则(可选)" "">设置防火墙规则(可选)
在Ubuntu 18.04系统上安装Tomcat需要一些步骤,以下是一个详细的指南,帮助您完成这个过程。
准备工作
在开始安装之前,请确保您的Ubuntu系统已经更新到最新版本,您可以通过运行以下命令来更新系统:
sudo apt update sudo apt upgrade
安装Java
Tomcat需要Java运行环境,您可以通过以下命令安装Java:
sudo apt install openjdk-11-jdk
下载Tomcat
从Apache Tomcat官方网站下载最新版本的Tomcat,您可以从以下链接下载:
https://tomcat.apache.org/download-90.cgi
选择适合您系统的版本,并下载到本地目录。
解压Tomcat
将下载的Tomcat压缩包解压到您选择的目录,您可以将其解压到/opt
目录:
sudo tar -zxvf apache-tomcat-9.0.0.M1.tar.gz -C /opt
配置环境变量
编辑~/.bashrc
文件,添加以下内容:
export CATALINA_HOME=/opt/apache-tomcat-9.0.0.M1 export PATH=$PATH:$CATALINA_HOME/bin
然后运行以下命令使更改生效
source ~/.bashrc
启动Tomcat
进入Tomcat目录,并启动Tomcat:
cd /opt/apache-tomcat-9.0.0.M1/bin/ ./startup.sh
您可以在浏览器中访问http://localhost:8080
来验证Tomcat是否成功启动,如果看到Tomcat的默认页面,则表示安装成功。
关闭Tomcat
要关闭Tomcat,请运行以下命令:
./shutdown.sh
设置防火墙规则(可选)
如果您希望通过防火墙允许外部访问Tomcat,请运行以下命令:
1、打开防火墙配置文件
sudo nano /etc/ufw/before.rules
2、在文件末尾添加以下内容
对于IPv4
# Tomcat HTTP (8080) and HTTPS (8443) access for inbound traffic on the local subnet (192.168.*.*) only. You may need to adjust the subnet range as appropriate for your network configuration. The default subnet range for a local subnet is 192.168.*.*. Adjust the range if you have a different local subnet configuration. For example: 192.168.0.* or 192.168.1.* etc. Adjust the port range if you have multiple instances of Tomcat running on different ports on the same server. For example: 8080-8090 and 8443-8453 etc. Adjust the protocol to TCP if required (UDP is the default). Adjust the source address range if you want to limit access to a specific source IP address range instead of the entire subnet. For example: 192.168.0.0/24 or 10.0.0.0/24 etc. Adjust the destination address range if you want to limit access to a specific destination IP address range instead of the entire subnet or server IP address range. For example: 192.168.0.0/24 or 10.0.0.0/24 etc. Adjust the port range if you have multiple instances of Tomcat running on different ports on the same server. For example: 8080-8090 and 8443-8453 etc. Adjust the protocol to TCP if required (UDP is the default). Adjust the source address range if you want to limit access to a specific source IP address range instead of the entire subnet or server IP address range. For example: 192.168.0.0/24 or 10.0.0.0/24 etc. Adjust the destination address range if you want to limit access to a specific destination IP address range instead of the entire subnet or server IP address range. For example: 192.168.0.0/24 or 10.0.0.0/24 etc. Adjust the protocol to TCP if required
版权声明
本文仅代表作者观点,不代表米安网络立场。
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。