Friday, July 25, 2014

Jboss 5


I am using Centos 6.5 with minimal installation.
using package version Jboss EAP 5.1.2 + Oracle JDK 1.6.0_45

Installation

download the Jboss package and unzip it to /opt
get the JDK from oracle website and install it
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html#jdk-6u45-oth-JPR

# unzip jboss-eap-5.1.2.zip -d /opt
# chmod +x jdk-6u45-linux-x64-rpm.bin
# ./jdk-6u45-linux-x64-rpm.bin

confirm the java version by using this command
# java -version

go to opt folder and rename it to jboss
# cd /opt
# mv jboss-eap-5.1 jboss

start up Jboss as default to confirm it is working
# cd /opt/jboss/jboss-as/bin
# ./run.sh

If it running good, you should see a bunch of info and ended with
INFO  [ServerImpl] JBoss (Microcontainer) [5.1.2 (build: SVNTag=JBPAPP_5_1_2 date=201111102209)] Started in 40s:20ms

ok, now you can CTRL + C to end it

NOTE:
you can use command below to run as production profile
run.sh -c production -b 0.0.0.0

----------------------------------------------------------------------------------------------------------
Setup

the run.sh script was run based on default server
you should be notice there are many server at /opt/jboss/jboss-as/server/
for here, i just use the production server, so delete all other except production
# rm -rf all/ minimal/ standard/ web/ default

then go to production/conf folder and edit jboss-log4j.xml
this is to change the log to include the IP into it for easy recognize
# cd production/conf/
# vim jboss-log4j.xml

Change

<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="File" value="${jboss.server.log.dir}/cluster.log"/>

To

<param name="File" value="${jboss.server.log.dir}/server.${jboss.bind.address}.log"/>
<param name="File" value="${jboss.server.log.dir}/cluster.${jboss.bind.address}.log"/>

Then go to props and edit jmx-console-users.properties
this file is control the username and password for the console login
# cd props/
# vim jmx-console-users.properties

remove the hash to enable it
remember to change it to other password

Now for the basic tuning,
go to production/deploy/jbossweb.sar and edit server.xml

From

 <Connector protocol="AJP/1.3" port="8009" address="${jboss.bind.address}" redirectPort="8443" />

 <Engine name="jboss.web" defaultHost="localhost">

To

<Connector port="8009" address="${jboss.bind.address}"
      emptySessionPath="true" enableLookups="false" redirectPort="8443"
      protocol="AJP/1.3" connectionTimeout="600000" maxThreads="500"
      useBodyEncodingForURI="true" URIEncoding="UTF-8" />
<Connector port="8009" address="127.0.0.1"
      emptySessionPath="true" enableLookups="false" redirectPort="8443"
      protocol="AJP/1.3" connectionTimeout="600000" maxThreads="500"
      useBodyEncodingForURI="true" URIEncoding="UTF-8" />

<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node${jboss.messaging.ServerPeerID}">

<Valve className="org.jboss.web.tomcat.service.sso.ClusteredSingleSignOn" />

--------------------------------------------------------------------------------------------------
Start up File

Now here is the start up file,
This will easy to manage and can include to chkconfig startup list

go to /etc/init.d/ and create a new file name jboss
# vim /etc/init.d/jboss

paste the below content into it

--------------------------------
#!/bin/sh
#
# $Id: jboss_init_redhat.sh 90717 2009-06-30 23:04:46Z smarlow@redhat.com $
#
# JBoss Control Script
#
# chkconfig: - 85 15
# description: JBoss Application Server
# processname: jboss
#
# 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/jboss-as"}

#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/java/default/bin"}

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

#if JBOSS_HOST specified, use -b to bind jboss services to that address
JBOSS_HOST=`ifconfig|grep 'inet addr:'|grep -v '127.0.0.1'|cut -d: -f2|awk 'NR==1{print $1}'`
JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"}  

#Clustering
JBOSS_PARTITION="cluster1"
JBOSS_PEERID=`echo $JBOSS_HOST|cut -d. -f4`
JBOSS_CLUSTER=${JBOSS_PARTITION:+"-g $JBOSS_PARTITION -Djboss.messaging.ServerPeerID=$JBOSS_PEERID -DjvmRoute=node$JBOSS_PEERID"}

#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:-"/bin/sh $JBOSS_HOME/bin/run.sh -c $JBOSS_CONF $JBOSS_BIND_ADDR $JBOSS_CLUSTER"}

if [ "$JBOSS_USER" = "RUNASIS" ]; then
  SUBIT=""
else
  SUBIT="su - $JBOSS_USER -s /bin/sh -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 -s $JBOSS_HOST -u admin -p admin"}

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


case "$1" in
start)
    echo JBOSS_CMD_START = $JBOSS_CMD_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
    touch /var/lock/subsys/jboss
    ;;
stop)
    echo JBOSS_CMD_STOP = $JBOSS_CMD_STOP
    if [ -z "$SUBIT" ]; then
        $JBOSS_CMD_STOP
    else
        $SUBIT "$JBOSS_CMD_STOP"
    fi
    rm -rf $JBOSS_HOME/server/$JBOSS_CONF/tmp/*
    rm -rf $JBOSS_HOME/server/$JBOSS_CONF/work/*
    rm -rf /var/lock/subsys/jboss
    ;;
restart)
    $0 stop
    i=0
    while [ `ps ax|grep -v grep|grep java|wc -l` -gt 0 -a $i -lt 60 ]
    do
     sleep 1
     (( i += 1 ))
    done
    /usr/bin/killall -9 java
    $0 start
    ;;
*)
    echo "usage: $0 (start|stop|restart|help)"

esac

then change its permission to 755
# chmod 755 /etc/init.d/jboss

then add it into chkconfig list
# cd /etc/init.d/
# chkconfig --add jboss

inside the startup script, search admin word and update the password according to jmx-console-users.properties you done just now

then add user jboss for the script to run
# useradd jboss

then now change jboss folder owner to jboss
# chown -R jboss:jboss /opt/jboss

-----------------------------------------------------------------------------------------------------------
Putting the WAR file

Now for deploy WAR, just put the whole things at /production/deploy/ folder
start up the service and you can try access it at <your-IP>:8080

Note: Please give it 5-10 min to start
you can check is the command is running or not using
# ps -aux | grep jboss

for more troubleshooting, please first check the log file located at
/opt/jboss/jboss-as/server/production/log

Now your JBOSS is fully functional for production use
-----------------------------------------------------------------------------------------------------------
Connect to MySQL (Optional)

Install the MySQL
create databases jboss
create user jboss and full access to jboss database
Please refer to here for mysql setup if you don't know
MySQL Setup

1. download the appropriate driver for your MySQL at http://www.mysql.com/products/connector/
choose Connector/J
2. untar / unzip the file to get the jar file
3. copy the jar file to your /opt/jboss/jboss-as/server/production/lib/
4. copy the /opt/jboss/jboss-as/docs/example/jca/mysql-ds.xml file to /opt/jboss/jboss-as/server/production/deploy/
5. now open the mysql-ds.xml file to edit it
replace this 4 things
    <jndi-name>MySqlDS</jndi-name>
    <connection-url>jdbc:mysql://<Your-Server-IP>:3306/jboss</connection-url>
    <user-name>jboss</user-name>
    <password>jboss</password>

NOTE: 
If you choose to make mySQL your default database (DefaultDS), then change your jndi-name from MySqlDS to DefaultDS and be sure to delete the example $JBOSS_HOME/server/all/deploy/hsqldb-ds.xml which is also configured to be DefaultDS.
Then remove the /production/messaging/hsqldb-persistence-service.xml
and put this
cp /opt/jboss/jboss-as/docs/examples/jms/mysql-persistence-service.xml


Reference for MySQL:
https://community.jboss.org/wiki/SetUpAMysqlDatasource

----------------------------------------------------------------------------------------------------

Clustering

Ok, let add 1 more node into it for failover or load balance it.
the step is easy as it just repeat everything above, mean setup another duplicate.
the most important part is at the startup script.
if you see back the startup script i provide above, you should be notice got 1 word i highlight in red color. thats the keyword. as long as it is under same network zone and using the same keyword, it will auto detect and add as new member for the group.
during startup, you should see some info like this

INFO  [org.jboss.cache.RPCManagerImpl] (main) Received new cluster view: [172.20.1.172:55200|1] [172.20.1.172:55200, 172.20.1.173:55200]

----------------------------------------------------------------------------------------------------

2 comments:

  1. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Alfresco , kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on Alfresco. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us:
    Name : Arunkumar U
    Email : arun@maxmunus.com
    Skype id: training_maxmunus
    Contact No.-+91-9738507310
    Company Website –http://www.maxmunus.com


    ReplyDelete
  2. Maxmunus Providing Free Webinar/Demo on JBoss. JBoss tutorial step to step process will help understanding JBoss tutorial in better way. also JBoss tutorial pdf include each and every detail of JBoss basics for beginners.


    For Registration Contact:
    Name : Arunkumar U
    Email : arun@maxmunus.com
    Skype id: arun@maxmunus.com
    Contact No: +91- 9738507310,
    Company Website :- http://www.maxmunus.com

    ReplyDelete