linux开机自启tomcat项目,Linux下配置tomcat、springboot项目jar包开机自启

Linux下配置tomcat、springboot项目jar包开机自启

Linux下配置tomcat、springboot项目jar包开机自启

1、在/etc/init.d/目录下创建shell启动脚本auto_jq.sh(脚本文件名称可自行命名)

cd /etc/init.d/

touch auto_jq.sh

vim auto_jq.sh

写入如下内容

6009fa761c399a5afae051f217a4b2da.png

#!/bin/sh

# chkconfig: 2345 85 15

# description:auto_run

#程序名

RUN_NAME="server-1.5_bg.jar"

#jar包位置

JAVA_OPTS=/home/server-1.5_bg.jar

JAVA_YML=/home/application.yml

LOG_OPTS=/home/logs.log

#开始方法

start() {

source /etc/profile; nohup java -jar $JAVA_OPTS --spring.config.location=$JAVA_YML >$LOG_OPTS 2>&1 &

echo "$RUN_NAME started success."

}

#结束方法

stop() {

echo "stopping $RUN_NAME ..."

kill -9 `ps -ef|grep $JAVA_OPTS|grep -v grep|grep -v stop|awk '{print $2}'`

}

case "$1" in

start)

start

;;

stop)

stop

;;

restart)

stop

start

;;

*)

echo "Userage: $0 {start|stop|restart}"

exit 1

esac

2、设置执行权限

chmod 777 /etc/init.d/auto_jq.sh

chmod 777 /home/server-1.5_bg.jar

3、添加到chkconfig作为系统服务,并设置开机启动:

chkconfig --add autojar.sh (添加为系统服务)

chkconfig autojar.sh on (开机自启动)

service autojar.sh start(启动服务)

reboot (重启服务器)

netstat -ntlp | grep 8080 (查看端口)

ps aux|grep java(查看服务)

配置Tomcat为系统服务并开机自启动

1、新建服务脚本

vim /etc/init.d/tomcat (文件名可自行命名)

填入如下脚本内容:注意更换自己的tomcat文件路径

#!/bin/bash

# description: Tomcat7 Start Stop Restart

# processname: tomcat7

# chkconfig: 234 20 80

CATALINA_HOME=/usr/local/tomcat/apache-tomcat-7.0.77

case $1 in

start)

sh $CATALINA_HOME/bin/startup.sh

;;

stop)

sh $CATALINA_HOME/bin/shutdown.sh

;;

restart)

sh $CATALINA_HOME/bin/shutdown.sh

sh $CATALINA_HOME/bin/startup.sh

;;

*)

echo 'please use : tomcat {start | stop | restart}'

;;

esac

exit 0

执行脚本,启动、停止 和 重启服务。

启动:service tomcat start

停止:service tomcat stop

重启:service tomcat restart

2、Tomcat 配置开启自启动

向chkconfig添加 tomcat 服务的管理

[[email protected] ~]# chkconfig --add tomcat

设置tomcat服务自启动

[[email protected] ~]# chkconfig tomcat on

查看tomcat的启动状态

[[email protected] ~]# chkconfig --list | grep tomcat

状态如下:

[[email protected] ~]# chkconfig –list | grep tomcat

tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off

关闭tomcat服务自启动:chkconfig tomcat off

删除tomcat服务在chkconfig上的管理:chkconfig –del tomcat

若启动时报 Neither the JAVA_HOME nor the JRE_HOME environment variable is defined 错误

配置完成 启动服务时出现如下错误日志:

Neither the JAVA_HOME nor the JRE_HOME environment variable is defined

At least one of these environment variable is needed to run this program

字面理解可看出是 JDK 问题,首先先查看JAVA_HOME路径

vim /etc/profile

75550f9aa201fc69bea656b685b605cf.png

编辑文件 tomcat bin目录下的 catalina.sh文件

在第二行中插入:export JAVA_HOME="JAVA_HOME路径"

0f6abd62eb06865381397b68f22ed98f.png

Linux下配置tomcat、springboot项目jar包开机自启相关教程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值