配置 Tomcat 以服务方式自动运行

栏目: 服务器 · 发布时间: 6年前

内容简介:接手一台用 Tomcat 跑着 Java Web 应用的 Linux CentOS 服务器,通过镜像的方式更换服务器后站点无法访问,发现是因为 Tomcat 不能在服务器启动后自动启动,于是基于 init.d 将 Tomcat 配置为以服务方式自动运行。配置步骤如下:配置要点:

接手一台用 Tomcat 跑着 Java Web 应用的 Linux CentOS 服务器,通过镜像的方式更换服务器后站点无法访问,发现是因为 Tomcat 不能在服务器启动后自动启动,于是基于 init.d 将 Tomcat 配置为以服务方式自动运行。

配置步骤如下:

/etc/init.d/
chmod +x tomcat-app
chkconfig --add tomcat-app
chkconfig --list tomcat-app
service tomcat-app start

tomcat-app 配置文件内容

配置要点:

  1. 注释中一定要添加 chkconfig ,不然添加到启动服务中时会报错 "service xxx does not support chkconfig"
  2. 要设置 JAVA_HOME 与 JRE_HOME 环境变量,不然启动服务时会报错 "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"

具体配置如下:

#!/bin/bash
# chkconfig: 2345 80 20

export JAVA_HOME="/javaWork/jdk1.8.0_171"
export JRE_HOME="/javaWork/jdk1.8.0_171/jre"

TOMCAT_HOME=/usr/local/javaTom/apache-tomcat-9.0.12/bin

start() {
    cd $TOMCAT_HOME    
    ./startup.sh
}

stop() {
    cd $TOMCAT_HOME
    ./shutdown.sh
}

case $1 in
start|stop) $1;;
restart) stop; start;;
*) echo "Run as $0 "; exit 1;;
esac

参考资料:


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The  C Programming Language

The C Programming Language

Brian W. Kernighan、Dennis M. Ritchie / Prentice Hall / 1988-4-1 / USD 67.00

Presents a complete guide to ANSI standard C language programming. Written by the developers of C, this new version helps readers keep up with the finalized ANSI standard for C while showing how to ta......一起来看看 《The C Programming Language》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

SHA 加密
SHA 加密

SHA 加密工具