![89cbb441093312f97d2308b38fb046ee.png](https://img-blog.csdnimg.cn/img_convert/89cbb441093312f97d2308b38fb046ee.png)
一、创建/opt/service目录,用于安装nginx的位置
管理员(root):
mkdir /opt/service
非管理员(not root):
sudo mkdir /opt/service
二、上传/解压
将apache-tomcat-8.5.23.tar.gz上传到服务器的/opt/service。
可以使用FileZilla将文件上传到服务器
cd /opt/service #切换到/opt/service目录下
tar -zxvf apache-tomcat-8.5.23.tar.gz #解压到当前目录
rm -f apache-tomcat-8.5.23.tar.gz #删除apache-tomcat-8.5.23.tar.gz
三、配置开机自动启动
1.在vi /etc/systemd/system/tomcat.service配置(如果没有该文件,就新建一个)
tomcat.service文件配置如下
[Unit]
Description=tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=oneshot
Environment='JAVA_HOME=/usr/java/jdk1.8.0_131' # jdk
Environment='JRE_HOME=/usr/java/jdk1.8.0_131/jre' #jre
ExecStart=/opt/service/apache-tomcat-8.5.23/bin/startup.sh # tomcat start
ExecStop=/opt/service/apache-tomcat-8.5.23/bin/shutdown.sh # tomcat stop
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
2.启动服务
[root@localhost system]# systemctl start tomcat.service
...
stop n Stop Catalina, waiting up to n seconds for the process to end
stop -force Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running
stop n -force Stop Catalina, wait up to n seconds and then use kill -KILL if still running
configtest Run a basic syntax check on server.xml - check exit code for result
version What version of tomcat are you running?
Note: Waiting for the process to end and use of the -force option require that $CATALINA_PID is defined
提示$CATALINA_PID异常提示则需要在setclasspath.sh配置jdk信息
[root@localhost bin]# vim setclasspath.sh
export JAVA_HOME=/usr/local/java/jdk1.8.0_144
export JRE_HOME=/usr/local/java/jdk1.8.0_144/jre
# 保存即可。
3. 设置服务启动
设置开机启动
# systemctl enable tomcat.service
查询当前tomcat的状态:
# systemctl status tomcat.service
关闭tomcat:
# systemctl stop tomcat.service
关闭开机自启:
# systemctl disable tomcat.service
# 开启服务
systemctl start tomcat.service