---
title: "Linux下配置JBoss自动启动"
author: "yzyzero"
date: "2013-04-28T15:16:50Z"
tags: []
categories: ["开源软件"]
slug: "linux-jboss"
draft: false
lastmod: "2013-04-28T15:16:50Z"
id: 1856647
url: "https://yzyzero.iteye.com/blog/1856647"
---

（JBoss V4.0）

#为root用户的命令提示符 $为jboss用户的命令提示符

Ø安装J2SDK到/usr/local/j2sdk1.4.2，编辑/etc/profile

\# /etc/profile

[Java](http://dev.21tx.com/java/)\_HOME=/usr/local/j2sdk

PATH=$PATH:$JAVA\_HOME/bin

CLASSPATH=.:$JAVA\_HOME/jre/lib/rt.jar

 

export JAVA\_HOME PATH CLASSPATH

 

Ø安装JBoss4.0到/usr/local/jboss4x，编辑/etc/profile

\# /etc/profile

JBOSS\_HOME=/usr/local/jboss4x

PATH=$PATH:$JBOSS\_HOME/bin

 

export JBOSS \_HOME PATH

 

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

\# cp $JBOSS\_HOME/bin/jboss\_init\_redhat.sh /etc/init.d/

 

Ø设置启动脚步

＃ ln –s /etc/init.d/jboss\_init\_redhat.sh /etc/rc3.d/K20jboss\_init\_redhat

＃ ln –s /etc/init.d/jboss\_init\_redhat.sh /etc/rc3.d/S80jboss\_init\_redhat

＃ ln –s /etc/init.d/jboss\_init\_redhat.sh /etc/rc5.d/K20jboss\_init\_redhat

＃ ln –s /etc/init.d/jboss\_init\_redhat.sh /etc/rc5.d/S80jboss\_init\_redhat

 

此时会在/etc/rc3.d和/etc/rc5.d下创建一个S80jboss\_init\_redhat.sh的连接文件，然后分配执行权限（为了简单使用了777的权限）

\# chmod –f 777 /etc/init.d/jboss\_init\_redhat.sh

\# chmod –f 777 /etc/rc3.d/S80jboss\_init\_redhat.sh

\# chmod –Rf 777 $JBOSS\_HOME

 

Ø编辑/etc/init.d/jboss\_init\_redhat.sh文件(注：红色为修改部分)

＃ vi /etc/init.d/jboss\_init\_redhat.sh

#!/bin/sh

\#

\# JBoss Control Script

\#

\# chkconfig: 3 80 20

\# description: JBoss [EJB](http://dev.21tx.com/java/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](http://dev.21tx.com/java/base/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 &gt;${JBOSS\_CONSOLE} 2&gt;&1 &

else

$SUBIT "$CMD\_START &gt;${JBOSS\_CONSOLE} 2&gt;&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

 

Ø添加jboss用户并分配组

＃ useradd jboss

＃ usermod -G jboss,root jboss

 

Ø配置完成，重新启动Linux[服务器](http://www.21tx.com/server/)