linux下JBoss服务器多实例配置学习总结

最近研究下了公司的jboss启动脚本,原来静下心来看脚本也是件快乐的事情,可以学习到很多东东,嘻嘻。

公司有2个项目A和B,jboss端口的配置有所不同, A是通过修改/deploy/jbossweb-tomcat55.sar/server.xml文件中的

 

  <Connector port="8080" address="${jboss.bind.address}"

         maxThreads="250" strategy="ms" maxHttpHeaderSize="8192"

         emptySessionPath="true"

         enableLookups="false" redirectPort="8443" acceptCount="100"

         connectionTimeout="20000" disableUploadTimeout="true"/>

 <Connector port="8009" address="${jboss.bind.address}"

         emptySessionPath="true" enableLookups="false" redirectPort="8443" 

         protocol="AJP/1.3"/>

该段代码来修改jboss端口,而B项目则是通过启用deploy/conf/jboss-server.xml文件中的ServiceBindingManager来统一管理各个jboss实例的端口基本思想如下: 
jboss提供一个服务器端口绑定文件--xxx-bindings.xml,里面定义了多个以server-name为标志的端口,它就作为统一的端口绑定配置文件。然后在每个服务器实例的jboss-server.xml中注册一个端口绑定服务ServiceBindingManager,该服务用参数 
   --ServerName:指定xxx-bindings.xml对应的端口配置 
   --StoreURL: 指定xx-bindings.xml文件的位置 
一旦该服务注册,则Tomcat下server.xml的端口设置被忽略,而启用新的端口配置。 代码如下:

<mbean code=" org.jboss.services.binding.ServiceBindingManager"
     name="jboss.system:service=ServiceBindingManager">
     <attribute name="ServerName"> ports-01</attribute>
     <attribute name="StoreURL"> ${jboss.home.url}/docs/examples/binding-manager/sample-bindings.xml</attribute>
     <attribute name="StoreFactoryClassName">
       org.jboss.services.binding.XMLServicesStoreFactory
     </attribute>
   </mbean>
sample-bindings.xml文件相关tomcat配置端口代码段如下:
  <!-- ********************* tomcat ********************** -->

      <service-config name="jboss.web:service=WebServer"
         delegateClass="org.jboss.services.binding.XSLTFileDelegate"
         >
         <delegate-config>
            <xslt-config configName="ConfigFile"><![CDATA[
   <xsl:stylesheet
         xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>

     <xsl:output method="xml" />
     <xsl:param name="port"/>

      <xsl:variable name="portAJP" select="$port - 71"/>  <!--ajp端口-->
     <xsl:variable name="portHttps" select="$port + 363"/>

     <xsl:template match="/">
       <xsl:apply-templates/>
     </xsl:template>

      <xsl:template match = "Connector">
         <Connector>
            <xsl:for-each select="@*">
            <xsl:choose>
               <xsl:when test="(name() = 'port' and . = '8080')">
                  <xsl:attribute name="port"><xsl:value-of select="$port" /></xsl:attribute>
               </xsl:when>
               <xsl:when test="(name() = 'port' and . = '8009')">
                  <xsl:attribute name="port"><xsl:value-of select="$portAJP" /></xsl:attribute>
               </xsl:when>
               <xsl:when test="(name() = 'redirectPort')">
                  <xsl:attribute name="redirectPort"><xsl:value-of select="$portHttps" /></xsl:attribute>
               </xsl:when>
               <xsl:when test="(name() = 'port' and . = '8443')">
                  <xsl:attribute name="port"><xsl:value-of select="$portHttps" /></xsl:attribute>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>
               </xsl:otherwise>
            </xsl:choose>
            </xsl:for-each>
            <xsl:apply-templates/>
         </Connector>
      </xsl:template>

     <xsl:template match="*|@*">
       <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
       </xsl:copy>
     </xsl:template>
   </xsl:stylesheet>
   ]]>
            </xslt-config>
         </delegate-config>
         <binding port="8180"/>  <!--jboss端口-->
      </service-config>


启动jboss+apache服务:
执行startws.sh即可,相关脚本如下:
startws.sh脚本 :
#!/bin/bash

# determine base directory; preserve where you're running from
BASEDIR="/home/admin/mdm_xj_stone/deploy"


#import var env
. $BASEDIR/bin/env.sh

    STR=`netstat -an |grep '8180'|grep LISTEN`
    if [ ! -z "$STR" ]; then
        echo "warn: check if your jboss port is conflict"
        exit;
    fi

if [ ! -d "$JBOSS_SERVER_HOME" ]; then   
    mkdir -p $JBOSS_SERVER_HOME
        cp -rf $BASEDIR/jbossdomain/. $JBOSS_SERVER_HOME/.
fi

cp -rf $BASEDIR/target/b2b-dw-mdm-bundle-war.war $JBOSS_SERVER_HOME/deploy/mdm.war
cp -rf $BASEDIR/conf/hz-oracle-ds.xml $JBOSS_SERVER_HOME/deploy/oracle-ds.xml
cp -rf $BASEDIR/conf/hz-login-config.xml $JBOSS_SERVER_HOME/conf/login-config.xml
cp -rf $BASEDIR/conf/jboss-service.xml $JBOSS_SERVER_HOME/conf/jboss-service.xml
cp -rf $BASEDIR/lib/ojdbc6.jar $JBOSS_SERVER_HOME/lib/oracle-jdbc.jar
cp -rf $BASEDIR/conf/logs-tomcat-jboss-service.xml $JBOSS_SERVER_HOME/deploy/jbossweb-tomcat55.sar/META-INF/jboss-service.xml

cp -rf $BASEDIR/conf/jboss/jmxconsole/console-users.properties  $JBOSS_SERVER_HOME/conf/props/console-users.properties
cp -rf $BASEDIR/conf/jboss/props/jbossws-users.properties $JBOSS_SERVER_HOME/conf/props/jbossws-users.properties
cp -rf $BASEDIR/conf/jboss/props/jmx-console-users.properties $JBOSS_SERVER_HOME/conf/props/jmx-console-users.properties

rm -rf $JBOSS_SERVER_HOME/deploy/jmx-console.war
rm -rf $JBOSS_SERVER_HOME/deploy/management
rm -rf $JBOSS_SERVER_HOME/deploy/jbossweb-tomcat55.sar/ROOT.war

//启动jboss
$JBOSS_HOME/bin/run.sh  -b 0.0.0.0 1>> $MDM_JBOSS_LOG 2>>$MDM_JBOSS_LOG &

echo 'jboss started...................'

 STARTTIME=`date +"%s"`
 rm index.html -f
 sleep 10 
//由于jboss启动需要一段时间且在后台运行,并将启动日志记录在$MDM_JBOSS_LOG中,故 使用一个循环,如果jboss已启动则wget命令可以将homePage.htm文件下载到当前目录,通过检查当前目录是否有homePage.htm文件,从而得知jboss是否已启动成功,若以启动成功,则继续启动apache
 while true
 do
    wget http://127.0.0.1:8180/mdm/homePage.htm -T 300
    ENDTIME=`date +"%s"`
    COSTTIME=$(($ENDTIME - $STARTTIME))

    if [ ! -f "homePage.htm" ]; then
      sleep 1
      echo -n -e "\rWait Jboss Start: $COSTTIME..."
    else
            sh $BASEDIR/bin/apachectl start   //启动apache
      rm -f homePage.htm 
      echo "HTTP Start in $COSTTIME."
      exit 0; 
    fi
 done

env.sh脚本:
SYSTEM_ROOT=/usr/ali


BASE="/home/admin/mdm_xj_stone/deploy/bin"

export LANG=en_US.iso88591
export SUPPORTED=en_US.iso88591:en_US:en

export JAVA_HOME=/usr/alibaba/java
export JBOSS_HOME=/usr/alibaba/jboss

export JBOSS_CONF=$BASE/conf/jboss

export MDM_JBOSS_LOG=$BASE/../logs/servlet_error_log

export JBOSS_SERVER_HOME=$BASE/../.jboss/default
export JBOSS_SERVER_OPTS=" -Djboss.server.home.dir=$JBOSS_SERVER_HOME -Djboss.server.home.url=file:$JBOSS_SERVER_HOME "
export JAVA_OPTS=" -server -Xmx2g -Xms2g -Xmn256m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 $JBOSS_SERVER_OPTS -Dapplication.codeset=GBK -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "


echo  $JBOSS_SERVER_HOME
echo $JBOSS_SERVER_OPTS

自定义的apachectl如下:
#!/bin/sh
#
# Apache control script designed to allow an easy command line interface
# to controlling Apache.  Written by Marc Slemko, 1997/08/23
# The exit codes returned are:
#       0 - operation completed successfully
#       1 - 
#       2 - usage error
#       3 - httpd could not be started
#       4 - httpd could not be stopped
#       5 - httpd could not be started during a restart
#       6 - httpd could not be restarted during a restart
#       7 - httpd could not be restarted during a graceful restart
#       8 - configuration syntax error
#
# When multiple arguments are given, only the error from the _last_
# one is reported.  Run "apachectl help" for usage info
#
#
# |||||||||||||||||||| START CONFIGURATION SECTION  ||||||||||||||||||||
# --------------------                              --------------------

# determine base directory; preserve where you're running from
cd `dirname $0`/..
BASE=`pwd`   //得到的base路径为当前文件所在路径的上一级目录
SYSTEM_ROOT=/usr/alibaba/httpd

# the path to your PID file
PIDFILE=$BASE/logs/httpd.pid
#
# the path to your httpd binary, including options if necessary
//-d用来指定severroot,默认值为%apache_home%。apache会收索 severroot/conf/httpd.conf文件作为apache启动的端口配置文件

HTTPD="$SYSTEM_ROOT/bin/httpd -d $BASE"    
#
# a command that outputs a formatted text version of the HTML at the
# url given on the command line.  Designed for lynx, however other
# programs may work.  
LYNX="lynx -dump"
#
# the URL to your server's mod_status status page.  If you do not
# have one, then status and fullstatus will not work.
STATUSURL="http://localhost/server-status"
#
# --------------------                              --------------------
# ||||||||||||||||||||   END CONFIGURATION SECTION  ||||||||||||||||||||

ERROR=0
ARGV="$@"
if [ "x$ARGV" = "x" ] ; then 
    ARGS="help"
fi

for ARG in $@ $ARGS
do
    # check for pidfile
    if [ -f $PIDFILE ] ; then
        PID=`cat $PIDFILE`
        if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then
            STATUS="httpd (pid $PID) running"
            RUNNING=1
        else
            STATUS="httpd (pid $PID?) not running"
            RUNNING=0
        fi
    else
        STATUS="httpd (no pid file) not running"
        RUNNING=0
    fi

    case $ARG in
    start)
        if [ $RUNNING -eq 1 ]; then
            echo "$0 $ARG: httpd (pid $PID) already running"
            continue
        fi
        if $HTTPD ; then
            echo "$0 $ARG: httpd started"
        else
            echo "$0 $ARG: httpd could not be started"
            ERROR=3
        fi
        ;;
    stop)
        if [ $RUNNING -eq 0 ]; then
            echo "$0 $ARG: $STATUS"
            continue
        fi
        if kill $PID ; then
            echo "$0 $ARG: httpd stopped"
        else
            echo "$0 $ARG: httpd could not be stopped"
            ERROR=4
        fi
        ;;
    restart)
        if [ $RUNNING -eq 0 ]; then
            echo "$0 $ARG: httpd not running, trying to start"
            if $HTTPD ; then
                echo "$0 $ARG: httpd started"
            else
                echo "$0 $ARG: httpd could not be started"
                ERROR=5
            fi
        else
            if $HTTPD -t >/dev/null 2>&1; then
                if kill -HUP $PID ; then
                    echo "$0 $ARG: httpd restarted"
                else
                    echo "$0 $ARG: httpd could not be restarted"
                    ERROR=6
                fi
            else
                echo "$0 $ARG: configuration broken, ignoring restart"
                echo "$0 $ARG: (run 'apachectl configtest' for details)"
                ERROR=6
            fi
        fi
        ;;
    graceful)
        if [ $RUNNING -eq 0 ]; then
            echo "$0 $ARG: httpd not running, trying to start"
            if $HTTPD ; then
                echo "$0 $ARG: httpd started"
            else
                echo "$0 $ARG: httpd could not be started"
                ERROR=5
            fi
        else
            if $HTTPD -t >/dev/null 2>&1; then
                if kill -USR1 $PID ; then
                    echo "$0 $ARG: httpd gracefully restarted"
                else
                    echo "$0 $ARG: httpd could not be restarted"
                    ERROR=7
                fi
            else
                echo "$0 $ARG: configuration broken, ignoring restart"
                echo "$0 $ARG: (run 'apachectl configtest' for details)"
                ERROR=7
            fi
        fi
        ;;
    status)
        $LYNX $STATUSURL | awk ' /process$/ { print; exit } { print } '
        ;;
    fullstatus)
        $LYNX $STATUSURL
        ;;
    configtest)
        if $HTTPD -t; then
            :
        else
            ERROR=8
        fi
        ;;
    *)
        echo "usage: $0 (start|stop|restart|fullstatus|status|graceful|configtest|help)"
        cat <<EOF

start      - start httpd
stop       - stop httpd
restart    - restart httpd if running by sending a SIGHUP or start if 
             not running
fullstatus - dump a full status screen; requires lynx and mod_status enabled
status     - dump a short status screen; requires lynx and mod_status enabled
graceful   - do a graceful restart by sending a SIGUSR1 or start if not running
configtest - do a configuration syntax test
help       - this screen

EOF
        ERROR=2
    ;;

    esac

done

exit $ERROR

# ====================================================================
# Copyright (c) 1995-1999 The Apache Group.  All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer. 
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. All advertising materials mentioning features or use of this
#    software must display the following acknowledgment:
#    "This product includes software developed by the Apache Group
#    for use in the Apache HTTP server project (http://www.apache.org/)."
# 4. The names "Apache Server" and "Apache Group" must not be used to
#    endorse or promote products derived from this software without
#    prior written permission. For written permission, please contact
#    apache@apache.org.
# 5. Products derived from this software may not be called "Apache"
#    nor may "Apache" appear in their names without prior written
#    permission of the Apache Group.
#
# 6. Redistributions of any form whatsoever must retain the following
#    acknowledgment:
#    "This product includes software developed by the Apache Group
#    for use in the Apache HTTP server project (http://www.apache.org/)."
# THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
# ====================================================================
# This software consists of voluntary contributions made by many
# individuals on behalf of the Apache Group and was originally based
# on public domain software written at the National Center for
# Supercomputing Applications, University of Illinois, Urbana-Champaign.
# For more information on the Apache Group and the Apache HTTP server
# project, please see <http://www.apache.org/>.

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值