将tomcat注册为centos上面的一个systemctl服务

本文详细介绍了如何将tomcat注册为CentOS的systemctl服务,包括下载与解压tomcat,编辑catalina.sh,设置PID,编写service文件,注册服务,以及处理服务状态错误和springboot jar服务的编写注意事项。
摘要由CSDN通过智能技术生成

前言

为了更好的管理自己编写的小程序,可以将自己写的一些小工具直接注册为linux服务。下面,我就以tomcat注册为systemctl举例子

下载tomcat

在apack官网下载 tomcat-8.5.61 :https://tomcat.apache.org/download-80.cgi
然后通过xftp放到自己的目标目录

解压tomcat并且编辑

# 因为我下的tomcat是zip压缩的,所以先下一个unzip解压软件
yum install unzip
# 在目标目录解压
unzip apache-tomcat-8.5.61.zip
# 赋予权限755
# 一般简单赋予权限是755或者777   
# 777是所有用户都有执行,读,写权限,755是root用可执行权限.文件所属用户和其它组用户没有执行权限!
# 这里考虑到最后会变成服务进行执行,就赋予了755权限
chmod 755 -R apache-tomcat-8.5.61/
# tomcat开启PID文件
cd apache-tomcat-8.5.61/bin
vi ./catalina.sh

修改 catalina.sh 文件,在 PRGDIR 下面一行添加 CATALINAPID 参数行,如下:

PRGDIR=dirname "$PRG"
CATALINA_PID=$PRGDIR/tomcat.pid

然后使用cat命令 修改如下:

cat catalina.sh 
[root@localhost bin]# cat catalina.sh 
#!/bin/sh

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governi
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值