David Ghedini

Linux, Java, Oracle, and PostgreSQL


David Ghedini

Tuesday Jul 11, 2017

GeoHelm

If you are looking to turn up a full, Open Source GIS stack with the latest versions of all software, check out GeoHelm.

GeoHelm installs the latest, stable releases of

Apache Tomcat
Java
PostgreSQL
PostGIS
PgRouting
GeoServer

It takes only 10 minutes to install

It also provides a UI within Webmin for managing all aspects of the stack (see screenshot below)

Best of all, it doesn't get tangled-up in the software, the module can be completely deleted with no impact on the stack.

Bookmark and Share



Tuesday Aug 14, 2012

Apache TomEE on CentOS 6

This post will cover installing Apache TomEE on CentOS 6.x

TomEE is a certified implementation of the Java EE 6 Web Profile.

What is most interesting is that it is build on top of Tomcat 7. Literally. Nothing has been removed from Tomcat 7, only added to.

Installation is quite identical to Tomcat 7 and you can even deploy TomEE as a WAR from within an existing Tomcat 7.x installation.

I wasn't keen on this option as the overall directory structure, jar locations, conf files, etc...are different from the apache-tomee-1.0.0-webprofile package layout, which we will be installing below.

Conversely, it could be an option to consider as apache-tomee-1.0.0-webprofile is packaged with Tomcat 7.0.27 (current stable is 7.0.29).

There is also a TomEE Plus package with additional features, but this is not Java EE6 certified. Installation of TomEE Plus is identical to Web Profile below, just change the file names.

Below, we'll install TomEE and configure it to run as a service. To see how to run TomEE as an unprivileged user, Manager configuration, run on port 80, etc, etc...please see my Tomcat 7 Installation post

To begin, we'll need to install the Java Development Kit (JDK) 6




Step 1: Install JDK 1.6 latest



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

We'll install the latest JDK, which is JDK 6, Update 33.

For CentOS 64 bit, I'll be using jdk-6u33-linux-x64.bin (for 32 bit, use jdk-6u33-linux-i586.bin)

Download jdk-6u33-linux-x64.bin and save it the /opt directory.

[root@demo3 opt]# ls
jdk-6u33-linux-x64.bin


Creating a new directory /usr/java:

[root@demo3 opt ]# mkdir /usr/java  


Change to the /usr/java directory we created

[root@demo3 opt ]# cd /usr/java  
[root@demo3 java ]# 


Execute the bin file using 'sh /opt/jdk-6u33-linux-x64.bin' (if you saved jdk-6u33-linux-x64.bin to a location other than /opt, adjust accordingly)

[root@demo3 java]# sh /opt/jdk-6u33-linux-x64.bin


This will create the directory /usr/java/jdk1.6.0_33. This will be our JAVA_HOME.


We can now set JAVA_HOME and put Java into the path of our users.

To set the JAVA_HOME, add below to the .bash_profile of root (you can do the same for user tomcat - or any other user - later if you decide to run it under a non-privileged user).
JAVA_HOME=/usr/java/jdk1.6.0_33
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH


Once you have added the above to .bash_profile, issue '. ~/.bash_profile' as shown below. Or you can simply log out and log back in.

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


Verify that Java is now in your path by issuing 'echo $JAVA_HOME'

[root@demo3 ~]# echo $JAVA_HOME
/usr/java/jdk1.6.0_33


You can also issue 'java -version' to check that Java is available to your user.

[root@demo3 ~]# java -version
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03, mixed mode)


Step 2: Download and Unpack Apache TomEE 1.0.0 (or latest)



We will install TomEE under /usr/share.

Switch to the /usr/share directory:

[root@demo3 ~]# cd /usr/share
[root@demo3 share ]# 
Download apache-tomee-1.0.0-webprofile.tar.gz (or the latest version) here

and save it to /usr/share

unpack the file using tar -xzf:

[root@demo3 share ]# tar -xzf apache-tomee-1.0.0-webprofile.tar.gz 
This will create the directory /usr/share/apache-tomee-webprofile-1.0.0

This will be the home directory for TomEE


Step 3: Configure TomEE to Run as a Service.



Create a simple Start/Stop/Restart for TomEE.

Change to the /etc/init.d directory and create a script called 'tomee' as shown below.

[root@demo3 share]# cd /etc/init.d
[root@demo3 init.d]# vi tomee
And here is the script we will use.

#!/bin/bash
# description: TomEE Start Stop Restart
# processname: tomee
# chkconfig: 234 20 80
JAVA_HOME=/usr/java/jdk1.6.0_33
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=apache-tomee-webprofile-1.0.0

case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;; 
stop)   
sh $CATALINA_HOME/bin/shutdown.sh
;; 
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;; 
esac    
exit 0
You can adjust your script according to your needs.

Make the script executable:

[root@demo3 init.d]# chmod 755 tomee
Add to chkconfig with run levels 234 (or whatever you prefer)

[root@demo3 init.d]# chkconfig --add tomee
[root@demo3 init.d]# chkconfig --level 234 tomee on
Verify it:

[root@demo3 init.d]# chkconfig --list tomee
tomee          0:off   1:off   2:on    3:on    4:on    5:off   6:off
Test the script.

Start TomEE:
[root@demo3 ~]# service tomee start
Using CATALINA_BASE:   /usr/share/apache-tomee-webprofile-1.0.0
Using CATALINA_HOME:   /usr/share/apache-tomee-webprofile-1.0.0
Using CATALINA_TMPDIR: /usr/share/apache-tomee-webprofile-1.0.0/temp
Using JRE_HOME:        /usr/java/jdk1.6.0_33
Using CLASSPATH:       /usr/share/apache-tomee-webprofile-1.0.0/bin/bootstrap.jar:/usr/share/apache-tomee-webprofile-1.0.0/bin/tomcat-juli.jar
Check if the Tomcat Manager page is visible at http://yourIPaddress:8080. If not check your firewall and logs.

Stop TomEE:

[root@demo3 ~]# service tomee stop
Using CATALINA_BASE:   /usr/share/apache-tomee-webprofile-1.0.0
Using CATALINA_HOME:   /usr/share/apache-tomee-webprofile-1.0.0
Using CATALINA_TMPDIR: /usr/share/apache-tomee-webprofile-1.0.0/temp
Using JRE_HOME:        /usr/java/jdk1.6.0_33
Using CLASSPATH:       /usr/share/apache-tomee-webprofile-1.0.0/bin/bootstrap.jar:/usr/share/apache-tomee-webprofile-1.0.0/bin/tomcat-juli.jar
Review the catalina.out log located at /usr/share/apache-tomee-webprofile-1.0.0/logs/catalina.out and check for any errors.

[root@demo3 init.d]# more /usr/share/apache-tomee-webprofile-1.0.0/logs/catalina.out


Step 4 (Optional): Configure Remote Access to TomEE Console



By default, the TomEE Console is restricted via a valve to 127.0.0.1 (localhost).

You can remove or change this via the context.xml at:

/usr/share/apache-tomee-webprofile-1.0.0/webapps/tomee/META-INF/context.xml

<Context>
  <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.0\.0\.1|0:0:0:0:0:0:0:1(%.*)?|^::1$" deny=""/>
</Context>


As with Tomcat 7, piping (|) is used in place of commas.


Below is a quick look at the TomEE Console screens and it's tabs:


TomEE Console Welcome Page:

TomEE Console



TomEE Console Test Page:

TomEE Console Test



TomEE Console JNDI Page:

TomEE Console JNDI



TomEE Console EJB Page:

TomEE Console EJB



TomEE Console Class Page:

TomEE Console Class



TomEE Console Invoke Page:

TomEE Console Invoke



To see how to run TomEE as an unprivileged user, Manager configuration, run on port 80, etc... please see my Tomcat 7 Installation post Related Tomcat Posts

Learn More About Apache Tomcat 7 Apache Tomcat Foundation Tomcat 7

Tomcat 7 Hosting

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




Main Menu

Built With

Pages

LinkedIn

Tag Cloud

Hosted by:

Navigation

Visitors

Sponsors

petiole Cloud

Feeds