在Ubuntu18.04上安装apache-tomcat-9.0.8
标签(空格分隔): Ubuntu Tomcat
Tomcat的安装(/opt/tomcat/latest/bin或/opt/tomcat/apache-tomcat-9.0.8/)
建Tomcat用户:
我们将创建一个新的系统用户和组,其主目录/opt/tomcat
将运行Tomcat服务:
sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat
为了更好地控制版本和更新,我们将最新创建一个符号链接,它将指向Tomcat安装目录:
sudo ln -s /opt/tomcat/apache-tomcat-* /opt/tomcat/latest
如果你想升级你的Tomcat安装,你可以简单地解压缩更新的版本,并更改符号链接以指向最新版本
目录所有权更改为用户和组tomcat:
sudo chown -R tomcat /opt/tomcat
sudo chmod +x /opt/tomcat/latest/bin/
sudo mkdir /opt/tomcat
sudo chmod +x /opt/tomcat/
sudo tar -zxvf /home/slf/下载/apache-tomcat-9.0.8.tar.gz -C /opt/tomcat/
将Tomcat作为服务运行:
我们将在/etc/systemd/system/
目录下用以下内容创建一个新的tomcat.service
单元文件:
sudo vi /etc/systemd/system/tomcat.service
[Unit]
Description=Tomcat 9.0.8 servlet container
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/usr/lib/jvm/default-java"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_BASE=/opt/tomcat/latest"
Environment="CATALINA_HOME=/opt/tomcat/latest"
Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
ExecStart=/opt/tomcat/latest/bin/startup.sh
ExecStop=/opt/tomcat/latest/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
通知systemd我们创建了一个新的单元文件并通过执行以下命令来启动Tomcat服务:
sudo systemctl daemon-reload
sudo systemctl start tomcat
检查服务状态:
sudo systemctl status tomcat
启用Tomcat服务在启动时自动启动:
sudo systemctl enable tomcat.service
打开浏览器并输入:http://<your_domain_or_IP_address>:8080
如果您无法访问该页面,那么很有可能您的防火墙阻止了端口8080.如果使用ufw打开端口8080,请运行以下命令
sudo ufw allow 8080/tcp
配置tomcat管理员:
sudo vi /opt/tomcat/latest/conf/tomcat-users.xml
<!--
<role rolename="manager-script"/>
-->
<!--Users with the admin-gui role should not be granted the admin-script role.-->
<role rolename="manager-gui"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="huang" roles="manager-gui,manager-jmx,manager-status"/>
sudo systemctl stop tomcat.service
sudo systemctl start tomcat.service
Tomcat的安装完成