Search

October 20, 2013

Build and Install JBoss 7.2.0 on CentOS 6.4

As you may or may not be aware, a great many changes have been happening to the JBoss application server since being purchased by Red Hat. Most importantly, the application server is being rebranded as WildFly for version 8. ("Why?" is the first entry on the WildFly FAQ if you are curious.) But since WildFly is not quite ready as of this writing (but looks real close), we are going to deal with the latest community release, JBoss AS 7.2.0.

Before the name change to WildFly, there was a split in JBoss into a 7.x community edition and a 6.x EAP edition. The community edition remains the open source version free to use as before. The EAP edition requires a subscription to use for production purposes (but is free for development). The EAP edition is based on the community edition, typically taking the "Final" version of the community edition as the "Alpha" of the corresponding EAP edition (although keep in mind that the community edition versions are 7.x while the EAP is 6.x). This appears to be a split in the mold of Red Hat Linux begetting Fedora and Red Hat Enterprise.

Whew, that is a lot of change and I haven’t even mentioned that JBoss AS 7 appears to be a complete rewrite. The configuration files and tools are completely different, so if are coming from JBoss 5 or 6, be prepared to invest a little time to get familiar with the new JBoss, er, WildFly.

OK, we are getting closer to the good stuff. In addition to all the changes mentioned above, Red Hat (or JBoss.org or WildFly.org whoever is responsible for the community editions of JBoss AS 7) has stopped providing builds of the JBoss AS 7 line after 7.1.1. Since then there have been versions 7.1.2, 7.1.3 and 7.2.0 but no corresponding build on the JBoss AS download page. Fortunately it is easy to get the source and build JBoss yourself.

We will be using a new CentOS 6.4 box created using the CentOS minimal DVD. We’ll start by installing Java; instead of going to Oracle, I decided to try the OpenJDK from the CentOS repositories to see how that goes:

Next we create a jboss user on the server to build and run JBoss as. (You may want to call the user jboss-as since the JBoss scripts reference this user by default. I already have a convention of using the user jboss and I want to stick with it.)

If you take a look at the README.md file in the download there are some basic instructions on how to do the build. One pleasant surprise is that there is no need to install maven. We do want a couple of tweaks to the command line they suggest however in order to skip the unit tests and get a release tarball. After running the command above you will find the tarball in the dist/target directory.

Now that we have a build of JBoss AS 7.2.0 on the system, we need to configure CentOS to treat it like a service. JBoss comes with some scripts in the bin/init.d directory that will help with this. I am using the standalone server, but it is not difficult to modify the instructions for the domain server. First up is the /etc/jboss-as/jboss-as.conf file.

# General configuration for the init.d scripts,# not necessarily for JBoss AS itself.# The username who should own the process.#JBOSS_USER=jboss
# The amount of time to wait for startup## STARTUP_WAIT=30# The amount of time to wait for shutdown## SHUTDOWN_WAIT=30# Location to keep the console log#JBOSS_CONSOLE_LOG=/var/log/jboss-as/console.log
# JBoss installation directory (default is /usr/share/jboss)JBOSS_HOME=/opt/jboss/jboss-as-7.2.0.Final
# Server configuration file, using full JEE 6 profileJBOSS_CONFIG=standalone-full.xml
# Need to modify the init script to account for theseJBOSS_OPTS="--properties=/etc/jboss-as/jboss-as.properties"

Just in case you are confused on the two files, jboss-as.conf is a bash script that is sourced by the JBoss init script; use it to set environment variables for the scripts. As for jboss-as.properties, it is a Java properties file that is read by JBoss on start up. Use it to set JBoss system properties (we will get to an example shortly).

Next up we will deposit the init script in /etc/init.d and set the server to start on boot:

As-is the scripts do not allow passing any additional options to the JBoss process, so we need to edit the /etc/init.d/jboss-as script to add the $JBOSS_OPTS variable whenever JBoss is starting. Here is the edited snippet (I’ve added some line breaks for readability):

To get JBoss to use these directories, we set the system properties for them in /etc/jboss-as/jboss-as.properties:

# System properties for jboss-asjboss.server.log.dir=/var/log/jboss-as
jboss.server.temp.dir=/tmp/jboss-as

At this point you can start the server using the command service jboss-as start. You won’t be able to do much however, unless you like browsing via wget since the server is bound to the localhost interface only (and we are working on a headless server, i.e. no GUI web browser). So we’ll need to bind JBoss to all interfaces and open up the CentOS firewall to allow browsing to JBoss and the management console. Keep in mind that this may not be exactly what you want in a production environment or in environment where unknown users might access your server (like shared hosting).

Depending on how your local network is setup you may need further configuration for JBoss to be completely happy binding to all interfaces. If your DNS recognizes the name of the CentOS server you are working on, congratulations, you are all set. On the other hand, if DNS is not configured for the server, you will need to add an entry to the /etc/hosts file pointing the name of the server to the external IP.

Next we need to open the firewall for ports 8080 (regular JBoss) and 9990 (the management console). Be careful when adjusting the firewall. The commands below use hard-coded line numbers that may not be appropriate for whatever system you are using. If you think you have screwed up your firewall use service iptables restart to reset it. Of course, this won’t work after you issue service iptables save so be extra sure before you save the rules. You will also need to replace 10.0.0.0 with your subnet below.