今天尝试将tomcat设置为开机启动,大家都知道只需要将启动脚本添加到/etc/rc.local下面开机就会自动执行。

/usr/local/tomcat8./bin/startup.sh >> /etc/rc.local

  重启机器,进行测试。结果未能如愿。这是为什么呢?开始排查。手动执行没有报错。于是开始查看日志。

[root@server2 ~]# tail /var/log/boot.log
Starting nginx: [ OK ]
Starting crond: [ OK ]
Starting atd: [ OK ]
Starting certmonger: [ OK ]
Using CATALINA_BASE: /usr/local/tomcat8.
Using CATALINA_HOME: /usr/local/tomcat8.
Using CATALINA_TMPDIR: /usr/local/tomcat8./temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat8./bin/bootstrap.jar:/usr/local/tomcat8./bin/tomcat-juli.jar
Tomcat started.

  发现日志里tomcat启动也没有异常,这下就非常疑惑了。

  回想下开机顺序: /sbin/init --> /etc/inittab --> /etc/rc.d/rc.sysinit --> /etc/rc.d/* --> /etc/rc.local --> login界面(username/passwd) --> /etc/profile.d/file --> /etc/profile

  rc.local 在 profile 前面执行,而jdk相关环境变量却在 profile 里。想要解决这个问题就需要在 tomcat脚本启动前就执行/etc/profile 才行。

[root@server2 ~]# vim /etc/rc.local 

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff. touch /var/lock/subsys/local
source /etc/profile  # 执行下 /etc/profile
/usr/local/tomcat8./bin/startup.sh
echo "tomcat test."

  再次重启机器测试。

[root@server2 ~]# tail /var/log/boot.log
Starting crond: [ OK ]
Starting atd: [ OK ]
Starting certmonger: [ OK ]
Using CATALINA_BASE: /usr/local/tomcat8.
Using CATALINA_HOME: /usr/local/tomcat8.
Using CATALINA_TMPDIR: /usr/local/tomcat8./temp
Using JRE_HOME: /usr/local/jdk1.
Using CLASSPATH: /usr/local/tomcat8./bin/bootstrap.jar:/usr/local/tomcat8./bin/tomcat-juli.jar
Tomcat started.
tomcat test.

  日志OK。

[root@server2 ~]# netstat -ntplu | grep
tcp 0.0.0.0: 0.0.0.0:* LISTEN /java

  服务也OK.

  这样的问题在以后可能也会遇到。可见,基础的原理和知识对解决问题有多重要。Linux开机执行文件的顺序一定要牢记。

[ 手记 ] 关于tomcat开机启动设置问题的更多相关文章

  1. Tomcat开机启动设置

    omcat开机启动设置 1.修改/etc/rc.d/rc.local,使用vi /etc/rc.d/rc.local 命令2.在/etc/rc.d/rc.local文件最后添加下面两行脚本 expor ...

  2. 添加tomcat开机启动服务时报错:Neither the JAVA_HOME nor the JRE_HOME enviromment variable is defined

    首先,参考的 https://blog.csdn.net/wabil/article/details/78818249 的方式添加 tomcat 开机启动,这种方式不需要添加 setenv.sh 文件 ...

  3. java部署:CentOS 7下Tomcat安装与配置教程(Tomcat开机启动)

    一.前言 1.本教程主要内容 Tomcat安装与基础配置 Tomcat开机启动配置 2.本教程适用范围与环境信息 适用范围 软件/工具 版本说明 CentOS CentOS 7 Tomcat Tomc ...

  4. CentOS 7 服务器配置--配置Tomcat开机启动

    #编辑Tomcat的文件,追加内容 vi /data/tomcat/apache-tomcat-8.0.43/bin/catalina.sh #追加内容,在CLASSPATH= 上面的第三行 CATA ...

  5. ubuntu 14 中tomcat的开机启动设置

    开机自启动,将要执行的语句写入/etc/rc.local. #!/bin/sh -e # # rc.local # # This script is executed at the end of ea ...

  6. CentOS 64-bit下安装JDK和Tomcat并设置Tomcat开机启动操作步骤

    准备文件如下: 1.CentOS-6.4-x86_64-bin-DVD1.iso 2.jdk-7u67-linux-x64.rpm 3.apache-tomcat-7.0.55.tar.gz 安装步骤 ...

  7. Linux设置程序开机启动-tomcat开机启动

    假设我有一个tomcat应用需要开机启动. 前提你的JAVA环境变量已经配置好没有问题,检测方法如图 然后找到tomcat的目录,我的目录是 /home/yuqing_4.0/tomcat_share ...

  8. centos设置tomcat开机启动

    1.编辑开机启动脚本 vi /etc/init.d/tomcat8 #!/bin/bash # tomcat8:start|stop|restart # chkconfig: 345 90 10 # ...

  9. Linux下设置mysql和tomcat开机启动

    本文基于CentOS 64位     一.mysql设置开机启动 1.cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql ...

随机推荐

  1. React错误总结(三)

    神坑react native之Cannot Add a child that doesn't have a YogaNode to a parent with out a measure functi ...

  2. 无法注册DLL/OCX:regsvr32 failed with exit code 0x5

    最近在服务器上装一个等值线控件,确报错: RegSvr32 failed with exit code 0x5   尝试解决方法1: 在cmd下 运行for %1 in (%windir%\syste ...

  3. gitbook生成的_book文件本地打开后链接失效问题

    Gitbook 生成本地 html 的问题 在本地用 gitbook-cli根据 Summary 生成目录 然后在每个 md 文件里书写内容 然后用 gitbook serve .生成本地 html ...

  4. python之time和os模块

    1.time.time()获得的是一个时间戳,距离1970年以来多少秒 2.time.strftime(),按固定格式设置时间 import time print(time.localtime())# ...

  5. winform 控件半透明设置

    1.backcolor属性为color.FromArgb(100, 220, 220, 220); 2.全透明设置为transparent方法.

  6. asp.net应用程序脱机app_offline.htm文件

    This application is currently offline. To enable the application, remove the app_offline.htm file fr ...

  7. Java——异常博客作业

    本次任务地址 6. 为如下代码加上异常处理 6.1 改正代码,并增加如下功能.当找不到文件时,需提示用户找不到文件xxx,请重新输入文件名,然后尝试重新打开. 如果是其他异常则提示打开或读取文件失败! ...

  8. 学习MVC中出现的一个BUG

    BUG描述:No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.S ...

  9. 【SSH】——Hibernate三种状态之间的转化

    Hibernate的三种状态为:transient.persistent和detached.对这三种状态的理解可以结合Session缓存,在Session缓存中的状态为persistent,另外两种不 ...

  10. background 背景图铺满界面

    background <body background="/image/1.png" style=" background-repeat:no-repeat ; b ...