What is JBoss ? JBoss Application Server (or JBoss AS) is a free software/open-source Java EE-based application server. An important distinction for this class of software is that it not only implements a server that runs on Java, but it actually implements the Java EE part of Java. Because it is Java-based, the JBoss application server operates cross-platform: usable on any operating system that supports Java. JBoss AS was developed by JBoss, now a division of Red Hat.
This article will show you how to install and configure JBoss on CentOS 6.6.
What thing to do?
- Download and install Java Development Kit (JDK)
- Download and config JBoss 5.1.0 GA-jdk6
- Set JAVA_HOME and JBOSS_HOME as variables environment
- Config JBoss run as service (can start/stop/restart)
- Change password of JBoss Admin Console
- Set memory parameters for JBoss using JAVA_OPTS
- Configure JBoss to run on port 80
Download and install Java Development Kit (JDK)
It's recommended to use JDK 6 with JBoss 5.1.0 GA so to install JDK 6, please refer this post: How to install JDK 6 on CentOS
Download and config JBoss 5.1.0 GA-jdk6
You can download JBoss 5.1.0 GA at http://sourceforge.net/projects/jboss/files/JBoss/JBoss-5.1.0.GA. You should download jboss-5.1.0.GA-jdk6.zip, it's optimized for JDK6.
Create folder for JBoss
# mkdir /opt/server/
Move jboss-5.1.0.GA-jdk6.zip to newly created folder and unzip it
# mv jboss-5.1.0.GA-jdk6.zip /opt/server/
# cd /opt/server/
# unzip jboss-5.1.0.GA-jdk6.zip
Now your JBoss is located in /opt/server/jboss-5.1.0.GA, this is JBOSS_HOME which is set in next step for variables environment.
Set JAVA_HOME and JBOSS_HOME as variables environment
Add the following lines in .bashrc or .bash_profile
# vi ~/.bashrc
JAVA_HOME=/usr/java/latest
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
JBOSS_HOME=/opt/server/jboss-5.1.0.GA
export JBOSS_HOME
Once finished, you have to log in current user again to verify that the JAVA_HOME and JBOSS_HOME are set correctly. This tutorial using root to config and run jboss therefore you have to log out and log in again with root account.
To verify variables set
# echo $JBOSS_HOME
# echo $JAVA_HOME
Output
/usr/java/latest
/opt/server/jboss-5.1.0.GA
Config JBoss run as service (can start/stop/restart)
JBoss 5.1.0 GA supports a script allow to run as service. Copy jboss_init_redhat.sh located in /opt/server/jboss-5.1.0.GA/bin paste it in etc/init.d and rename to jboss
# cp /opt/server/jboss-5.1.0.GA/bin/jboss_init_redhat.sh /etc/init.d/jboss
In jboss script, make the following changes:
Add lines 3,4 and 5
# description: JBoss Start Stop Restart
# processname: jboss
# chkconfig: 234 20 80
Line 21, Set the JBOSS_HOME to where we unzip JBoss:
JBOSS_HOME=${JBOSS_HOME:-"/opt/server/jboss-5.1.0.GA"}
Line 27. Set the JAVA_HOME to where we installed the JDK
JAVAPTH=${JAVAPTH:-"/usr/java/latest"}
Add line 33, which sets the JBOSS_HOST to 0.0.0.0, allowing JBoss to bind to any IP.
JBOSS_HOST="0.0.0.0"
There is complete jboss script after changed
#!/bin/sh
#
# description: JBoss Start Stop Restart
# processname: jboss
# chkconfig: 234 20 80
# $Id: jboss_init_redhat.sh 81068 2008-11-14 15:14:35Z dimitris@jboss.org $
#
# 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/server/jboss-5.1.0.GA"}
#define the user under which jboss will run, or use 'RUNASIS' to run as the current user
JBOSS_USER=${JBOSS_USER:-"root"}
#make sure java is in your path
JAVAPTH=${JAVAPTH:-"/usr/java/latest"}
#configuration to use, usually one of 'minimal', 'default', 'all'
JBOSS_CONF=${JBOSS_CONF:-"default"}
#if JBOSS_HOST specified, use -b to bind jboss services to that address
JBOSS_HOST="0.0.0.0"
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
Now make jboss script executable
# chmod +x jboss
And make it run when every boot
# chkconfig jboss on
Check it
# chkconfig --list | grep jboss
jboss 0:off 1:off 2:on 3:on 4:on 5:on 6:off
By default, jboss script will be set at level 2345
Now you can start jboss as service
# service jboss start
JBOSS_CMD_START = cd /usr/share/jboss-5.1.0.GA/bin; /usr/share/jboss-5.1.0.GA/bin/run.sh -c default -b 0.0.0.0
Stop jboss
# service jboss stop
JBOSS_CMD_START = cd /usr/share/jboss-5.1.0.GA/bin; /usr/share/jboss-5.1.0.GA/bin/run.sh -c default -b 0.0.0.0
Shutdown message has been posted to the server.
Server shutdown may take a while - check logfiles for completion
Or restart
# service jboss restart
Make sure jboss has been started at http://localhost:8080 or http://yourIP:8080
Change password of JBoss Admin Console
The default user name and password for the JBoss Admin Console is admin/admin. To change the password, go to /usr/share/jboss-5.1.0.GA/server/default/conf/props and ddit the jmx-console-users.properties file as below
# A sample users.properties file for use with the UsersRolesLoginModule
admin=admin
Username is left and password is right. Change whatever you want
Set memory parameters for JBoss using JAVA_OPTS
You could set the memory parameters for JBoss using JAVA_OPTS. Edit .bashrc or .bash_profile where you set variables environment above
# Setup JBoss specific properties
JAVA_OPTS="-Dprogram.name=$PROGNAME $JAVA_OPTS"
JAVA_OPTS="$JAVA_OPTS -Xms128m -Xmx256m"
You should set this to whatever is appropriate to your server and application.
Configure JBoss to run on port 80
By default, JBoss uses port 8080, you could change this to others ports as you want.
Open file server.xml located in /opt/server/jboss-5.1.0.GA/server/default/deploy/jbossweb.sar
Find
<connector address="${jboss.bind.address}" connectiontimeout="20000" port="8080" protocol="HTTP/1.1" redirectport="8443">
</connector>
And change
<connector address="${jboss.bind.address}" connectiontimeout="20000" port="80" protocol="HTTP/1.1" redirectport="443">
</connector>
Now restart your JBoss to apply change
Another way, you don't need to change server.xml, just add the following to your IP tables
# iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
and then restart iptables service
# service iptables restart
Done.
Reference