Jboss是常用的Java EE应用服务器,我司部署版本有Jboss4和Jboss7,均为多个Server的集群部署。总结一下需注意到的地方:

1、测试环境添加多个虚IP,每个IP部署4个server

[root@test02 ~]# ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:50:56:87:2E:FB  
          inet addr:192.168.2.104  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fe87:2efb/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:692746536 errors:0 dropped:0 overruns:0 frame:0
          TX packets:763407121 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:511746100021 (476.6 GiB)  TX bytes:190460411752 (177.3 GiB)

eth1      Link encap:Ethernet  HWaddr 00:50:56:87:19:E4  
          inet addr:192.168.2.124  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fe87:19e4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3532923 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:301860936 (287.8 MiB)  TX bytes:816 (816.0 b)

eth2      Link encap:Ethernet  HWaddr 00:50:56:8B:7F:07  
          inet addr:192.168.2.144  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fe8b:7f07/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3532891 errors:0 dropped:0 overruns:0 frame:0
          TX packets:11 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:301858486 (287.8 MiB)  TX bytes:746 (746.0 b)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:46444187 errors:0 dropped:0 overruns:0 frame:0
          TX packets:46444187 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:13395205203 (12.4 GiB)  TX bytes:13395205203 (12.4 GiB)


2、Standalone模式开发配置

1)数据源配置

            <datasources>
                <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
                    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
                    <driver>h2</driver>
                    <security>
                        <user-name>sa</user-name>
                        <password>sa</password>
                    </security>
                </datasource>
                <datasource jta="false" jndi-name="java:/jdbc/ticket_order" pool-name="ticket_order" enabled="true" use-ccm="false">
                    <connection-url>jdbc:mysql://192.168.2.42:3306/ticket_order?characterEncoding=utf-8</connection-url>
                    <driver-class>com.mysql.jdbc.Driver</driver-class>
                    <driver>mysql</driver>
                    <security>
                        <user-name>root</user-name>
                        <password>mysql</password>
                    </security>
                    <validation>
                        <check-valid-connection-sql>select 1 from dual</check-valid-connection-sql>
                        <validate-on-match>false</validate-on-match>
                        <background-validation>false</background-validation>
                    </validation>
                    <statement>
                        <share-prepared-statements>false</share-prepared-statements>
                    </statement>
                </datasource>
              </datasources>

注:需在server/default/lib目录下添加相应的JDBC驱动

2)server绑定ip设置

    <interfaces>
        <interface name="management">
            <inet-address value="${jboss.bind.address.management:192.168.2.124}"/>
        </interface>
        <interface name="public">
            <inet-address value="${jboss.bind.address:192.168.2.124}"/>
        </interface>
        <interface name="unsecure">
            <inet-address value="${jboss.bind.address.unsecure:192.168.2.124}"/>
        </interface>
    </interfaces>

3)端口配置

    <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:10930}">
        <socket-binding name="management-native" interface="management" port="${jboss.management.native.port:9999}"/>
        <socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>
        <socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9443}"/>
        <socket-binding name="ajp" port="8009"/>
        <socket-binding name="http" port="8080"/>
        <socket-binding name="https" port="8443"/>
        <socket-binding name="osgi-http" interface="management" port="8090"/>
        <socket-binding name="remoting" port="4447"/>
        <socket-binding name="txn-recovery-environment" port="4712"/>
        <socket-binding name="txn-status-manager" port="4713"/>
        <outbound-socket-binding name="mail-smtp">
            <remote-destination host="localhost" port="25"/>
        </outbound-socket-binding>
    </socket-binding-group>

注:

port-offset 为端口号偏移量,在http端口基础上偏移

4)启动脚本配置:

[root@test02 bin]# ls
check_dump.sh       jboss_init_redhat.sh  run1.sh    run.bat                   server3.sh    twiddle.sh       wstools.bat
classpath.sh        jboss_init_suse.sh    run2.conf  run.conf                  server4.sh    wsconsume.bat    wstools.sh
dump1.sh            logs                  run2.sh    run.conf.20150829_001721  shutdown.bat  wsconsume.sh
dump2.sh            nohup.out             run3.conf  run.jar                   shutdown.jar  wsprovide.bat
dump3.sh            probe.bat             run3.sh    run.sh                    shutdown.sh   wsprovide.sh
dump4.sh            probe.sh              run4.conf  server1.sh                twiddle.bat   wsrunclient.bat
jboss_init_hpux.sh  run1.conf             run4.sh    server2.sh                twiddle.jar   wsrunclient.sh

[root@test02 bin]# cat server1.sh 
#kill pid
echo "192.168.2.104 jboss server1 start........."
export DT_SOCKET=18787
export JMXREMOTE_PORT=11099
echo "step1 stop jboss......."
ps -ef|grep server1|grep -v "grep"|grep -v "ticket"|awk '{print $2}'|while read pid
    do
        if [ -n "$pid" ];then
                #echo $pid
                kill -9 $pid
        fi
    done

 #delete temp/ work/
 echo "step2 delete temp/ work/ ...."
rm -rf /jboss-4.2.3/server/server1/tmp/ /jboss-4.2.3/server/server1/work/

 #start jboss
 echo "step3 start jboss......."
cd /jboss-4.2.3/bin
nohup /jboss-4.2.3/bin/run.sh -b 192.168.2.104 -c server1 &
tail -f /jboss-4.2.3/bin/nohup.out

[root@test02 bin]# cat run.sh
# Display our environment
echo "========================================================================="
echo ""
echo "  JBoss Bootstrap Environment"
echo ""
echo "  JBOSS_HOME: $JBOSS_HOME"
echo ""
echo "  JAVA: $JAVA"
echo ""
echo "  JAVA_OPTS: $JAVA_OPTS"
echo ""
echo "  CLASSPATH: $JBOSS_CLASSPATH"
echo ""
echo "========================================================================="
echo ""

while true; do
   if [ "x$LAUNCH_JBOSS_IN_BACKGROUND" = "x" ]; then
      # Execute the JVM in the foreground
      "$JAVA" $JAVA_OPTS \
         -Djava.endorsed.dirs="$JBOSS_ENDORSED_DIRS" \
         -classpath "$JBOSS_CLASSPATH" \
         org.jboss.Main "$@"
      JBOSS_STATUS=$?
   else
      # Execute the JVM in the background
      "$JAVA" $JAVA_OPTS \
         -Djava.endorsed.dirs="$JBOSS_ENDORSED_DIRS" \
         -classpath "$JBOSS_CLASSPATH" \
         org.jboss.Main "$@" &
      JBOSS_PID=$!
      # Trap common signals and relay them to the jboss process
      trap "kill -HUP  $JBOSS_PID" HUP
      trap "kill -TERM $JBOSS_PID" INT
      trap "kill -QUIT $JBOSS_PID" QUIT
      trap "kill -PIPE $JBOSS_PID" PIPE
      trap "kill -TERM $JBOSS_PID" TERM
      # Wait until the background process exits
      WAIT_STATUS=128
      while [ "$WAIT_STATUS" -ge 128 ]; do
         wait $JBOSS_PID 2>/dev/null
         WAIT_STATUS=$?
         if [ "${WAIT_STATUS}" -gt 128 ]; then
            SIGNAL=`expr ${WAIT_STATUS} - 128`
            SIGNAL_NAME=`kill -l ${SIGNAL}`
            echo "*** JBossAS process (${JBOSS_PID}) received ${SIGNAL_NAME} signal ***" >&2
         fi          
      done
      if [ "${WAIT_STATUS}" -lt 127 ]; then
         JBOSS_STATUS=$WAIT_STATUS
      else
         JBOSS_STATUS=0
      fi      
   fi
   # If restart doesn't work, check you are running JBossAS 4.0.4+
   #    http://jira.jboss.com/jira/browse/JBAS-2483
   # or the following if you're running Red Hat 7.0
   #    http://developer.java.sun.com/developer/bugParade/bugs/4465334.html   
   if [ "$JBOSS_STATUS" -eq 10 ]; then
      echo "Restarting JBoss..."
   else
      exit $JBOSS_STATUS
   fi
done

[root@test02 bin]# cat run.conf 
## -*- shell-script -*- ######################################################
##                                                                          ##
##  JBoss Bootstrap Script Configuration                                    ##
##                                                                          ##
##############################################################################

### $Id: run.conf 62747 2007-05-02 17:43:36Z dimitris@jboss.org $

#
# This file is optional; it may be removed if not needed.
#

#
# Specify the maximum file descriptor limit, use "max" or "maximum" to use
# the default, as queried by the system.
#
# Defaults to "maximum"
#
#MAX_FD="maximum"

#
# Specify the profiler configuration file to load.
#
# Default is to not load profiler configuration file.
#
#PROFILER=""

#
# Specify the location of the Java home directory.  If set then $JAVA will
# be defined to $JAVA_HOME/bin/java, else $JAVA will be "java".
#
#JAVA_HOME="/opt/java/jdk"

#
# Specify the exact Java VM executable to use.
#
#JAVA=""

#
# Specify options to pass to the Java VM.
#
#
if [ "x$JAVA_OPTS" = "x" ]; then
   JAVA_OPTS="-Xms512m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=java.hprof -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000"
fi

# Sample JPDA settings for remote socket debuging
JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=$DT_SOCKET,server=y,suspend=n"
#JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=${JMXREMOTE_PORT} -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=${JAVA_HOME}/jre/lib/management/jmxremote.password -Dcom.sun.management.jmxremote.access.file=${JAVA_HOME}/jre/lib/management/jmxremote.access"

# Sample JPDA settings for shared memory debugging 
#JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_shmem,server=y,suspend=n,address=jboss"
#JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=18383,server=y,suspend=n"

如此,可启动3个不同ip的4个server,一共可跑12个server,如果服务器性能足够,可再添加。