Java世界

学习笔记

常用链接

统计

积分与排名

天籁村

新华网

雅虎

最新评论

Linux下配置JBoss自动启动

 

Linux下配置JBoss自动启动
 
 1. 操作系统:openSUSE 10.2
 
 2. JBOSS 4.2.2.GA


二. 实验步骤


 CODE:# /etc/profile
 
 JAVA_HOME=/usr/local/j2sdk
 
 PATH=$PATH:$JAVA_HOME/bin
 
 CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar
 
 export JAVA_HOME PATH CLASSPATH


jboss安装目录:/usr/local/jboss

  1. 添加jboss环境变量:

  #vi /etc/profile

  JBOSS_HOME=/usr/local/jboss  #根据你所安装的jboss的目录

  PATH=$PATH:$JBOSS_HOME/bin


  export JBOSS _HOME PATH

  2. 复制JBoss4自带的启动文件到/etc/init.d下:

 

   # cp /usr/local/jboss/bin/jboss_init_redhat.sh  /etc/init.d/jboss

  3. 设置启动脚步


    ln -s /etc/init.d/jboss /etc/rc3.d/K20jboss
    ln -s /etc/init.d/jboss /etc/rc3.d/S80jboss
    ln -s /etc/init.d/jboss /etc/rc5.d/K20jboss
    ln -s /etc/init.d/jboss /etc/rc5.d/S80jboss

     此时会在/etc/rc3.d和/etc/rc5.d下创建一个S80jboss的连接文件.
 
   4. 分配执行权限(为了简单使用了777的权限)


    chmod -f 777 /etc/init.d/jboss

    chmod -f 777 /etc/rc3.d/S80jboss

    chmod -Rf 777 $JBOSS_HOME  #根据你所安装的jboss的目录

   5. 编辑/etc/init.d/jboss文件,修改如下:
  
  #!/bin/sh
  
  #
  
  # JBoss Control Script
  
  #
  
  # chkconfig: 3 80 20
  
  # description: JBoss EJB Container
  
  #
  
  # To use this script
  
  # run it as root - it will switch to the specified user
  
  # It loses all console output - use the log.
  
  #
  
  # Here is a little (and extremely primitive)
  
  # startup/shutdown script for RedHat systems. It assumes
  
  # that JBoss lives in /usr/local/jboss, it's run by user
  
  # 'jboss' and JDK binaries are in /usr/local/jdk/bin. All
  
  # this can be changed in the script itself.
  
  # Bojan
  
  #
  
  # Either amend this script for your requirements
  
  # or just ensure that the following variables are set correctly
  
  # before calling the script
  
  # [ #420297 ] JBoss startup/shutdown for RedHat
  
  #define where jboss is - this is the directory containing directories log, bin, conf etc
  
  JBOSS_HOME=${JBOSS_HOME:-"/usr/local/jboss4x"}
  
  #make java is on your path
  
  JAVAPTH=${JAVAPTH:-"/usr/local/j2sdk1.4.2/bin"}
  
  #define the classpath for the shutdown class
  
  JBOSSCP=${JBOSSCP:-"$JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jnet.jar"}
  
  #define the script to use to start jboss
  
  JBOSSSH=${JBOSSSH:-"$JBOSS_HOME/bin/run.sh -c all"}
  
  if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then
  
  # ensure the file exists
  
  touch $JBOSS_CONSOLE
  
  fi
  
  if [ -n "$JBOSS_CONSOLE" -a ! -f "$JBOSS_CONSOLE" ]; then
  
  echo "WARNING: location for saving console log invalid: $JBOSS_CONSOLE"
  
  echo "WARNING: ignoring it and using /dev/null"
  
  JBOSS_CONSOLE="/dev/null"
  
  fi
  
  #define what will be done with the console log
  
  JBOSS_CONSOLE=${JBOSS_CONSOLE:-"/dev/null"}
  
  #define the user under which jboss will run, or use RUNASIS to run as the current user
  
  JBOSSUS=${JBOSSUS:-"jboss"}
  
  CMD_START="cd $JBOSS_HOME/bin; $JBOSSSH"
  
  CMD_STOP="java -classpath $JBOSSCP org.jboss.Shutdown --shutdown"
  
  if [ "$JBOSSUS" = "RUNASIS" ]; then
  
  SUBIT=""
  
  else
  
  SUBIT="su - $JBOSSUS -c "
  
  fi
  
  if [ -z "`echo $PATH | grep $JAVAPTH`" ]; then
  
  export PATH=$PATH:$JAVAPTH
  
  fi
  
  if [ ! -d "$JBOSS_HOME" ]; then
  
  echo JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME
  
  exit 1
  
  fi
  
  echo CMD_START = $CMD_START
  
  case "$1" in
  
  start)
  
  cd $JBOSS_HOME/bin
  
  if [ -z "$SUBIT" ]; then
  
  eval $CMD_START >${JBOSS_CONSOLE} 2>&1 &
  
  else
  
  $SUBIT "$CMD_START >${JBOSS_CONSOLE} 2>&1 &"
  
  fi
  
  ;;
  
  stop)
  
  if [ -z "$SUBIT" ]; then
  
  $CMD_STOP
  
  else
  
  $SUBIT "$CMD_STOP"
  
  fi
  
  ;;
  
  restart)
  
  $0 stop
  
  $0 start
  
  ;;
  
  *)
  
  echo "usage: $0 (start|stop|restart|help)"
  
  esac
    

    6. 添加jboss用户并分配组:


    useradd jboss
    usermod -G jboss,root jboss


    7. 配置完成,重新启动Linux服务器 。



注:防火墙需要开通以下端口,jboss才能进行远程访问:
        TCP:1099,1098,4444,4445,8009,8080,8083,8093,1100,0,3528 。
        UDP:1102,1161,1162,45566 。

posted on 2008-07-02 22:09 Rabbit 阅读(2660) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: