---
title: "Linux下建立Web应用环境(二)"
author: "aumy2008"
date: "2009-10-13T16:55:32Z"
tags: ["Bash", "Linux", "Tomcat", "Web", "nagios"]
slug: "linux-web"
draft: false
lastmod: "2009-10-13T16:55:32Z"
id: 487132
url: "https://aumy2008.iteye.com/blog/487132"
---

遇到问题1：***tomcat: unrecognized service***

配置tomcat自启动服务  
编写tomcat服务文件（见附件）  
放在/etc/initd/下  
执行 chmod +x /etc/init.d/tomcat设置权限，否则会出现***tomcat: unrecognized service***的错误提示

 

问题2：***service tomcat does not support chkconfig***

 \[root@OWLinux ~]# chkconfig --add tomcat

***service tomcat does not support chkconfig***

解决方法1：

完成后是无法用chkconfig --add tomcat设置为自动启动，会显示错误信息：service tomcat does not support chkconfig ，需要修改脚本$CATALINA\_HOME/bin/jsvc-src/native/Tomcat.sh，并cp到/etc/rc.d/init.d。

 

解决方法2：参照[http://www.cactus.org.cn/2008/04/linuxtomcat.html](http://www.cactus.org.cn/2008/04/linuxtomcat.html)

在脚本的最前面加上

#!/bin/bash 

# chkconfig: 2345 10 90 

\# description: Starts and Stops the Tomcat daemon.  

再运行命令

sudo /sbin/chkconfig –add tomcat

sudo /sbin/chkconfig –list

看到tomcat，一切搞定。

 

自己更改（执行通过）

#!/bin/sh

\# chkconfig: 345 88 14

\# description: Starts and Stops the Tomcat daemon.

 

问题3：***-bash: ckhconfig: command not found***

\[root@OWLinux ~]#  ckhconfig --list

***-bash: ckhconfig: command not found***

解决：

\[root@OWLinux init.d]# which chkconfig

/sbin/chkconfig

\[root@OWLinux init.d]# /sbin/chkconfig  --list

这样可以看到信息。但没有彻底解决，最终解决：在root的PATH中加了sbin就行。

 

\[root@OWLinux init.d]#  /sbin/chkconfig  --list  tomcat

tomcat          0:off   1:off   2:off   3:on    4:on    5:on    6:off

 

 

问题4：

chkconfig: 2345 10 90    chkconfig: 345 88 14   怎么理解？

其中我们要修改的就是：# chkconfig: 345 99 01 后面的数字部分  
345 99 01  
这三组数字到底是什么意思呢？  
345代表的是\[color="#ff0000"]系统的启动级别。也就是说系统在345的启动级别的时候会启动nagios服务  
99 01 代表的是系统启动的时候 \[color="#ff0000"]应用程序也就是\[color="#ff0000"]服务的启动级别

实践证实，数值越小，就越先启动和关闭。  
理解了这个，那在处理问题的时候就相当简单了，要不然都不知道怎么去修改那个服务的启动顺序。呵呵 

 

2345表示在runlevel 2 3 4 5下被启动操作系统, 20 80 是优先级  
20为启动操作系统, 80为关闭. 即在rcIII.d您可能看到 S20 或者是 K80.

优先即是一个两位数

 

 

Linux下两种自动启动Tomcat的方法

[http://vod.sjtu.edu.cn/help/Article\_Show.asp?ArticleID=626](http://vod.sjtu.edu.cn/help/Article_Show.asp?ArticleID=626)