David Ghedini

Linux, Java, Oracle, and PostgreSQL


David Ghedini

Tuesday Aug 07, 2012

JasperReportsIntegration 2.0.0 Beta on JBoss 7

Dietmar Aust / Opal Consulting have released JasperReportsIntegration 2.0.0 Beta for testing.

You can see the announcement here

It is has some amazing new features, is updated for JasperReports 4.7.0, and has a new deployment model.

Most importantly, the new version allows you to easily run JasperReportsIntegration on JBoss :)

If you don't have JBoss 7.1.1 installed, you can follow my tutorial here:

One important note - it did not work for me with JDK 1.7 but worked wonderfully with JDK 1.6

The zip file contains the required items for deployment on JBoss as well as items for Oracle (/sql directory) and Apex (/apex directory), it also contains some scripts to run in standalone mode as well as Jetty.

1. Create a directory under /usr/share to be the home for under JasperReportsIntegration

[root@dev2 ~]# mkdir /usr/share/JasperReportsIntegration


2. Change to the new directory:

[root@dev2 ~]# cd /usr/share/JasperReportsIntegration


3. Download the kit from Opal:

Or use wget:

[root@dev2 JasperReportsIntegration]# wget http://www.opal-consulting.de/downloads/free_tools/JasperReportsIntegration/2.0.0/JasperReportsIntegration-2.0.0.0.zip
--2012-08-07 03:43:35--  http://www.opal-

consulting.de/downloads/free_tools/JasperReportsIntegration/2.0.0/JasperReportsIntegration-2.0.0.0.zip
Resolving www.opal-consulting.de... 213.185.81.187
Connecting to www.opal-consulting.de|213.185.81.187|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 82738852 (79M) [application/zip]
Saving to: `JasperReportsIntegration-2.0.0.0.zip'

100%[======================================>] 82,738,852  2.26M/s   in 37s

2012-08-07 03:44:12 (2.13 MB/s) - `JasperReportsIntegration-2.0.0.0.zip' saved [82738852/82738852]


3. unzip it.

[root@dev2 JasperReportsIntegration]# unzip -q JasperReportsIntegration-2.0.0.0.zip


4. Your directory will look like this:

[root@dev2 JasperReportsIntegration]# ls -l
total 80944
drwxr-xr-x 2 root root     4096 Aug  6 17:49 apex
drwxr-xr-x 2 root root     4096 Aug  6 17:49 bin
drwxr-xr-x 2 root root     4096 Aug  7 05:30 conf
-rw-r--r-- 1 root root      204 Aug  6 17:49 deployJasperReportsIntegration.cmd
-rw-r--r-- 1 root root      178 Aug  6 17:49 deployJasperReportsIntegration.sh
drwxr-xr-x 3 root root     4096 Aug  6 17:49 doc
-rw-r--r-- 1 root root      341 Aug  6 17:49 Index.html
-rw-r--r-- 1 root root 82738852 Aug  6 19:57 JasperReportsIntegration-2.0.0.0.zip
drwxr-xr-x 3 root root     4096 Aug  6 17:49 jetty
drwxr-xr-x 2 root root     4096 Aug  6 17:49 lib
drwxr-xr-x 2 root root     4096 Aug  6 17:48 logs
drwxr-xr-x 5 root root     4096 Aug  7 05:33 reports
drwxr-xr-x 5 root root     4096 Aug  6 17:49 sql
-rw-r--r-- 1 root root      793 Aug  6 17:49 startJasperReportsIntegration.cmd
-rw-r--r-- 1 root root      772 Aug  6 17:49 startJasperReportsIntegration.sh
drwxr-xr-x 2 root root     4096 Aug  6 17:49 webapp


5. Change to the webapp directory and locate JasperReportsIntegration.war:

[root@dev2 JasperReportsIntegration]# cd webapp
[root@dev2 JasperReportsIntegration]# ls -l
total 66508
-rw-r--r-- 1 root root 68028460 Aug  6 17:49 JasperReportsIntegration.war
[root@dev2 webapp]#


6. Move the JasperReportsIntegration.war to JBOSS_HOME/standalone/deployments

In my case /usr/share/jboss-as/standalone/deployments:

[root@dev2 webapp]# mv JasperReportsIntegration.war  /usr/share/jboss-as/standalone/deployments/JasperReportsIntegration.war


7. Once you have moved the WAR, delete the webapp directory along with the following:
[root@dev2 JasperReportsIntegration]# rm -rf webapp/
[root@dev2 JasperReportsIntegration]# rm -rf jetty/
[root@dev2 JasperReportsIntegration]# rm -rf apex/
[root@dev2 JasperReportsIntegration]# rm -rf sql/
[root@dev2 JasperReportsIntegration]# rm -f deployJasperReportsIntegration.cmd
[root@dev2 JasperReportsIntegration]# rm -f deployJasperReportsIntegration.sh
[root@dev2 JasperReportsIntegration]# rm -f startJasperReportsIntegration.sh 
[root@dev2 JasperReportsIntegration]# rm -f startJasperReportsIntegration.cmd
[root@dev2 JasperReportsIntegration]# rm -f JasperReportsIntegration-2.0.0.0.zip


4. You should now be left with the following:

[root@dev2 JasperReportsIntegration]# ls
bin  conf  doc  Index.html  lib  logs  reports


If you are running under the user jboss, change ownership of the logs directory at /usr/share/JasperReportsIntegration/logs to the user jboss

[root@dev2 JasperReportsIntegration]# chown -Rf jboss.jboss /usr/share/JasperReportsIntegration/logs


5. Change to the conf directory, where you will find application.properties and log4jproperties:

[root@dev2 JasperReportsIntegration]# cd conf
[root@dev2 conf]# ls
application.properties  log4j.properties


6. The application.properties will look as below:

Change the data sources to your own.

Note that one of the verification tests later will look for a data source with the name 'default', so may want to leave one named as 'default'.

#====================================================================
# Application properties (global)
#====================================================================
[application]
jndiPrefix=java:comp/env/jdbc/

#====================================================================
# JDBC datasource configuration
# http://www.orafaq.com/wiki/JDBC#Thin_driver
#====================================================================
[datasource:default]
name=default
url=jdbc:oracle:thin:@192.168.2.114:1521:XE
username=my_oracle_user
password=my_oracle_user_pwd

#====================================================================
# JDBC datasource configuration
# http://www.orafaq.com/wiki/JDBC#Thin_driver
#====================================================================
[datasource:test]
name=test
url=jdbc:oracle:thin:@192.168.2.114:1521:XE
username=my_oracle_user
password=my_oracle_user_pwd

#====================================================================
# Direct printing
#====================================================================
[directPrinting]
isEnabled=true

# for debugging purposes does it make sense to display the 
# print dialog ON THE SERVER before printing. You can even cancel the 
# request through the print dialog
# DONT do that in production!!!
displayPrintDialog=false

#====================================================================
## Syntax for specifying properties: 
## http://commons.apache.org/configuration/userguide/howto_basicfeatures.html#Basic_features_and_AbstractConfiguration
#====================================================================


7. Placing OC_JASPER_CONFIG_HOME into the path of JBoss.

Where you place the path to OC_JASPER_CONFIG_HOME depends on the user you running JBoss under.

If you are running JBoss under the user jboss, you need to add the path to OC_JASPER_CONFIG_HOME to the .bash_profile of user jboss.

If you are running JBoss under the user root, you need to add the path to OC_JASPER_CONFIG_HOME to the .bash_profile of the user root.

If you simply place the path into the Jboss init script (JBOSS_HOME/bin/jboss-as-standalone.sh) or into your jboss script under /etc/init.d, it will throw the following error as JBoss will look for the application.properties file under ../JasperReportsIntegration.war-xxx/conf/application.properties:

net.sf.jasperreports.engine.JRRuntimeException: File /usr/share/jboss-as/standalone/tmp/vfs/temp38167c0517128991/JasperReportsIntegration.war-d170f314ce444645/conf/application.properties not found.
	de.oc.integration.jasper.webapp.AppContext.loadApplicationProperties(AppContext.java:144)
	de.oc.integration.jasper.webapp.ReportWrapper.service(ReportWrapper.java:152)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:847)


So, add the following to the .bash_profile of the user your running jboss under (jboss or root):

OC_JASPER_CONFIG_HOME=/usr/share/JasperReportsIntegration  
export OC_JASPER_CONFIG_HOME


Along with JAVA_HOME and bin paths (and any others you have), your jboss (or root) user bash_profile would look something like:

JAVA_HOME=/usr/java/jdk1.6.0_33
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
OC_JASPER_CONFIG_HOME=/usr/share/JasperReportsIntegration
export OC_JASPER_CONFIG_HOME


8. Install the SQL into the user schema

This bit has not changed.

Connect to your database server and change directories to the location you uploaded the /sql directory.

Connect to SQL*Plus as the required user and run @user_install.sql

[root@or2 JRI2]# cd sql
[root@or2 sql]# ls
sys_install_acl.sql  sys_remove.sql    user_remove.sql  xlib_jasperreports
sys_install.log      user_install.log  xlib_base        xlib_status.sql
sys_install.sql      user_install.sql  xlib_http        xlib_status_sys.sql
[root@or2 sql]# sqlplus /nolog

SQL*Plus: Release 11.2.0.3.0 Production on Mon Aug 6 20:39:01 2012

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

SQL> connect soctt/tiger
Connected.
SQL> @user_install.sql


Make sure it compiles with no errors.


9. Install the f860_JasperIntegrationTest_2.0.0.0.sql Application

Import the f860_JasperIntegrationTest_2.0.0.0.sql into your work space.

The new testing application has some new features as you can see below.


10. Verify your installation.

In the screenshot below, you can see I did not use the name 'default' for any of my data sources.

JBoss 7 JRI Application



11. Test your reports.

Among other new features, there is now a "Save File on Server" option. This allows you to save the generated report on the file system of the application server (jboss). You need to supply the full OS path. One additional note, if you are running as user jboss you will only be able to save into directories owned by jboss (or made available to user jboss). If you are running a root, of course, you can save anywhere on the server.

Jboss 7 Jasper Test



There is the file, fromapp.pdf, saved to server in above screen shot.

[root@dev2 jboss]# ls -l
total 8
-rw-rw-r-- 1 jboss jboss 2153 Aug  7 06:48 fromapp.pdf



Cool beans. Hoping to learn a lot more about this

Official Installation Guide

Bookmark and Share



Monday Jul 23, 2012

Install JBoss 7.1 on CentOS 6

This post will cover installing JBoss 7.1.1 on CentOS 6.x.

We'll also set up JBoss to run as a service, as well as set up access to the management console

Finally, we will look at how run JBoss on port 80 or, alternatively, placing JBoss behind Apache.

In this post, we will set up the JBoss 7.1.1 in Standalone mode. In a subsequent post we will look at setting up JBoss 7.1.1 in Domain mode.

Step 1: Install the Java 6 or 7


Firstly, we will need to install Java.

JBoss 7.1.1 will work with JDK 6 or JDK 7.

I'm using JDK 7, update 5.

You can download the JDK here: http://www.oracle.com/technetwork/java/javase/downloads/index.html

The instructions below will also work with JDK 6, you just need to change the file names accordingly.


Start by creating a directory /usr/java.

[root@dev2 ~]# mkdir /usr/java


Download jdk-7u5-linux-x64.tar.gz (or latest) and save to /usr/java directory you created above.


[root@dev2 java]# ls
jdk-7u5-linux-x64.tar.gz



Extract it:

[root@dev2 java]# tar -zxf  jdk-7u5-linux-x64.tar.gz


This will create the directory, /usr/java/jdk1.7.0_05, this will be our JAVA_HOME.

[root@dev2 java]# ls
jdk1.7.0_05  jdk-7u5-linux-x64.tar.gz
[root@dev2 java]# cd jdk1.7.0_05
[root@dev2 jdk1.7.0_05]# pwd
/usr/java/jdk1.7.0_05


Note: If you decided to use JDK 6 rather than 7 as we did above, simply save the JDK 6 bin file to /opt (or another location), then navigate to /usr/java and issue: 'sh /opt/jdk-6u33-linux-x64.bin' as shown below (substitute whichever version you downloaded). This will create a JAVA Home of /usr/java/jdk1.6.0.33

[root@dev2 ~]#cd /usr/java
[root@dev2 java]# sh /opt/jdk-6u33-linux-x64.bin



Step 2: Download and Install JBoss 7.1.1 Application Server


Change to the /usr/share directory:

[root@dev2 jdk1.7.0_05]# cd /usr/share


Download jboss-as-7.1.1.Final.zip at http://www.jboss.org/jbossas/downloads and save it to /usr/share. Or, use wget:


[root@dev2 share]# wget http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final.zip



Unzip the file:


[root@dev2 share]# unzip -q jboss-as-7.1.1.Final.zip



Rename jboss-as-7.1.1.Final to jboss-as. This isn't strictly necessary, but it will save you the bother of changing the start up script later.


[root@dev2 share]# mv jboss-as-7.1.1.Final jboss-as


Our JBOSS_HOME is '/usr/share/jboss-as'.

[root@dev2 share]# cd jboss-as
[root@dev2 jboss-as]# pwd
/usr/share/jboss-as


Step 3: Create the user jboss, who will own and run JBoss


Since we will want to run JBoss as a non-root user with minimal privileges, we'll create a user, jboss, who will own the JBoss files and JBoss will run under his account.

To do this, do the following.

Create a new group, jboss, and then create the user jboss and add the user to the jboss group.

[root@dev2 share]# groupadd jboss
[root@dev2 share]# useradd -s /bin/bash -g jboss jboss


Change ownership of the JBoss home directory, /usr/share/jboss-as so all files are owned by the user jboss we created.

[root@dev2 share]# chown -Rf jboss.jboss /usr/share/jboss-as/


Step 4: Put Java into the path of jboss and root


Now, we need to put Java into the path of the users jboss and root (as well as any other users you like)

The JAVA_HOME is where we installed the JDK above: /usr/java/jdk1.7.0_05

Add the following to the .bash_profile of the user jboss and the user root:

JAVA_HOME=/usr/java/jdk1.7.0_05
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH


As root, issue '. ~/.bash_profile' as below to put JAVA into the path of root immediately.

[root@dev2 ~]# . ~/.bash_profile


Check that JAVA is now in the path of root by issuing 'java -version' as below.
[root@dev2 ~]# java -version
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b06)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)
[root@dev2 ~]#



We need to have JAVA in the path of user root for when we add a Management User for JBoss console in Step 8 below.

Finally, switch to the user jboss and issue 'java -version' to verify that Java is now in the path of user jboss.


[root@dev2 ~]# su - jboss
[jboss@dev2 ~]$ java -version
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b06)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)
[jboss@dev2 ~]$



Step 5: Create a start/stop/restart script for JBoss.


To create our JBoss script, we will copy the jboss-as-standalone.sh script located under /usr/share/jboss-as/bin/init.d

As root, copy jboss-as-standalone.sh to /etc/init.d and rename it jboss

.
[root@dev2 ~]# cd /usr/share/jboss-as/bin/init.d
[root@dev2 bin]# cp jboss-as-standalone.sh /etc/init.d/jboss


The only change I needed to make two changes to the script

The first was to change line #5 below from it's original '# chkconfig: - 80 20' to '# chkconfig: 234 80 20' The second was to set the JBOSS_USER.

To set the JBOSS_USER, add the following lines to script:

JBOSS_USER=jboss
export JBOSS_USER

You can add the lines just under 'export JAVA_HOME' on line 18 or so below. So the beginning of your script will look like this:

#!/bin/sh
#
# JBoss standalone control script
#
# chkconfig: 234 80 20
# description: JBoss AS Standalone
# processname: standalone
# pidfile: /var/run/jboss-as/jboss-as-standalone.pid
# config: /etc/jboss-as/jboss-as.conf

# Source function library.
. /etc/init.d/functions

# Load Java configuration.
[ -r /etc/java/java.conf ] && . /etc/java/java.conf
export JAVA_HOME

JBOSS_USER=jboss
export JBOSS_USER

# Load JBoss AS init.d configuration.
if [ -z "$JBOSS_CONF" ]; then
  JBOSS_CONF="/etc/jboss-as/jboss-as.conf"
fi

[ -r "$JBOSS_CONF" ] && . "${JBOSS_CONF}"

# Set defaults.

if [ -z "$JBOSS_HOME" ]; then
  JBOSS_HOME=/usr/share/jboss-as
fi
export JBOSS_HOME


Step 6: Run JBoss as a Service.


To run JBoss as a service and enable start up at boot, make the script we created above executable and add it to our chkconfig so it starts at boot.

[root@dev2 init.d]# chmod 755 jboss
[root@dev2 init.d]# chkconfig --add jboss
[root@dev2 init.d]# chkconfig --level 234 jboss on


We should now be able to Start, Stop, and Restart JBoss as a service.

Start JBoss (JBoss can take some time to start, but it is faster than JBoss 6).:

[root@dev2 init.d]# service jboss start
Starting jboss-as:                                         [  OK  ]
[root@dev2 init.d]# 


Stop JBoss:
[root@dev2 init.d]# service jboss stop
Stopping jboss-as: *** JBossAS process (25794) received TERM signal ***
                                                           [  OK  ]


Step 7: Change bind address to make JBoss accessible.


By default, JBoss 7.1.1 is bound to the loopback IP of 127.0.0.1, so if we want to make it available on the web, we need to change this.

Locate standalone.xml under /usr/share/jboss-as/standalone/configuration/.

Open standalone.xml in vi or a text editor and look for the public interfaces node as shown below.

<interface name="public">
<inet-address value="${jboss.bind.address:127.0.0.1}"/>
</interface>

To make JBoss publicly accessible, change 127.0.0.1 to either 0.0.0.0 to allow access on all interfaces or to your public IP.

So, for example, if your public IP is 173.194.35.177, you would change it as so:

<interfaces>
        <interface name="management">
            <inet-address value="${jboss.bind.address.management:127.0.0.1}"/>
        </interface>
        <interface name="public">
            <inet-address value="${jboss.bind.address:173.194.35.177}"/>
        </interface>
        <!-- TODO - only show this if the jacorb subsystem is added  -->
        <interface name="unsecure">
            <!--
              ~  Used for IIOP sockets in the standard configuration.
              ~                  To secure JacORB you need to setup SSL 
              -->
            <inet-address value="${jboss.bind.address.unsecure:127.0.0.1}"/>
        </interface>
    </interfaces>



Again, if you wish to have JBoss publicly accessible on all interfaces, use 0.0.0.0 in place of your IP above.

Save your changes, start up JBoss, and check it is publicly accessible via http://yourIP:8080

[root@dev2 init.d]# service jboss start
Starting jboss-as:                                         [  OK  ]


Woo-hoo! JBoss 7:

JBoss 7.1.1 Welcome Page



Step 8: Accessing the JBoss 7 Admin Console and adding a Management User


If you try to access the JBoss Admin Console via the link on the home page (or by going directly to http://YourIP:9990, you will be greeted with the following:

java -jar



While the error page tells you how to add a user, you will also need to update the standalone.xml as we did earlier if you want to allow access over your public IP.


Let's start with adding a Management user as shown on the error page:

As root, navigate to /usr/share/jboss-as/bin

[root@dev2 etc]# cd /usr/share/jboss-as/bin


Issue './add-user.sh' to run the script to add a Management user. Follow the prompts. Some defaults are provided.

[root@dev2 bin]# ./add-user.sh

What type of user do you wish to add?
 a) Management User (mgmt-users.properties)
 b) Application User (application-users.properties)
(a):

Enter the details of the new user to add.
Realm (ManagementRealm) :
Username : david
Password :
Re-enter Password :
About to add user 'david' for realm 'ManagementRealm'
Is this correct yes/no? yes
Added user 'david' to file '/usr/share/jboss-as/standalone/configuration/mgmt-users.properties'
Added user 'david' to file '/usr/share/jboss-as/domain/configuration/mgmt-users.properties'
[root@dev2 bin]# 


While you can now access the Admin console on localhost (127.0.0.1), if you want to access it publicly, we need to update standalone.xml under /usr/share/jboss-as/standalone/configuration/ as we did earlier in Step 7.

Open standalone.xml in vi or a text editor and look for the management interface node as shown below.

<interface name="management">
<inet-address value="${jboss.bind.address.management:127.0.0.1}"/>
</interface>

To make the JBoss Admin console publicly accessible, change 127.0.0.1 to your your public IP or to 0.0.0.0 for all interfaces.

So, for example, if your public IP is 173.194.35.177, you would change it as so:

<interfaces>
        <interface name="management">
            <inet-address value="${jboss.bind.address.management:173.194.35.177}"/>
        </interface>
        <interface name="public">
            <inet-address value="${jboss.bind.address:173.194.35.177}"/>
        </interface>
        <!-- TODO - only show this if the jacorb subsystem is added  -->
        <interface name="unsecure">
            <!--
              ~  Used for IIOP sockets in the standard configuration.
              ~                  To secure JacORB you need to setup SSL 
              -->
            <inet-address value="${jboss.bind.address.unsecure:127.0.0.1}"/>
        </interface>
    </interfaces>



Again, if you wish to have the Admin console publicly accessible on all interfaces, use 0.0.0.0 in place of your IP above.

Retstart JBoss to reload the the change to standalone.xml:

[root@dev2 init.d]# service jboss stop
Stopping jboss-as: *** JBossAS process (25794) received TERM signal ***
                                                           [  OK  ]
[root@dev2 init.d]# service jboss start
Starting jboss-as:                                         [  OK  ]


Now, navigate back to http://YourIP:9990 and you should be prompted for the Management user credentials you just created:


JBoss 7 Management User Log In



Below, we are now logged in to the Admin console as the Management user we created:


JBoss 7 Admin Console



Step 9 (Optional): Running JBoss on Port 80.


To run services below port 1024 as user other than root, you can use port forwarding.

You can do this by adding the following to your IP tables:

[root@sv2 ~]# iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
[root@sv2 ~]# iptables -t nat -A PREROUTING -p udp -m udp --dport 80 -j REDIRECT --to-ports 8080


Be sure to save and restart your IP Tables.

Step 10 (Optional): Putting Apache in Front of JBoss.


As an alternative to running JBoss on port 80, if you have Apache in front of JBoss, you can use mod_proxy as well as ajp connector to map your domain to your JBoss applications using an Apache vhost as shown below:

While both Tomcat and JBoss have improved their standalone performance, I still prefer to have Apace in front for a number of reasons.

Note that when using proxy, if you will be proxy to localhost (which you should be), you will need to set your public interface bind address to either 0.0.0.0 (for all interfaces) or to 127.0.0.1 for localhost only.
<VirtualHost *:80>
    ServerAdmin admin@domain.com
    ServerName domain.com
    ServerAlias www.domain.com


    ProxyRequests Off
    ProxyPreserveHost On
    <Proxy *>
       Order allow,deny
       Allow from all
    </Proxy>


    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/


    ErrorLog logs/domain.com-error_log
    CustomLog logs/domain.com-access_log common

</VirtualHost>



Alternatively, with the AJP connector enabled, you can use ajp as well:


<VirtualHost *:80>
    ServerAdmin admin@domain.com
    ServerName domain.com
    ServerAlias www.domain.com


    ProxyRequests Off
    ProxyPreserveHost On
    <Proxy *>
       Order allow,deny
       Allow from all
    </Proxy>


    ProxyPass / ajp://localhost:8009/
    ProxyPassReverse / ajp://localhost:8009/


    ErrorLog logs/domain.com-error_log
    CustomLog logs/domain.com-access_log common

</VirtualHost>


The AJP connector is NOT enabled by default. To enable the AJP connector:

1. Log into the Admin console
2. Click Profile on the top right.
3. On the left menu, go to Web > Servlet/HTTP.
3. Click on the "add" button at right.


JBoss 7.1.1 Profile



4. Enter the following in the Create Connector dialogue box as shown below.

5. Click Save.

JBoss 7.1.1 Welcome Page



The AJP connector is now enabled.

JBoss 7.1.1  AJP Connector



One final note above the vhost examples above (proxy and ajp).

In both vhost examples above, we are "mapping" the domain to the root.

If we wish to map to an application such as domain.com/myapp, we can add some rewrite as shown below.

This will rewrite all requests for domain.com to domain.com/myapp.


<VirtualHost *:80>
    ServerAdmin admin@domain.com
    ServerName domain.com
    ServerAlias www.domain.com

    RewriteEngine On
    RewriteRule ^/$ myapp/ [R=301]


    ProxyRequests Off
    ProxyPreserveHost On
    <Proxy *>
       Order allow,deny
       Allow from all
    </Proxy>


    ProxyPass / ajp://localhost:8009/
    ProxyPassReverse / ajp://localhost:8009/


    ErrorLog logs/domain.com-error_log
    CustomLog logs/domain.com-access_log common

</VirtualHost>


JBoss 7.1.1 Docs



JBoss and WildFly Hosting

Bookmark and Share



Saturday Mar 12, 2011

How to Install JBoss 6 on CentOS

This post will cover installing JBoss 6.0 on CentOS 5.x.

(If you are looking to install JBoss 7, please see my post here: http://www.davidghedini.com/pg/entry/install_jboss_7_on_centos)

We'll also set up JBoss to run as a service, as well as secure the JMX and Web Service consoles

While there are similarities to JBoss 5.1 installation, the file locations have changed in some instances

Here is an outline of the steps we will follow:

1. Download and Install the Java Development Kit (JDK)
2. Download and Install JBoss 6.0 Application Server
3. Create the user, jboss, who will own and run JBoss
4. Set the required JAVA_HOME and JBOSS_HOME paths
5. Create a start/stop/restart script for JBoss
6. Configure JBoss to run as a service
7. Access the JBoss Admin console
8. Change the JBoss Admin Password
9. Secure the JMX Console
10. Securing the Web Service Console
11. Set memory parameters for JBoss using JAVA_OPTS
12. Configure JBoss to run on port 80

Step 1: Download and Install the Java Development Kit (JDK)


You can download the JDK here: http://www.oracle.com/technetwork/java/javase/downloads/index.html

I'm using JDK 6, update 24, the latest as of this post. The JDK is specific to 32 and 64 bit versions.

My CentOS box is 64 bit, so I'll need: jdk-6u24-linux-x64.bin.

If you are on 32 bit, you'll need: jdk-6u24-linux-i586.bin

Download the appropriate JDK and save it to a directory. I'm saving it to /root.

Move (mv) or copy (cp) the file to the /opt directory:

[root@sv2 ~]# mv jdk-6u24-linux-x64.bin /opt/jdk-6u24-linux-x64.bin


Create the directory /usr/java.

[root@sv2 ~]# mkdir /usr/java


Change to the /usr/java directory we created and install the JDK using 'sh /opt/jdk-6u24-linux-x64.bin'

[root@sv2 ~]# cd /usr/java
[root@sv2 java]# sh /opt/jdk-6u24-linux-x64.bin


We now have the JDK installed at /usr/java/jdk1.6.0_24. We'll use this for our JAVA_HOME a bit later in step

Step 2: Download and Install JBoss 6.0 Application Server


Download jboss-6.0.0.Final.zip at http://sourceforge.net/projects/jboss/files/JBoss/jboss-6.0.0.Final/ or use wget:

[root@sv2 ~]# wget http://sourceforge.net/projects/jboss/files/JBoss/JBoss-6.0.0.Final/jboss-as-distribution-6.0.0.Final.zip/download
.
.
.
100%[======================================>] 181,267,148  816K/s   in 3m 31s

2011-03-13 00:56:44 (839 KB/s) - `jboss-as-distribution-6.0.0.Final.zip' saved [181267148/181267148]



Move (mv) or copy (cp) the file to /usr/share/jboss-6.0.0.Final.zip.

[root@sv2 ~]# mv jboss-as-distribution-6.0.0.Final.zip /usr/share/jboss-as-distribution-6.0.0.Final.zip


Change to the /usr/share directory and unzip the file:

[root@sv2 ~]# cd /usr/share
[root@sv2 share]# unzip -q jboss-as-distribution-6.0.0.Final.zip


The unzip will create the following directory: /usr/share/jboss-6.0.0.Final

This directory will be our JBOSS_HOME, which we will use below in Step 4.

Step 3: Create the user, jboss, who will own and run JBoss


Since we will want to run JBoss as a non-root user with minimal privileges, we'll create a user, jboss, who will own the JBoss files and JBoss will run under his account.

To do this, we can need to the following.

Create a new group, jboss, and then create the user jboss and add the user to the jboss group.

[root@sv2 ~]# groupadd jboss
[root@sv2 ~]# useradd -s /bin/bash -g jboss jboss


Change ownership of the JBoss home directory, /usr/share/jboss-6.0.0.Final so all files are owned by the user jboss we created.

[root@sv2 ~]# chown -Rf jboss.jboss /usr/share/jboss-6.0.0.Final/


Step 4: Set the required JAVA_HOME and JBOSS_HOME paths


We no need to set the JAVA_HOME and JBOSS_HOME.

The JAVA_HOME is where we installed the JDK above, /usr/java/jdk1.6.0_24, and the JBOSS_HOME is where we installed JBoss above /usr/share/jboss-6.0.0.Final.

Add the following to the jboss users .bash_profile:

JAVA_HOME=/usr/java/jdk1.6.0_24
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
JBOSS_HOME=/usr/share/jboss-6.0.0.Final
export JBOSS_HOME


To set the JAVA_HOME for users, we add this to the user ~/.bashrc or ~/.bash_profile of the user. We can also add it /etc/profile and then source it to give to all users.

JAVA_HOME=/usr/java/jdk1.6.0_24 
export JAVA_HOME 
PATH=$JAVA_HOME/bin:$PATH 
export PATH


Once you have added the above to ~/.bash_profile or ~/.bashrc, you should su to the user jboss and verify that the JAVA_HOME and JBOSS_HOME are set correctly.

[root@sv2 ~]#  su jboss
[jboss@sv2 ~]#  echo $JAVA_HOME
/usr/java/jdk1.6.0_24
[jboss@sv2 ~]#  echo $JBOSS_HOME
/usr/share/jboss-6.0.0.Final


Step 5: Create a start/stop/restart script for JBoss.


For our JBoss script we will simply copy the existing jboss_init_redhat.sh script located at at /usr/share/jboss-6.0.0.Final/bin, copy it to /etc/init.d and rename it to 'jboss':

So, as root:

[root@sv2 ~]# cd /usr/share/jboss-6.0.0.Final/bin 
[root@sv2 bin]# cp jboss_init_redhat.sh /etc/init.d/jboss


In the jboss script (shown completed below), make the following changes:

1. Add lines 3,4, and 5:
# description: JBoss Start Stop Restart
# processname: jboss
# chkconfig: 234 20 80
2. Line 22, Set the JBOSS_HOME to where we unpacked JBoss in step 2 above:
JBOSS_HOME=${JBOSS_HOME:-"/usr/share/jboss-6.0.0.Final"}

3. Line 28. Set the JAVA_HOME to where we installed the JDK in step 1 above:
JAVAPTH=${JAVAPTH:-"/usr/java/jdk1.6.0_24"}

4. Add line 34, which sets the JBOSS_HOST to 0.0.0.0, allowing JBoss to bind to any IP.
JBOSS_HOST="0.0.0.0"

#!/bin/sh
#
# description: JBoss Start Stop Restart
# processname: jboss6
# 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:-"/usr/share/jboss-6.0.0.Final"}

#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/jdk1.6.0_24"}

#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


Step 6: Run JBoss as a Service.


To run JBoss as a service and enable start up at boot, make the script we created above executable and add it to our chkconfig so it starts at boot.

[root@sv2 init.d]# chmod 755 jboss
[root@sv2 init.d]# chkconfig --add jboss
[root@sv2 init.d]# chkconfig --level 234 jboss on


We should now be able to Start, Stop, and Restart JBoss as a service.

Start JBoss:

Note: JBoss can take some time to start.

[root@sv2 init.d]# service jboss6 start
JBOSS_CMD_START = cd /usr/share/jboss-6.0.0.Final/bin; /usr/share/jboss-6.0.0.Final/bin/run.sh -c default -b 0.0.0.0


Stop JBoss:
[root@sv2 init.d]# service jboss6 stop
JBOSS_CMD_START = cd /usr/share/jboss-6.0.0.Final/bin; /usr/share/jboss-6.0.0.Final/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


Step 7: Access the JBoss Admin.


Make sure JBoss is started and you should now be able to access the Jboss Console at:

http://yourdomain.com:8080 or http://yourip:8080

The default user name and password for the JBoss Admin Console is admin/admin



Access the Admin Console by clicking on the Administration Console link.



Step 8: Change the JBoss Admin Password


To change the default Admin Console password, go to:

/usr/share/jboss-6.0.0.Final/server/default/conf/props

Open the jmx-console-users.properties file in text editor and change the password.

# A sample users.properties file for use with the UsersRolesLoginModule
admin=MyPassword


Step 9: Secure the JMX Console


To secure the JMX Console, go to:

/usr/share/jboss-6.0.0.Final/common/deploy/jmx-console.war/WEB-INF

First, edit the web.xml file. Towards the bottom, you will find the security-constraint as shown below:

<!-- A security constraint that restricts access to the HTML JMX console
   to users with the role JBossAdmin. Edit the roles to what you want and
   uncomment the WEB-INF/jboss-web.xml/security-domain element to enable
   secured access to the HTML JMX console.
   <security-constraint>
     <web-resource-collection>
       <web-resource-name>HtmlAdaptor</web-resource-name>
       <description>An example security config that only allows users with the
         role JBossAdmin to access the HTML JMX console web application
       </description>
       <url-pattern>/*</url-pattern>
     </web-resource-collection>
     <auth-constraint>
       <role-name>JBossAdmin</role-name>
     </auth-constraint>
   </security-constraint>
   -->


Un-comment the security-constraint section so it appears thus:

<security-constraint>
     <web-resource-collection>
       <web-resource-name>HtmlAdaptor</web-resource-name>
       <description>An example security config that only allows users with the
         role JBossAdmin to access the HTML JMX console web application
       </description>
       <url-pattern>/*</url-pattern>
     </web-resource-collection>
     <auth-constraint>
       <role-name>JBossAdmin</role-name>
     </auth-constraint>
   </security-constraint>


Next, still in the WEB-INF directory, edit the jboss-web.xml file, which will look as below:

<!DOCTYPE jboss-web PUBLIC
   "-//JBoss//DTD Web Application 5.0//EN"
   "http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd">
   
<jboss-web>
   <!-- Uncomment the security-domain to enable security. You will
      need to edit the htmladaptor login configuration to setup the
      login modules used to authentication users.
      <security-domain>java:/jaas/jmx-console</security-domain>
   -->
</jboss-web>


Uncomment the security-domain so it appears thus:

<pre class="js" name="code"><!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 5.0//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd"> <jboss-web> <security-domain>java:/jaas/jmx-console</security-domain> </jboss-web>

At this point, the password for the JMX Console will be the same as the password we set for the Admin Console in step 8 above.

Both the Admin Console and JMX Console are are using the jmx-console-roles.properties and jmx-console-users.properties files.

Step 10: Secure the Web Service Console


To secure the Web Service Console, go to:

/usr/share/jboss-6.0.0.Final/common/deploy/jbossws-console.war/WEB-INF

First, edit the web.xml file. Towards the bottom, you will find the security-constraint as shown below:

<!-- A security constraint that restricts access
   <security-constraint>
     <web-resource-collection>
       <web-resource-name>ContextServlet</web-resource-name>
       <description>An example security config that only allows users with the
         role 'friend' to access the JBossWS console web application
       </description>
       <url-pattern>/*</url-pattern>
     </web-resource-collection>
     <auth-constraint>
       <role-name>friend</role-name>
     </auth-constraint>
   </security-constraint>
   -->


Un-comment the security-constraint section so it appears thus:

<security-constraint>
     <web-resource-collection>
       <web-resource-name>ContextServlet</web-resource-name>
       <description>An example security config that only allows users with the
         role 'friend' to access the JBossWS console web application
       </description>
       <url-pattern>/*</url-pattern>
     </web-resource-collection>
     <auth-constraint>
       <role-name>friend</role-name>
     </auth-constraint>
   </security-constraint>


Next, still in the WEB-INF directory, edit the jboss-web.xml file, which will look as below:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE jboss-web
    PUBLIC "-//JBoss//DTD Web Application 2.3V2//EN"
    "http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd">

<jboss-web>

  <!-- A security domain that restricts access
  <security-domain>java:/jaas/JBossWS</security-domain>
  -->
  
  <context-root>jbossws</context-root>

</jboss-web>


Uncomment the security-domain so it appears thus:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE jboss-web
    PUBLIC "-//JBoss//DTD Web Application 2.3V2//EN"
    "http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd">

<jboss-web>

 
  <security-domain>java:/jaas/JBossWS</security-domain>
 
  
  <context-root>jbossws</context-root>

</jboss-web>


The default user name and password are kermit/thefrog

To change this, go to:

/usr/share/jboss-6.0.0.Final/server/default/conf/props

Open jbossws-roles.properties in a text editor it should appear as below.

# A sample roles.properties file for use with the UsersRolesLoginModule
kermit=friend


Change 'kermit' to a new user name. For example, we'll change it to 'mywsuser' as shown below:

# A sample roles.properties file for use with the UsersRolesLoginModule
mywsuser=friend


Open jbossws-users.properties in a text editor it should appear as below.

# A sample users.properties file for use with the UsersRolesLoginModule
kermit=thefrog


Change 'kermit' to our new user name 'mywsuser' and change the password. For example, we'll change the password to it to 'MyWsPassword' as shown below:

# A sample users.properties file for use with the UsersRolesLoginModule
mywsuser=MyWsPassword


Step 11: Set JAVA_OPTS Memory Parameters


To set the memory limits for JBoss, go to: /usr/share/jboss-6.0.0.Final/bin

Open the run.sh file in a text editor.

Find the section below:

# Setup JBoss specific properties
JAVA_OPTS="-Dprogram.name=$PROGNAME $JAVA_OPTS"


Directly below this, add the desired parameters.

# Setup JBoss specific properties
JAVA_OPTS="-Dprogram.name=$PROGNAME $JAVA_OPTS"
JAVA_OPTS="$JAVA_OPTS -Xms128m -Xmx256m"


I'm installing this on a small VPS so I'm using JAVA_OPTS="$JAVA_OPTS -Xms128m -Xmx256m". You should set this to whatever is appropriate to your server and application.

Step 12: Running JBoss on Port 80.


To run services below port 1024 as user other than root, you can use port forwarding.

You can do this by adding the following to your IP tables:

[root@sv2 ~]# iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
[root@sv2 ~]# iptables -t nat -A PREROUTING -p udp -m udp --dport 80 -j REDIRECT --to-ports 8080


Bookmark and Share




Main Menu

Built With

Search

Pages

LinkedIn

Tag Cloud

Hosted by:

Navigation

Visitors

Sponsors

petiole Cloud

Feeds