在Linux下安装Tomcat 5.5

1. 下载最新版的tomcat5.5 2. 解压缩到/opt/下,并创建软链接/opt/tomcat -> /opt/apache-tomcat-5.5.31/ 3. 修改/opt/tomcat/bin下的catalina.sh文件,在开始部分追加以下内容

export LANG=zh_CN.GB18030
export LC_ALL=zh_CN.GB18030
JAVA_OPTS="-server -Xms512m -Xmx1024m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m"
CATALINA_PID=/var/run/tomcat.pid

4. 修改shutdown.sh,增加-force选项 这样可以保证shutdown.sh 更快,更有效的执行 即将

exec "$PRGDIR"/"$EXECUTABLE" stop "$@"

修改为

exec "$PRGDIR"/"$EXECUTABLE" stop -force "$@"

5. 编写/etc/init.d/tomcat文件 一个典型的tomcat文件为

#!/bin/sh
# chkconfig: - 10 90
# description: Starts and Stops the Tomcat daemon.
# processname: jsvc
# pidfile: /var/run/jsvc.pid
# config:
#
# Source function library
. /etc/rc.d/init.d/functions
#
##############################################################################
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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=/opt/jre
#JAVA_HOME=/opt/jdk
CATALINA_HOME=/opt/tomcat
DAEMON_HOME=$CATALINA_HOME
TOMCAT_USER=tomcat

# for multi instances adapt those lines.
TMP_DIR=/var/tmp
PID_FILE=/var/run/jsvc.pid
CATALINA_BASE=$CATALINA_HOME

JAVA_OPTS="-server -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m"
#CATALINA_OPTS="-Djava.library.path=/home/jfclere/jakarta-tomcat-connectors/jni/native/.libs"
CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar

start(){
  echo -n starting tomcat...
  $DAEMON_HOME/bin/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' \
  $JAVA_OPTS \
  $CATALINA_OPTS \
  -cp $CLASSPATH \
  org.apache.catalina.startup.Bootstrap
  [ "$?" -eq 0 ] && success $"startup" || failure $"startup"
  echo
}

stop(){
  echo -n stopping tomcat...
  $DAEMON_HOME/bin/jsvc \
  -stop \
  -pidfile $PID_FILE \
  org.apache.catalina.startup.Bootstrap
  [ "$?" -eq 0 ] && success $"shutdown" || failure $"shutdown"
  echo
}

status(){
  ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap" | awk '{printf $1 " "}' | wc | awk '{printf $2}' >/tmp/tomcat_process_count.txt
  read line < /tmp/tomcat_process_count.txt
  if [ $line -gt 0 ]; then
    echo -n "tomcat ( pid "
    ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap" | awk '{printf $1 " "}'
    echo ") is running..."
  else
    echo "tomcat is stopped"
  fi
}

case "$1" in
  start)
    start
    exit $?
    ;;
  stop)
    stop
    exit $?
    ;;
  restart)
    stop
    sleep 3
    start
    exit $?
    ;;
  status)
    status
    exit $?
    ;;
  *)
    echo "Usage: tomcat {start|stop|restart|status}"
    exit 1
    ;;
esac

exit $?

 

6. 将tomcat加入到系统自动启动中

chkconfig --add tomcat --level 345

7. 下载tomcat的管理工具(Administration Web Application) http://tomcat.apache.org/download-55.cgi 配置admin及manager应用的IP地址限制(只允许办公室及内网可以访问) 在 /opt/tomcat/server/webapps/admin/admin.xml 及 /opt/tomcat/server/webapps/manager/manager.xml中的<Context标签中,

  

配置帐号/opt/tomcat/conf/tomcat-users.xml

  
  
  

8. 可选项:将tomcat设置为非root帐号启动 (注意,须将一些目录设置为tomcat帐号可写,或者指定属于tomcat帐号的目录),参考http://linux-sxs.org/internet_serving/c140.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值