linux下apache和tomcat 自動啓動

在Linux系統中我通常採用編譯源碼的方式來安裝Apache,有兩種方法可讓Apache在系統啓動時自動啓動。
1. 在/etc/rc.d/rc.local中增長啓動apache的命令,例如:/usr/local/httpd/bin/apachectl start
2. 將apache註冊爲系統服務
首先將apachectl命令拷貝至/etc/rc.d/init.d目錄下,更名爲httpd
使用編輯器打開httpd文件,並在第一行#!/bin/sh下增長兩行文字以下
# chkconfig: 35 70 30
# description: Apache
接着註冊該服務
chkconfig --add httpd
一切OK了,啓動服務
service httpd start
其中所增長的第二行中三個數字第一個表示在運行級別3和5下啓動apache,第2、三是關於啓動和中止的優先級配置,可有可無。




前幾天總結了使用JSVC來設置tomcat做爲linux服務並
且開機自動啓動,可是若是要更專業一點來控制tomcat的啓動 ,使用Java Service Wrapper應該不失爲一個好的選擇,下面來總結一下Java Service Wrapper在Linux中對於tomcat啓動的設置:

一、安裝JDK、Tomcat,此處略過。好比tomcat安裝在 /opt/tomcat目錄中。

2、使用命令wget 下載Java Service Wrapper(目前版本wrapper-linux-x86-32-3.2.3,官網: http://wrapper.tanukisoftware.org), 用命令tar -zxvc wrapper-linux-x86-32-3.2.3.tar .gz 解壓,獲得目錄wrapper-linux-x86-32-3.2.3,使用ln -s wrapper-linux-x86-32-3.2.3 wrapper 給目錄wrapper-linux-x86-32-3.2.3 建一個名稱爲wrapper的快捷方式。

3、複製wrapper\src\bin\sh.script .in到/opt/tomcat/bin目錄,重命名爲tomca t
複製wrapper\src\conf\wrapper .conf.in到/opt/tomcat/conf目錄,重命名爲wrapper.conf
複製wrapper\src\lib\lib目錄下的全部3個文件 到/opt/tomcat/lib目錄
複製wrapper\bin目錄下的wrapper文件到 /opt/tomcat/bin目錄

4、修改/opt/testapp/bin/tomcat文件
APP_NAME="tomcat"
APP_LONG_NAME="Tomcat Application Server"
WRAPPER_CMD="./wrapper"
WRAPPER_CONF="../conf/wrapper .conf"
賦予執行權限
chmod 775 /opt/tomcat/bin/tomcat
chmod 775 /opt/tomcat/bin/tomcat

5、修改/opt/tomcat/conf/wrapper .conf文件,如:
#***************************** ****************************** *********
# Wrapper Properties
#***************************** ****************************** *********
# Java Application
# 設置環境變量
set.JAVA_HOME=/usr/java/jdk1.6 .0_01
set.CATALINA_HOME=/opt/tomcat
set.CATALINA_BASE=/opt/tomcat
wrapper.java.command=/usr/java /jdk1.6.0_01/bin/java

# Java Main class. This class must implement the WrapperListener interface
# or guarantee that the WrapperManager class is initialized. Helper
# classes are provided to do this for you. See the Integration section
# of the documentation for details.
# 使用WrapperStartStopApp,這樣能夠經過命令帶 start/stop來啓動/中止程序。
wrapper.java.mainclass=org .tanukisoftware.wrapper .WrapperStartStopApp

# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
# 設置執行tomcat的classpath文件
wrapper.java.classpath.1= %CATALINA_HOME%/lib/wrapper.jar
wrapper.java.classpath.2= %CATALINA_BASE%/bin/bootstrap .jar

# Java Library Path (location of Wrapper.DLL or libwrapper.so)
# 設置tomcat的lib路徑
wrapper.java.library.path.1= %CATALINA_HOME%/lib/

# Java Additional Parameters
# 設置額外參數
wrapper.java.additional.1= -Djava.endorsed.dirs=%CATALINA _HOME%/common/endorsed
wrapper.java.additional.2= -Dcatalina.base=%CATALINA_BASE%
wrapper.java.additional.3= -Dcatalina.home=%CATALINA_HOME%
wrapper.java.additional.4= -Djava.io.tmpdir=%CATALINA _BASE%/temp

# Initial Java Heap Size (in MB)
# 設置tomcat的JVM初始化堆的大小
wrapper.java.initmemory=128

# Maximum Java Heap Size (in MB)
# 設置tomcat的JVM堆的最大值
wrapper.java.maxmemory=512

# Application parameters. Add parameters as needed starting from 1
# 設置啓動、中止和重啓參數
wrapper.app.parameter.1=org .apache.catalina.startup .Bootstrap
wrapper.app.parameter.2=1
wrapper.app.parameter.3=start

wrapper.app.parameter.4=org .apache.catalina.startup .Bootstrap
wrapper.app.parameter.5=true
wrapper.app.parameter.6=1
wrapper.app.parameter.7=stop

wrapper.filter.trigger.1=java .lang.OutOfMemoryError
wrapper.filter.action.1=RESTART

#***************************** ****************************** *********
# Wrapper Logging Properties
#***************************** ****************************** *********
# Format of output for the console. (See docs for formats)
wrapper.console.format=PM

# Log Level for console output. (See docs for log levels)
wrapper.console.loglevel=INFO

# Log file to use for wrapper output logging.
# 設置log文件路徑
wrapper.logfile=%CATALINA_BASE %/logs/wrapper.log

# Format of output for the log file. (See docs for formats)
wrapper.logfile.format=LPTM

# Log Level for log file output. (See docs for log levels)
wrapper.logfile.loglevel=INFO

# Maximum size that the log file will be allowed to grow to before
# the log is rolled. Size is specified in bytes. The default value
# of 0, disables log rolling. May abbreviate with the 'k' (kb) or
# 'm' (mb) suffix. For example: 10m = 10 megabytes.
# 設置log文件最大值
wrapper.logfile.maxsize=5

# Maximum number of rolled log files which will be allowed before old
# files are deleted. The default value of 0 implies no limit.
#設置log文件最多個數
wrapper.logfile.maxfiles=10

# Log Level for sys/event log output. (See docs for log levels)
wrapper.syslog.loglevel=NONE

#***************************** ****************************** *********
# Wrapper Windows Properties
#***************************** ****************************** *********
# Title to use when running as a console
# windows下tomcat控制檯名稱
wrapper.console.title=Tomcat6 Application Server

#***************************** ****************************** *********
# Wrapper Windows NT/2000/XP Service Properties
#***************************** ****************************** *********
# WARNING - Do not modify any of these properties when an application
# using this configuration file has been installed as a service.
# Please uninstall the service before modifying this section. The
# service can then be reinstalled.

# Name of the service
# 設置服務名稱
wrapper.ntservice.name=tomcat6

# Display name of the service
wrapper.ntservice.displayname= @app.long.name@

# Description of the service
wrapper.ntservice.description= @app.description@

# Service dependencies. Add dependencies as needed starting from 1
wrapper.ntservice.dependency.1=

# Mode in which the service is installed. AUTO_START or DEMAND_START
# 設置容許Tomcat服務自動啓動
wrapper.ntservice.starttype =AUTO_START

# Allow the service to interact with the desktop.
wrapper.ntservice.interactive =false

6、設置tomcat開機自動運行:
ln -s /opt/tomcat/bin/tomcat /etc/init.d/tomcat


7、測試,執行命令:service tomcat start|stop|restart|status 至此,使用Java Service Wrapper來設置Tomcat做爲Linux的服務完成 ,今後過程看來,Java Service Wrapper對tomcat的控制程度比tomcat自帶的JS VC深刻多了。 目錄結構: /opt/tomcat/bin                  | tomcat                  | wrapper /opt/tomcat/logs                  | wrapper.log(程序運行時自動產生) /opt/tomcat/conf                  | wrapper.conf /opt/tomcat/lib                  | libwrapper.so                  | wrapper.jar                  | test.jar
相關文章
相關標籤/搜索