Monday, December 27, 2010

Installing & Running JBoss in Ubuntu

Being mostly a Java guy, a couple of my favorite servers to work with are Tomcat and JBoss. While at work, it has been exclusively Tomcat, lately, I've been mostly interested in working with JBoss. For a couple years, I've had JBoss installed on my Windows machine. It is pretty easy,just unzip on your hard drive and execute the run script in the bin directory.

Since I installed Ubuntu, I've wanted to switch to using Linux as my JBoss OS. With Ubuntu, I could easily use the update manager, or apt-get jboss, to get it installed. However, it wouldn't give me the version I wanted. So, I figured I'd work this manually.

The first thing I do, is download a zip. A common place to put the software is /usr/local. So, I will download, and unzip the package there.
cd /usr/local
sudo wget http://sourceforge.net/projects/jboss/files/JBoss/JBoss-6.0.0.Final/jboss-as-distribution-6.0.0.Final.zip
sudo unzip jboss-as-distribution-6.0.0.Final.zip
The funny thing is that I can't seem to find a tarball for JBoss, so I just get the zip. Based on this, and the directory structure of JBoss, it seems that the development of JBoss was mostly geared towards Windows based servers. Regardless, it works great on Linux as well.
Now, at this point, you can just run JBoss out of the box, using the run.sh script in th ebin directory.
sudo /usr/local/jboss-6.0.0.Final/bin/run.sh
This will start up the server, and the terminal window would be the standard output. It that is all you need, then you can stop right here. But in general, there are a couple things to simplify the start up and shut down process. I like to control the server as a service, from the /etc/init.d directory. Within the bin directory, there is a startup script which will call the run.sh script as the jboss user. The script is written with redhat in mind, but is easily modified to run with Ubuntu. But first, lets create a jboss user and grant ownership to the jboss directory.
sudo useradd -s /bin/bash -d /home/jboss -p jboss
sudo chown -R jboss:jboss /usr/local/jboss-6.0.0.Final/
The useradd command will create the jboss user, with the /home/jboss directory as it's home, and the default shell is bash. This command will create the jboss user without a password. If you are like me, and like to make things as secure as possible, use sudo passwd jboss to create a password for the jboss user.

sudo ln -s jboss-6.0.0.Final/ jboss. The chown command grants ownership to the jboss user. The -R, after the chown command, does a recursive call to the sub directories.
Now that the jboss user is set up, copy the jboss_init_redhat.sh file into the /ect/init.d directory, and name it jboss.
sudo cp jboss-6.0.0.Final/bin/jboss_init_redhat.sh /etc/init.d/jboss
There are a couple changes we need to make with the file. first, it assumes that the JBoss home directory is /usr/local/jboss. By default, our command to unzip the package created the home as jboss-6.0.0.Final/, so we can either rename the directory, with the mv command, change the init file to reflect the real path, or create a symbolic link. I prefer the symbolic link, because we can keep the old packages as we download more, and if we need to revert, it is just a matter of modifying the symlink.
sudo ln -s jboss-6.0.0.Final ./jboss
The next change is in the file itself. Use VI and modify the JAVAPTH variable to the correct path of your java command. In my case, and most likely yours as well, the path is /usr/local/bin. If you don't know the path, just use the command "which java". Verify some of your other variables, just in case you need to make changes for your system.

At this point, you are all set to run it as a service. Use the following commands to start, stop, and restart the server.
/etc/init.d/jboss start
/etc/init.d/jboss stop
/etc/init.d/jboss restart
If you created your jboss user with a password, you will need to supply the password. The server will start up and the logs will be written to /usr/local/jboss-6.0.0.Final/server/default/log/server.log. If you'd like to have the server start at system start, then you can update the rc.d to include it as an auto start up.
sudo update-rc.d jboss defaults
I personally prefer to start it up as needed. Once started, you can deploy your jars, wars, and ears as you normally would, in the deploy directory of the server you are using. In this case, we are using the default server.

Update 12/29: I updated this post to reflect the GA release of JBoss 6.0.

2 comments:

Chris Pyle said...

Thank you so much for this! I am working through it and thought you should know that in my case I needed to append " jboss" to the adduser command call - Ubuntu 10.10 64bit did not like leaving the "LOGIN" off. Again, thank you for this guide - I'd be totally lost without it.

Chris

Anonymous said...

I'm new to everything and these instructions were very helpful -- Thank you!