Linux6下部署2個Tomcat7.0.40及註冊成服務

來源:互聯網
上載者:User

Linux6下部署2個Tomcat7.0.40及註冊成服務 [root@Tomcat conf]# cd /opt/[root@Tomcat opt]# lltotal 16drwxr-xr-x. 8  500  500 4096 Apr  4 19:52 jdk1.7.0_21drwxr-xr-x. 2 root root 4096 May 10  2012 rhdrwxr-xr-x. 9 root root 4096 May 31 00:23 TomcatAdrwxr-xr-x. 9 root root 4096 May 31 00:26 TomcatB[root@Tomcat opt]# ls /etc/init.d/Tomcat*/etc/init.d/TomcatA  /etc/init.d/TomcatB[root@Tomcat opt]# ls /tmp/hsperfdata_root  tomcatA_process_count.txt  tomcatB_process_count.txt  yum.log[root@Tomcat opt]# chkconfig --add TomcatA[root@Tomcat opt]# chkconfig --add TomcatB[root@Tomcat opt]# chkconfig --list|grep TomcatTomcatA         0:off   1:off   2:on    3:on    4:on    5:on    6:offTomcatB         0:off   1:off   2:on    3:on    4:on    5:on    6:off  [root@Tomcat bin]# more /etc/init.d/TomcatA#!/bin/bash#chkconfig: 2345 10 90#description:TomcatA serviceJAVA_HOME=/opt/jdk1.7.0_21CATALINA_HOME=/opt/TomcatATOMCAT_START=$CATALINA_HOME/bin/startup.shTOMCAT_STOP=$CATALINA_HOME/bin/shutdown.sh # source function library.. /etc/rc.d/init.d/functions# check that networking is up.[ "${NETWORKING}" = "no" ] && exit 0# check for tomcat scriptif [ ! -f $CATALINA_HOME/bin/catalina.sh ]; then         echo "TomcatA not valilable..."        exitfistart(){        echo -n "Starting TomcatA: "        daemon $TOMCAT_START        echo        touch /var/lock/subsys/tomcat}stop(){                ps ax --width=1000 | grep "/opt/TomcatA/temp [o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'  | wc | awk '{print $2}' > /tmp/tomcatA_process_count.txt        read line < /tmp/tomcatA_process_count.txt        if [ $line -gt 0 ]; then                echo -n "TomcatA ( pid "                ps ax --width=1000 | grep "/opt/TomcatA/temp org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'                echo -n ") is running..."                                echo                                 echo -n $"Shutting down TomcatA: "                                daemon $TOMCAT_STOP                                rm -f /var/lock/subsys/tomcat.pid echo        else                echo "TomcatA is stopped"        fi}restart(){        stop        start}status(){        ps ax --width=1000 | grep "/opt/TomcatA/temp [o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'  | wc | awk '{print $2}' > /tmp/tomcatA_process_count.txt        read line < /tmp/tomcatA_process_count.txt        if [ $line -gt 0 ]; then                echo -n "TomcatA ( pid "                ps ax --width=1000 | grep "/opt/TomcatA/temp org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'                echo -n ") is running..."                echo        else                echo "TomcatA is stopped"        fi}case "$1" in        start)                start ;;        stop)                stop ;;        restart)                stop                sleep 3                start ;;        status)                status ;;        *)                echo "Usage: TomcatA {start|stop|restart|status}"                exit 1esacexit 0 [root@Tomcat bin]#  [root@Tomcat bin]# more /etc/init.d/TomcatB#!/bin/bash#chkconfig: 2345 10 90#description:TomcatB serviceJAVA_HOME=/opt/jdk1.7.0_21CATALINA_HOME=/opt/TomcatBTOMCAT_START=$CATALINA_HOME/bin/startup.shTOMCAT_STOP=$CATALINA_HOME/bin/shutdown.sh # source function library.. /etc/rc.d/init.d/functions# check that networking is up.[ "${NETWORKING}" = "no" ] && exit 0# check for tomcat scriptif [ ! -f $CATALINA_HOME/bin/catalina.sh ]; then         echo "TomcatB not valilable..."        exitfistart(){        echo -n "Starting TomcatB: "        daemon $TOMCAT_START        echo        touch /var/lock/subsys/tomcat}stop(){                ps ax --width=1000 | grep "/opt/TomcatB/temp [o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'  | wc | awk '{print $2}' > /tmp/tomcatB_process_count.txt        read line < /tmp/tomcatB_process_count.txt        if [ $line -gt 0 ]; then                echo -n "TomcatB ( pid "                ps ax --width=1000 | grep "/opt/TomcatB/temp org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'                echo -n ") is running..."                                echo                                 echo -n $"Shutting down Tomcat: "                                daemon $TOMCAT_STOP                                rm -f /var/lock/subsys/tomcat.pid echo        else                echo "TomcatB is stopped"        fi}restart(){        stop        start}status(){        ps ax --width=1000 | grep "/opt/TomcatB/temp [o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'  | wc | awk '{print $2}' > /tmp/tomcatB_process_count.txt        read line < /tmp/tomcatB_process_count.txt        if [ $line -gt 0 ]; then                echo -n "TomcatB ( pid "                ps ax --width=1000 | grep "/opt/TomcatB/temp org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'                echo -n ") is running..."                echo        else                echo "TomcatB is stopped"        fi}case "$1" in        start)                start ;;        stop)                stop ;;        restart)                stop                sleep 3                start ;;        status)                status ;;        *)                echo "Usage: TomcatB {start|stop|restart|status}"                exit 1esacexit 0 [root@Tomcat bin]在2個tomcat的bin目錄下修改setclasspath.sh,添加JAVA_HOME環境變數 [root@Tomcat bin]# more /opt/TomcatA/bin/setclasspath.sh#!/bin/sh # 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. # -----------------------------------------------------------------------------# Set JAVA_HOME or JRE_HOME if not already set, ensure any provided settings# are valid and consistent with the selected start-up options and set up the# endorsed directory.## $Id: setclasspath.sh 1430568 2013-01-08 22:08:57Z schultz $# -----------------------------------------------------------------------------export JAVA_HOME=/opt/jdk1.7.0_21 # Make sure prerequisite environment variables are setif [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then  if $darwin; then    # Bugzilla 54390    if [ -x '/usr/libexec/java_home' ] ; then      export JAVA_HOME=`/usr/libexec/java_home`    # Bugzilla 37284 (reviewed).    elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then      export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home"    fi  else    JAVA_PATH=`which java 2>/dev/null`    if [ "x$JAVA_PATH" != "x" ]; then      JAVA_PATH=`dirname $JAVA_PATH 2>/dev/null`      JRE_HOME=`dirname $JAVA_PATH 2>/dev/null`    fi    if [ "x$JRE_HOME" = "x" ]; then      # XXX: Should we try other locations?      if [ -x /usr/bin/java ]; then        JRE_HOME=/usr      fi    fi  fi  if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then    echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"    echo "At least one of these environment variable is needed to run this program"    exit 1  fifiif [ -z "$JAVA_HOME" -a "$1" = "debug" ]; then  echo "JAVA_HOME should point to a JDK in order to run in debug mode."  exit 1fiif [ -z "$JRE_HOME" ]; then  JRE_HOME="$JAVA_HOME"fi # If we're running under jdb, we need a full jdk.if [ "$1" = "debug" ] ; then  if [ "$os400" = "true" ]; then    if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/javac ]; then      echo "The JAVA_HOME environment variable is not defined correctly"      echo "This environment variable is needed to run this program"      echo "NB: JAVA_HOME should point to a JDK not a JRE"      exit 1    fi  else    if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/jdb -o ! -x "$JAVA_HOME"/bin/javac ]; then      echo "The JAVA_HOME environment variable is not defined correctly"      echo "This environment variable is needed to run this program"      echo "NB: JAVA_HOME should point to a JDK not a JRE"      exit 1    fi  fifi # Don't override the endorsed dir if the user has set it previouslyif [ -z "$JAVA_ENDORSED_DIRS" ]; then  # Set the default -Djava.endorsed.dirs argument  JAVA_ENDORSED_DIRS="$CATALINA_HOME"/endorsedfi # Set standard commands for invoking Java._RUNJAVA="$JRE_HOME"/bin/javaif [ "$os400" != "true" ]; then  _RUNJDB="$JAVA_HOME"/bin/jdbfi[root@Tomcat bin] 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.