Skip to content

Instantly share code, notes, and snippets.

@slok
Created December 31, 2011 09:06
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save slok/1543449 to your computer and use it in GitHub Desktop.
Save slok/1543449 to your computer and use it in GitHub Desktop.
Setup for jboss 7 with apache and mod_cluster in ubuntu 11.10

Preparing Jboss environment

Create Jboss user and group

Create a group for a system user (daemnos and program users like www-data, mysql...)

# addgroup --system jboss

Create a user (system user, without home -> See below the command, to the jboss group and no login shell)

# useradd -r -M -g jboss -s /bin/false jboss

Maybe we want home to store data from maven, ant... that is needed by the jboss user when executing jenkins stuff

# useradd -r -g jboss -s /bin/false jboss

Add Jboss env var

Add to /etc/environment JBOSS_HOME var

#  echo "JBOSS_HOME=\"/usr/share/jboss7\"" >> /etc/environment

Installation of Jboss

Download Jboss 7 from [jboss donwnload site] (http://www.jboss.org/jbossas/downloads) Extract jboss in the proper place for example /usr/share

$ cd /usr/share
# tar xvf /home/xxxxx/Downloads/jboss-as-7.X.X.Final.tar.gz
# chown -R jboss:jboss /usr/share/jboss-as-7.X.X.Final/
# ln -s /usr/share/jboss-as-7.X.X.Final /usr/share/jboss7
# chown -h jboss:jboss /usr/share/jboss7

Installation of mod_cluster

Download the libs, [actually mod_cluster 1.1.3] (http://www.jboss.org/mod_cluster/downloads/1-1-3) Extract the libs

$ cd /home/xxxx/Downloads
$ mkdir ./mod_cluster_libs
$ cd ./mod_cluster_libs
$ tar xvf ./mod_cluster-1.1.3.Final-linux2-XXXX-so.tar.gz

Copy libs (not all, mod_proxy_ajp.so, mod_proxy_http.so and mod_proxy.so NO) to apache modules dir (i.e /usr/lib/apache2/modules/)

# cp ./mod_advertise.so  ./mod_manager.so  ./mod_proxy_cluster.so  ./mod_slotmem.so  /usr/lib/apache2/modules/

Configuration of mod_cluster in Jboss

Configure jboss Standalone mode to enable mod_cluster. Edit the standalone.xml file in $JBOSS_HOME/standalone/configuration/standalone.xml and add this two lines in their sections

Extensions

<extension module="org.jboss.as.modcluster"/>

profile

<subsystem xmlns="urn:jboss:domain:modcluster:1.0" />

Configuration of mod_cluster in apache

Create two files in mods-available (/etc/apache2/mods-available)

mod_cluster.load

LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule proxy_ajp_module /usr/lib/apache2/modules/mod_proxy_ajp.so
LoadModule slotmem_module /usr/lib/apache2/modules/mod_slotmem.so
LoadModule manager_module /usr/lib/apache2/modules/mod_manager.so
LoadModule proxy_cluster_module /usr/lib/apache2/modules/mod_proxy_cluster.so
LoadModule advertise_module /usr/lib/apache2/modules/mod_advertise.so

mod_cluster.conf

CreateBalancers 1

<IfModule manager_module>
    Listen 127.0.0.1:6666
    ManagerBalancerName mycluster
 
    <VirtualHost 127.0.0.1:6666> 
        KeepAliveTimeout 300
        MaxKeepAliveRequests 0
        AdvertiseFrequency 5
        ServerAdvertise On
 
        <Location />
            Order deny,allow
            Allow from 127.0.0
        </Location>

     </VirtualHost>

</IfModule>

And enable the module

# a2enmod mod_cluster

Configuration of jboss (mod_cluster/proxy) in apache

Create a file (virtual host) for jboss in sites-available (/etc/apache2/sites-available)

jboss

NameVirtualHost *:80
<VirtualHost *:80> 
    #ServerAdmin info@domain.de
    ServerName jboss.mdiss.info
    ServerAlias jboss.mdiss.info

    ProxyPass / balancer://mycluster stickysession=JSESSIONID|jsessionid nofailover=On
    ProxyPassReverse / balancer://mycluster
    ProxyPreserveHost On

    <Location />
        Order deny,allow
        Allow from All
    </Location>

   <Location /mod_cluster-manager>
      SetHandler mod_cluster-manager
      Order deny,allow
      #Deny from all
      Allow from 127.0.0
   </Location>

</VirtualHost>

And enable the site

# a2ensite jboss

Fix mod_cluster log problem

There is a problem with mod_cluster (in ubuntu?), needs the log directory in /etc/apache2

We can do two things, create the dir or create a symbloic link to /var/log/apache2

Creating the dir

# mkdir /etc/apache2/logs

Creating the symbolic link

#ln -s /var/log/apache2 /etc/apache2/logs

Create Jboss daemon

Create a Daemon to start jboss as jboss user, so create aa file (/etc/init.d/jboss) with this content

#!/bin/sh
### BEGIN INIT INFO
# Provides:          jboss
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/Stop JBoss AS v7.0.2
### END INIT INFO
#
#source some script files in order to set and export environmental variables
#as well as add the appropriate executables to $PATH
#[ -r /etc/profile.d/java.sh ] && . /etc/profile.d/java.sh
#[ -r /etc/profile.d/jboss.sh ] && . /etc/profile.d/jboss.sh

case "$1" in
    start)
        echo "Starting JBoss AS 7.0.2"
        sudo -u jboss sh ${JBOSS_HOME}/bin/standalone.sh
    ;;
    stop)
        echo "Stopping JBoss AS 7.0.2"
        sudo -u jboss sh ${JBOSS_HOME}/bin/jboss-admin.sh --connect command=:shutdown
    ;;
    *)
        echo "Usage: /etc/init.d/jboss {start|stop}"
        exit 1
    ;;
esac

exit 0

Install Jenkins

Download and deploy jenkins war

We download Jenkins from the [site] (http://mirrors.jenkins-ci.org/war/latest/jenkins.war) and we deploy the war.

Connect to the jboss admin console

# $JBOSS_HOME/bin/jboss-admin.sh
$ connect
$ deploy /home/xxxx/Downloads/jenkins.war
$ exit

Configure jenkins environmnent

Create the jenkins home (data storage)

# mkdir /usr/share/jenkins
# chown jboss:jboss /usr/share/jenkins

Set env variable in java (the system vars sometimes doesn't work with jboss user from jboss-as). Edit servers boot conf (standalone, domain). For example for estandalone: Edit $JBOSS_HOME/bin/standalone.conf

Add in the end of the file:

#Set jenkins home env variable
JAVA_OPTS="$JAVA_OPTS -DJENKINS_HOME=/usr/share/jenkins"
@ahoehn
Copy link

ahoehn commented Oct 7, 2012

Thanks for this good howto for mod_cluster. Unfortantly i don't get forwarded (when i access my servers url on port 80) to my jboss server (port 8080). Is there something else needed to get forwarded to jboss?

@profversaggi
Copy link

ahoehn, have a look at this article: http://stackoverflow.com/questions/17117368/can-not-access-admin-console-of-jboss-eap-6-at-standalone-mode

Evidently, the stock vintage of EAP 6 by default binds and connects to the 127.0.0.1 IP address instead of the live one. By altering the standalone.xml and switching the live IP for the 127.0.0.1, it'll work just fine.

And a BIG thank you to the author for the awesome article, it saved my day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment