今天尝试将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. 树莓派配置 USB 无线网卡

    树莓派配置 USB 无线网卡来上网的过程. 本人使用的USB无线网卡型号:EP-N8508GS(树莓派专用型号) 一.检查 USB 无线网卡是否已经正确识别 将无线 USB 网卡插入树莓派后启动树莓派 ...

  2. 软工实践 - 第二十七次作业 Beta 冲刺(5/7)

    队名:起床一起肝活队 组长博客:https://www.cnblogs.com/dawnduck/p/10134471.html 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过 ...

  3. [剑指Offer] 41.和为S的连续正数序列

    题目描述 小明很喜欢数学,有一天他在做数学作业时,要求计算出9~16的和,他马上就写出了正确答案是100.但是他并不满足于此,他在想究竟有多少种连续的正数序列的和为100(至少包括两个数).没多久,他 ...

  4. vue.js 三种方式安装--npm安装

    Vue.js是一个构建数据驱动的 web 界面的渐进式框架.     Vue.js 的目标是通过简单的 API 实现响应的数据绑定和组合的视图组件.它不仅易上手,便于与第三方库或既有项目整合.     ...

  5. Linux总结(二)

      1. 虚拟机安装 a)双系统(不建议初学者一开始去装) b)般建议使用虚拟机来操作试验环境 c)好处:可以模拟真实的环境进行各种的试验和操作 d)在启动之后,在操作的时候会占用一部分的系统资源 1 ...

  6. [Leetcode] subsets ii 求数组所有的子集

    Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: ...

  7. [Leetcode] The minimum depth of binary tree二叉树的最小深度

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  8. jsp电子商务 购物车实现之三 购物车

    CartServlet参考代码 : public void doPost(HttpServletRequest req, HttpServletResponse resp) throws Servle ...

  9. 【NOIP模拟赛】飞(fly) 数论+树状数组

    树状数组一个被发明以来广为流行的数据结构,基于数组,核心是lowerbit()操作.他向前lowerbit()操作为前缀,向后lowerbit()操作为上辖,我们运用树状数组都是使一个由O(1)变为O ...

  10. 论文笔记《Spatial Memory for Context Reasoning in Object Detection》

    好久不写论文笔记了,不是没看,而是很少看到好的或者说值得记的了,今天被xinlei这篇paper炸了出来,这篇被据老大说xinlei自称idea of the year,所以看的时候还是很认真的,然后 ...