您的位置:首页 > 运维架构 > Tomcat

linux 下tomcat6 配置为服务

2012-03-24 07:50 190 查看
本人从官网http://tomcat.apache.org/上面下载的6.0.1_31版本,并解压包后改名存放在:/usr/share/tomcat6

本人使用的是root用户登录,下面就说说具体的操作步骤,

1、在/usr/share/tomcat6/bin中有commons-daemon-native.tar.gz 压缩包

2、解压commons-daemon-native.tar.gz

[root@localhost ~]# tar -zxvf commons-daemon-native.tar.gz

3、解压完成,出现commons-daemon-1.0.2-native-src文件夹(目录)

1、
进入commons-daemon-1.0.2-native-src 下的unix目录

[root@localhost ~]# ls

[root@localhost ~]# cdcommons-daemon-1.0.2-native-src/unix

2、
发现configure 配置文件,执行如下修改属性的命令

[root@localhost ~]# chmod 777 configure

4、
执行configure 文件

[root@localhost ~]# ./configure

5、
编译

[root@localhost ~]# make #会报错

[root@localhost ~]# make clean

[root@localhost ~]# make #重新编译成功

6、 编译完成后出现jsvc文件夹,复制jsvc到/usr/share/tomcat6/bin目录下面

[root@localhost ~]# cp jsvc /usr/share/tomcat6/bin

------------------------------------------------------------------------------------

10、在/etc/init.d/目录下编写tomcat6启动服务配置文件。

[root@localhost ~]#cd /etc/init.d/

[root@localhost ~]# vi tomcat6

录入以下内容

#!/bin/sh

# tomcat: Start/Stop/Restart tomcat

#

# chkconfig: 2345 85 15

# description: Apache tomcat6

# Small shell script to show how to start/stop Tomcat using jsvc

# If you want to have Tomcat running on port 80 please modify the server.xml

# file:

#

# <!-- Define a non-SSL HTTP/1.1 Connector on port 80 -->

# <Connector className="org.apache.catalina.connector.http.HttpConnector"

# port="80" minProcessors="5" maxProcessors="75"

# enableLookups="true" redirectPort="8443"

# acceptCount="10" debug="0" connectionTimeout="60000"/>

#

JAVA_HOME=/usr/java/jdk1.6.0_31 #根据自己的实际jdk位置来修改

CATALINA_HOME=/usr/share/tomcat6 #根据自己实际tomcat位置来修改

DAEMON_HOME=$CATALINA_HOME/bin

# I did not use the user.

#TOMCAT_USER=tomcat

# for multi instances adapt those lines.

TMP_DIR=$CATALINA_HOME/tmp

PID_FILE=/var/run/jsvc.pid

CATALINA_BASE=$CATALINA_HOME

. /etc/rc.d/init.d/functions

CATALINA_OPTS=

CLASSPATH=\

$JAVA_HOME/lib/tools.jar:\

$CATALINA_HOME/bin/commons-daemon.jar:\

$CATALINA_HOME/bin/bootstrap.jar

start() {

echo -n $"Starting Tomcat6: "

# If you want to specify a user to run Tomcat.

#increase the 'user $ TOMCAT_USER \' to the parameter list.

$DAEMON_HOME/jsvc \

-home $JAVA_HOME \

-Dcatalina.home=$CATALINA_HOME \

-Dcatalina.base=$CATALINA_BASE \

-Djava.io.tmpdir=$TMP_DIR \

-wait 10 \

-pidfile $PID_FILE \

-outfile $CATALINA_HOME/logs/catalina.out \

-errfile '&1' \

$CATALINA_OPTS \

-cp $CLASSPATH \

org.apache.catalina.startup.Bootstrap

echo"*****************************[ok]"

}

stop() {

echo -n $"Stopping Tomcat6: "

#

$DAEMON_HOME/jsvc \

-stop \

-pidfile $PID_FILE \

org.apache.catalina.startup.Bootstrap

echo "*****************************[ok]"

}

status() {

ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap" | awk '{printf $1 " "}' | wc | awk '{print $2}' >/tmp/tomcat_process_count.txt

read line < /tmp/tomcat_process_count.txt

if [ $line -gt 0 ]; then

echo -n "tomcat6 ( pid "

ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap" | awk '{printf $1 " "}'

echo ") is running "

else

echo "Tomcat6 is stopped"

fi

}

case "$1" in

start)

# Start Tomcat

start

exit $?

;;

stop)

# Stop Tomcat

stop

exit $?

;;

restart)

# Restart Tomcat

stop

sleep 3

start

exit $?

;;

status)

status

exit $?

;;

*)

echo "Usage: tomcat6 {start|stop|restart|status}"

exit 1;;

esac

#####

####

11、录入完成,按Esc键。输入: wq保存退出并赋予/etc/init.d/tomcat6文件可执行权限

[root@localhost~]# chmod 777 /etc/init.d/tomcat6

------------------添加服务-----------------------------------------

12、[root@localhost~] #chkconfig --add tomcat6 ##添加tomcat服务

13、[root@localhost~] #chkconfig –list |grep tomcat6 ##查看tomcat服务是否被添加

--------------------启动服务---------------------------------------------

14、[root@localhost~] # service tomcat6 start ##启动tomcat服务

15、[root@localhost~] # service tomcat6 stop ##停止tomcat服务

16、[root@localhost~] # service tomcat6 restart ##重启tomcat

17、[root@localhost~] # service tomcat6 status ##查看tomcat服务启动状态
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: