今天尝试将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. Android之ViewPager 第二课

    在这里只粘贴部分代码 在第一课中,只有View滑动完毕,才触发动画效果,令滑块移动,在第二课中,将实现滑块与View同步运行. SecondActivity.java package com.andr ...

  2. SpringMVC 上传图片保存到服务器 同时更改图片名称保存至数据库

    @RequestMapping(value = "/save.do", method = RequestMethod.POST)    public String saveDriv ...

  3. JAVA-I/O流任务

    作业地址 5. Scanner基本概念组装对象 编写public static List readStudents(String fileName)从fileName指定的文本文件中读取所有学生,并将 ...

  4. JVM(2)——GC算法和收集器

    一.引入 上篇博客<JVM--简介>中主要介绍了JVM的内存模型,思考一下: 为什么要划分堆.栈.方法区等? 为什么把不同种类的数据信息分别存放? 答案可以分为很多很多条,这里就说一个方面 ...

  5. hdu 2199 Can you solve this equation? (二分法)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  6. AtCoder 神题汇总

    记录平时打 AtCoder 比赛时遇到的一些神题. Tenka1 Programmer Contest 2019 D Three Colors 题目大意 有 $n$ 个正整数 $a_1, a_2,\d ...

  7. HDU 6201 transaction transaction transaction(拆点最长路)

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  8. 【题解】SCOI2010幸运数字

    最近在学习容斥相关,于是就看到了这个题.一开始以为是补集转化,但是观察一下马上发现不可行,好像直接做会比较容易一些.一个数满足要求的充要条件即为是一个幸运数字的倍数,那么容斥可以轻松搞定,只要枚举是一 ...

  9. composer应用

    ubentu安装 进入自己的项目根目录cd/path/to/my/project 下载composer curl -s http://getcomposer.org/installer 把这个文件移到 ...

  10. WCF分布式开发步步为赢(13):WCF服务离线操作与消息队列MSMQ

    之前曾经写过一个关于MSMQ消息队列的文章:WCF分布式开发必备知识(1):MSMQ消息队列 ,当时的目的也是用它来作为学习WCF 消息队列MSMQ编程的基础文章.在那篇文章里,我们详细介绍了MSMQ ...