今天尝试将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. 简单的java采集程序二

    继[简单的java采集程序],这里将完成对整个网站的号码段的采集任务. [使用预编译+批处理采集网页内容至数据库表中]          在之前我们用statement类来创建sql语句的执行对象,以 ...

  2. 201621044079 week05-继承、多态、抽象类与接口

    作业05-继承.多态.抽象类与接口 1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 接口 interface关键字 implements has-a;comparable co ...

  3. PAT 1005 继续(3n+1)猜想

    https://pintia.cn/problem-sets/994805260223102976/problems/994805320306507776 卡拉兹(Callatz)猜想已经在1001中 ...

  4. vue.js的特点-1

    1. Vue.js是数据驱动的,无需手动操作DOM. 它通过一些特殊的HTML语法,将DOM和数据绑定起来.一旦你创建了绑定,DOM将和数据保持同步,每当变更了数据,DOM也会相应的更新. 2. MV ...

  5. Java中Model1和Model2

    Model1和Model2是java web的两种架构模式.这两种模式各有优缺点,都有各自适合使用的场景. Model1 首先,从分层的角度说,Model1模式可以看作是由两层组成:视图层和模型层. ...

  6. perf原理再看

    vim ./arch/x86/kernel/hw_breakpoint.c perf如何控制采样的频率 perf采样不同的事件,得到的不是一样 cycles: 向PMU中增加不同的函数,增加不同 使用 ...

  7. IPad Pro 2018 & sketch

    IPad Pro 2018 & sketch https://sketch.cloud/s/MyY5w/LJmLgW

  8. CSS兼容性总结

    一.针对IE6的 !important 必须写在前面,例如: background:#9C6 !important;background:#999; 二.CSS HACK //IE6 专用 _heig ...

  9. Spring中Resource接口的前缀书写格式

    Resource template = ctx.getResource("classpath:some/resource/path/myTemplate.txt");   //这个 ...

  10. Linux命令的返回值

    转摘自:http://hi.baidu.com/suchshow/item/230255b6caab369218469732 在 Linux 下,不管你是启动一个桌面程序也好,还是在控制台下运行命令, ...