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

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="ProgId" content="Word.Document"> <meta name="Generator" content="Microsoft Word 11"> <meta name="Originator" content="Microsoft Word 11"> <link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"> <smarttagtype namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="chsdate"></smarttagtype><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL/> <w:BalanceSingleByteDoubleByteWidth/> <w:DoNotLeaveBackslashAlone/> <w:ULTrailSpace/> <w:DoNotExpandShiftReturn/> <w:AdjustLineHeightInTable/> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:UseFELayout/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles deflockedstate="false" latentstylecount="156"> </w:LatentStyles> </xml><![endif]--><!--[if !mso]><object classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id="ieooui"></object> <style> st1\:*{behavior:url(#ieooui) } </style> <![endif]--><style> <!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"\@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:none; mso-hyphenate:none; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:.5pt; mso-fareast-language:#00FF;} a:link, span.MsoHyperlink {mso-style-parent:""; color:navy; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline; text-underline:single;} p.a, li.a, div.a {mso-style-name:表格内容; margin:0cm; margin-bottom:.0001pt; mso-pagination:no-line-numbers; mso-hyphenate:none; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:.5pt; mso-fareast-language:#00FF;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.25pt 841.85pt; margin:2.0cm 2.0cm 2.0cm 2.0cm; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1; mso-footnote-position:beneath-text;} --> </style> <!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->

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

1.安装jdk6

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

2.下载tomcat6

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

       本次安装的是:apache-tomcat-<chsdate isrocdate="False" islunardate="False" day="30" month="12" year="1899" w:st="on">6.0.18</chsdate>.tar.gz

3.安装

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

              shell>sudo cp apache-tomcat-<chsdate isrocdate="False" islunardate="False" day="30" month="12" year="1899" w:st="on">6.0.18</chsdate>.tar.gz /opt

       解压文件

              shell>cd /opt

              shell>sudo tar zxvf apache-tomcat-<chsdate isrocdate="False" islunardate="False" day="30" month="12" year="1899" w:st="on">6.0.18</chsdate>.tar.gz

       解压完成后,会在 /opt 下生成文件夹 apache-tomcat-<chsdate year="1899" month="12" day="30" islunardate="False" isrocdate="False" w:st="on">6.0.18</chsdate>

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

              shell>cd /usr/local

shell>sudo ln -s /opt/apache-tomcat-<chsdate isrocdate="False" islunardate="False" day="30" month="12" year="1899" w:st="on">6.0.18</chsdate> 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-<chsdate isrocdate="False" islunardate="False" day="30" month="12" year="1899" w:st="on">6.0.18</chsdate>

       安装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 ,如果看到首页,即表示安装成功

             

      

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值