Linux上安装tomcat
参考https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-centos-7,原文中是单独创建了tomcat账号来运行tomcat,我这边因为自己使用,为方便就直接使用了自己的账号(用户和用户组都是soul);另外原文是CentOS 7系统,但实际安装部分基本上是完全通用的
- 下载tomcat
cd ~
wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.31/bin/apache-tomcat-8.5.31.tar.gz
(包的地址会变化,从http://tomcat.apache.org/download-80.cgi获取最新地址)
- 创建tomcat目录,并解压tomcat
sudo mkdir /opt/tomcat
sudo tar xvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1
- 赋予soul组权限
cd /opt/tomcat
sudo mkdir cache
sudo chgrp -R soul /opt/tomcat
sudo chmod -R g+r conf
sudo chmod g+x conf
- 赋予soul用户权限
sudo chown -R soul webapps/ work/ temp/ logs/ cache/
- 将tomcat生成为系统服务
sudo vi /etc/systemd/system/tomcat.service
# Systemd unit file for tomcat [Unit] Description=Apache Tomcat Web Application Container After=syslog.target network.target [Service] Type=forking Environment=JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/ Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid Environment=CATALINA_HOME=/opt/tomcat Environment=CATALINA_BASE=/opt/tomcat Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -Xss256k -XX:+UseParallelGC' Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom' ExecStart=/opt/tomcat/bin/startup.sh ExecStop=/opt/tomcat/bin/shutdown.sh User=soul Group=soul UMask=0007 RestartSec=10 Restart=always [Install] WantedBy=multi-user.target
注:JAVA_HOME、User、Group按照实际的替换
-
sudo systemctl daemon-reload
-
sudo systemctl start tomcat
- 设置tomcat服务开机启动
-
sudo systemctl enable tomcat
-
本文来自博客园,作者:SoulTraitor,转载请注明原文链接:https://www.cnblogs.com/soultraitor/p/16655213.html