JBoss 5.0.0GA在ubuntu上的安装指南

最近遇到的应用系统,基本上都是基于JBoss的,看着销售们吹得是天昏地暗,日月无光,于是便起了一探究意的心思,本来看着Ubuntu 8.10中有一个JBoss AS的包,但看了一下Readme,发现是十分Alpha的包,连打包者都不推荐使用,于是还是老老实实去官方下载包,于是便有了这样文章。

众所周知,JBoss是基于JAVA的,所以第一步就是

 

安装和配置JAVA

sudo apt-get install sun-java6-jdk

 

提示:安装过程中需要你回答是否同意使用协议(终端中红蓝色的提示界面),此时按tab键至OK,再按回车即可正常安装。

然后设置默认的JAVA解释器:

sudo update-alternatives --config java

现有 3 个可选项,它们都提供了“java”

选择 可选项
-----------------------------------------------
*+ 1 /usr/lib/jvm/java-6-sun/jre/bin/java
 2 /usr/bin/gij-4.2<br> 3 /usr/bin/gij-4.3

要维持缺省值[*],按回车键,或者键入选择的编号:

 

选择有sun的那行即可,上例中为1。

配置JAVA环境变量:

sudo gedit /etc/environment

 

在其中添加如下两行:

CLASSPATH=.:/usr/lib/jvm/java-6-sun/lib
JAVA_HOME=/usr/lib/jvm/java-6-sun

 

然后编辑/etc/jvm文件

sudo gedit /etc/jvm

 

将文件中的

/usr/lib/jvm/java-6-sun

 这一行填入到配置块的顶部,这样JAVA环境就算是配好了。

 

创建JBoss用户

为什么要创建JBoss用户,这个就不需要我多讲了吧,总之Root用户是能不用尽量不用的好。

sudo mkdir /opt/jboss
sudo mkdir /home/jboss
sudo useradd -s /bin/bash -d /home/jboss jboss
sudo chown -R jboss:jboss /opt/jboss/
sudo chown -R jboss:jboss /home/jboss/ 

 

安装JBoss

接下来就是到JBoss官方网站去下载 JBoss 了,下载之后,您将得到一个名为 jboss-5.0.0.GA.zip 的文件。

sudo apt-get install unzip
sudo chown jboss:jboss jboss-5.0.0.GA.zip
sudo su jboss
unzip jboss-5.0.0.GA.zip -d /opt/jboss
mv ~/jboss-5.0.0.GA/* ~
rm -rvf jboss-5.0.0.GA
exit

 

生成init脚本

接下来就是要JBoss象守护进程一样运行了。

首先创建init脚本(下面的脚本里面有一些数据调用的jdk是/usr/lib/jvm/java-6-sun里面的,你的jdk如果是自己装的那就很可能不是这个路径了,要在JAVAPTH=${JAVAPTH:-"/usr/lib/jvm/java-6-sun"}里面改动一下,还有你的jboss安装路径也未必按照上面的/opt/jboss ,所以你也需要在下面的配置文件里面JBOSS_HOME=${JBOSS_HOME:-"/opt/jboss"}这一行,改动一下jboss的路径)

sudo vi /etc/init.d/jboss

 

脚本内容如下:

#!/bin/sh
#
# $Id: jboss_init_redhat.sh 81068 2008-11-14 15:14:35Z [email protected] $
#
# JBoss Control Script
#
# To use this script run it as root - it will switch to the specified user
#
# 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.
#
# Either modify this script for your requirements or just ensure that
# the following variables are set correctly before calling the script. 

#define where jboss is - this is the directory containing directories log, bin, conf etc
JBOSS_HOME=${JBOSS_HOME:-"/opt/jboss"}

#define the user under which jboss will run, or use 'RUNASIS' to run as the current user
JBOSS_USER=${JBOSS_USER:-"jboss"}

#make sure java is in your path
JAVAPTH=${JAVAPTH:-"/usr/lib/jvm/java-6-sun"}

#configuration to use, usually one of 'minimal', 'default', 'all'
JBOSS_CONF=${JBOSS_CONF:-"default"}

#the host where jboss should answer. o.o.o.o means answer all calls. set this to yourhost.com
JBOSS_HOST=${JBOSS_HOST:-"0.0.0.0"}

#Uncomment this line to store the console output, otherwise it's sent to /dev/null
JBOSS_CONSOLE=${JBOSS_CONSOLE:+"$JBOSS_HOME/server/$JBOSS_CONF/log/console.log"}

#if JBOSS_HOST specified, use -b to bind jboss services to that address
JBOSS_BIND_ADDR=${JBOSS_HOST:-"-b $JBOSS_HOST"}

#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 $JBOSS_CONF $JBOSS_BIND_ADDR"}

if [ "$JBOSS_USER" = "RUNASIS" ]; then
 SUBIT=""
else
 SUBIT="su - $JBOSS_USER -c "
fi 

if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then
 # ensure the file exists
 touch $JBOSS_CONSOLE
 if [ ! -z "$SUBIT" ]; then
  chown $JBOSS_USER $JBOSS_CONSOLE
 fi
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"}

JBOSS_CMD_START="cd $JBOSS_HOME/bin; $JBOSSSH"
JBOSS_CMD_STOP=${JBOSS_CMD_STOP:-"java -classpath $JBOSSCP org.jboss.Shutdown --shutdown"} 

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 JBOSS_CMD_START = $JBOSS_CMD_START 

case "$1" in
start)
 cd $JBOSS_HOME/bin
 if [ -z "$SUBIT" ]; then
  eval $JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &
 else
  $SUBIT "$JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &"
 fi
 ;;
stop)
 if [ -z "$SUBIT" ]; then
  $JBOSS_CMD_STOP
 else
  $SUBIT "$JBOSS_CMD_STOP"
 fi
 ;;
restart)
 $0 stop
 $0 start
 ;;
*)
 echo "usage: $0 (start|stop|restart|help)"
esac 

 然后使该init脚本生效

sudo chown root:root /etc/init.d/jboss
sudo chmod ug+x /etc/init.d/jboss
sudo update-rc.d jboss defaults 

 

启动JBoss

sudo /etc/init.d/jboss start

 

卸载JBoss

sudo /etc/init.d/jboss stop
sudo update-rc.d -f jboss remove
sudo rm -vf /etc/init.d/jboss
sudo userdel jboss
sudo rm -rvf /opt/jboss 

 原贴地址:http://wiki.ubuntu.org.cn/JBoss_5.0.0GA%E5%AE%89%E8%A3%85%E6%8C%87%E5%8D%97

你可能感兴趣的:(java,jvm,jboss,ubuntu,sun)