@nextleaf
2018-06-07T21:43:36.000000Z
字数 1933
阅读 935
Ubuntu
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安装,你可以简单地解压缩更新的版本,并更改符号链接以指向最新版本
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/
我们将在/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
sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl status tomcat
sudo systemctl enable tomcat.service
打开浏览器并输入:http://<your_domain_or_IP_address>:8080
如果您无法访问该页面,那么很有可能您的防火墙阻止了端口8080.如果使用ufw打开端口8080,请运行以下命令
sudo ufw allow 8080/tcp
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的安装完成