傻子一个

一路走来~~

 

ubuntu8.04 下安装tomcat6,并开机自启动

整合网络上的各种零散的资料,并经过本人的实践操作,整理,转载请注明出处。

1.安装jdk6

       shell>sudo apt-get install sun-java6-jdk(用新得立软件包安装)

2.下载tomcat6

       下载地址是:http://tomcat.apache.org/

       本次安装的是:apache-tomcat-6.0.18.tar.gz

3.安装

       将压缩包拷贝到 /opt 下(个人喜好,可以放在别处)

              shell>sudo cp apache-tomcat-6.0.18.tar.gz /opt

       解压文件

              shell>cd /opt

              shell>sudo tar zxvf apache-tomcat-6.0.18.tar.gz

       解压完成后,会在 /opt 下生文件夹 apache-tomcat-6.0.18

       为了操作方便,在/usr/local 下建立软链接,名字是tomcat6

              shell>cd /usr/local

shell>sudo ln -s /opt/apache-tomcat-6.0.18 tomcat6

       测试tomcat是否能够正常启动

              shell>sudo /usr/local/tomcat6/bin/startup.sh

              打开firefox,输入http://localhost:8080,如果正常访问,则表示成功。

4.设置tomcat开机自启动

       根据tomcat官方的document说明,linux下设置开机自启动可以使用jsvctomcat包里自带)

       设置tomcat以独立的用户运行(防止以root运行,权限太大)

              shell>sudo useradd -d /usr/local/tomcat6 -s /usr/sbin/nologin tomcat

              上边的这个命令是添加一个系统用户tomcat,并且设置为不可登录系统。

       设置用户tomcat tomcat6的访问权限

              shell>sudo chown -R tomcat:tomcat /usr/local/tomcat6

              shell>sudo chown -R tomcat:tomcat /opt/apache-tomcat-6.0.18

       安装jsvc

              前提需要系统安装了gcc(系统一般默认安装)autoconflibc6-dev

                     shell>sudo apt-get install .....

              解压jsvc.tar.gz,并准备编译

                     shell>cd /usr/local/tomcat6/bin

                     shell>sudo tar zxvf jsvc.tar.gz

                     shell>cd jsvc-src

                     shell>sudo sh support/buildconf.sh

                     如果成功,命令终端会打出:

                            support/buildconf.sh: configure script generated successfully

              configure添加执行权限

                     shell>sudo chmod 755 configure

              编译     

                     shell>sudo ./configure –with-java=/usr/lib/jvm/java-6-sun (java的安装路径)

                     shell>sudo make

                      如果没有出现错误,jsvc就安装成功了。

              设置启动脚本

                     拷贝jsvc带的tomcat5.sh 脚本拷贝到 /etc/init.d/ 下,并改名为tomcat

                     shell>sudo cp /usr/local/tomcat6/bin/jsvc-src/native/Tomcat5.sh /etc/init.d/tomcat

               修改/etc/init.d/tomcat文件

                     shell>sudo gedit /etc/init.d/tomcat

 

              文件内容如下(修改的地方有颜色和注释说明):

#!/bin/sh

##############################################################################

#

#   Copyright 2004 The Apache Software Foundation.

#

#   Licensed under the Apache License, Version 2.0 (the "License");

#   you may not use this file except in compliance with the License.

#   You may obtain a copy of the License at

#

#       http://www.apache.org/licenses/LICENSE-2.0

#

#   Unless required by applicable law or agreed to in writing, software

#   distributed under the License is distributed on an "AS IS" BASIS,

#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

#   See the License for the specific language governing permissions and

#   limitations under the License.

##############################################################################

#

# 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"/>

#

# That is for Tomcat-5.0.x (Apache Tomcat/5.0)

#

# Adapt the following lines to your configuration

JAVA_HOME=/usr/lib/jvm/java-6-sun               #这个地方设置为机器的jdk的位置

CATALINA_HOME=/usr/local/tomcat6            #tomcat的安装位置(软链接)

DAEMON_HOME=/usr/local/tomcat6/bin       #tomcat启动程序的位置

TOMCAT_USER=tomcat                                  #tomcat 的用户

 

 

# for multi instances adapt those lines.

TMP_DIR=/var/tmp

PID_FILE=/var/run/jsvc.pid

CATALINA_BASE=/usr/local/tomcat6             #tomcat的安装位置

 

#注释掉下边这句

#CATALINA_OPTS="-Djava.library.path=/home/jfclere/jakarta-tomcat-connectors/jni/native/.libs"

#添加下边这句

CATALINA_OPTS=

CLASSPATH=\

$JAVA_HOME/lib/tools.jar:\

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

$CATALINA_HOME/bin/bootstrap.jar

 

 

case "$1" in

  start)

    #

    # Start Tomcat

    #

    $DAEMON_HOME/jsvc-src/jsvc \                #设置正确的jsvc程序的位置

    -user $TOMCAT_USER \

    -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

    #

    # To get a verbose JVM

    #-verbose \

    # To get a debug of jsvc.

    #-debug \

    exit $?

    ;;

 

 

  stop)

    #

    # Stop Tomcat

    #

    $DAEMON_HOME/jsvc-src/jsvc \                      #设置正确的jsvc程序的位置

    -stop \

    -pidfile $PID_FILE \

    org.apache.catalina.startup.Bootstrap

    exit $?

    ;;

 

 

  *)

    echo "Usage tomcat.sh start/stop"

    exit 1;;

esac

 

       设置 /etc/init.d/tomcat的可执行权限

              Shell>sudo chmod 755 /etc/init.d/tomcat

/etc/rc2.d/下设置一个/etc/init.d/tomcat 的软链接

              shell>cd /etc/rc2.d/

              shell>sudo ln -s /etc/init.d/tomcat S16tomcat

              [:rc2.d目录下的文件要以S后就数字开头,表示启动的顺序。而rc2.d中的2,表示这个目录下文件在开机时的运行级别(runlevel)2]

 

5.结束

       重新启动系统 shell>sudo reboot –n, 启动后,就可以在FF中直接输入http://localhost:8080 ,如果看到首页,即表示安装成功

             

      

posted on 2008-08-13 08:20 老文 阅读(1626) 评论(0)  编辑  收藏 所属分类: ubuntu(linux)上应用程序相关


只有注册用户登录后才能发表评论。


网站导航:
 

导航

常用链接

留言簿(2)

随笔分类(29)

收藏夹(1)

My Work

学习文章

软件使用

最新随笔

最新评论