每日博客

服务器Ubuntu20系统安装配置Tomcat

(利用terminal远程连接工具)

1.下载并上传到服务器(目录自定)

 2.解压到指定文件夹(自定)

sudo tar -zxvf apache-tomcat-9.0.58.tar.gz -C /usr/local/Tomcat/

3.修改tomcat-users.xml文件

在<tomcat-users>标签下添加:

<!-- user manager can access only manager section -->
<role rolename="manager-gui" />
<user username="manager" password="StrongPassword" roles="manager-gui" />

<!-- user admin can access manager and admin section both -->
<role rolename="admin-gui" />
<user username="admin" password="StrongPassword" roles="manager-gui,admin-gui" />

 

 

 

4.修改context.xml文件(注释掉 IP 地址部分)

 

 5.为 Apache Tomcat 创建一个 systemd 单元文件

 

 写入(注意文件地址):

[Unit]
Description=Tomcat
After=network.target

[Service]
Type=forking

User=root
Group=root

Environment="JAVA_HOME=/usr/local/java/jdk1.8.0_162"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_BASE=/usr/local/Tomcat/apache-tomcat-9.0.58"
Environment="CATALINA_HOME=/usr/local/Tomcat/apache-tomcat-9.0.58"
Environment="CATALINA_PID=/usr/local/Tomcat/apache-tomcat-9.0.58/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/usr/local/Tomcat/apache-tomcat-9.0.58/bin/startup.sh
ExecStop=/usr/local/Tomcat/apache-tomcat-9.0.58/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

 6.最后

#重新加载 systemd 守护程序服务以应用更改
sudo systemctl daemon-reload

#启动 Apache Tomcat 服务
sudo systemctl start tomcat

#使服务在系统启动时启动
sudo systemctl enable tomcat

#检查服务的状态
sudo systemctl status tomcat

 访问Apache Tomcat网络界面

Apache Tomcat安装及配置完成后,打开浏览器,在地址栏中输入http://服务器IP地址:8080,以访问其Web界面。

posted @ 2022-05-04 18:59  谦寻  阅读(21)  评论(0编辑  收藏  举报