Thursday, May 19, 2011

JBoss 5.1.0GA with Ubuntu 10.04

That was the first time that I tried to install Jboss server on a linux platform(it doesn't mean that I installed it on a different OS :P). After downloading "installation and getting started guide", I started to follow installation steps and configure our server environment. I won't rephrase what is already written in the guide so I want to share some important points that may help you. 

1. Configure your java environment: If sun jdk is not installed on your system, you have to start with this step. 
  • DO NOT forget adding java related environment variables for your users. It is a good idea to set those variables within .bashrc files. Add those lines to your files:
    export JAVA_HOME=/usr/java/jdk_versionNo
    export PATH=$PATH:$JAVA_HOME/bin

    Update your java home path as you prefer.
  • DO NOT forget to update your java alternatives. Because it is possible that you have more than one java installation, and you have to tell your system which java version to use. Use the command:

    $ update-alternatives --config java

    Note: It is possible that you don't see your previously downloaded java version. In this case, you have to manually add this option using the command:

    $ update alternatives --install "/usr/bin/java" "java" "/usr/lib/Java6/bin/java" 1

    Parameters are respectively as the following: system-wide java command, for "java", your previously installed java installation path and priority. After adding this option, you can update your java version as described above.
2. Download JBoss: In my case, I downloaded binary zip file of JBoss 5.1.0GA, and extracted files to a folder.

3. Set the JBOSS_HOME variable: As we set java environment variables, this time we will set jboss related environment variables. You will edit .bashrc files of your users, and specify jboss home path by adding those lines:

export JBOSS_HOME=/usr/jboss/jboss-release_no
export PATH=$PATH:$JBOSS_HOME/bin
Update your jboss home location as you prefer. 

4. Test your installation: The most exciting part is this step :) Simply, you go to JBOSS_HOME/bin directory and execute "run.sh" script as the following:
$ ./run.sh
Note that you need to have privileges to execute this command. 

If everything goes well, go to "localhost:8080" page on your favourite web browser, then you will see a jboss welcome page. Good news! :) Note that instead of "localhost", you have to type "127.0.0.1" for some systems. 

If there is no other application using your 8080 port, and you work on a local machine, all steps described above will help you to set up your jboss server. I needed to work more on it because I did this installation on a server environment, thus I needed to start Jboss on a specific ip using 8080 as port number. Again you need to execute "run.sh" script but with additional parameters:
$ ./run.sh -b "ip_number"
That command will start Jboss server on this ip with the default port 8080. 

Everything is going well, we started the server without any problem. BUT.. Of course, we need additonal things!.. What if your system reboots? Jboss won't start because we didn't do anything about it. So let's work on a init script. This page helped me to do things right. 

5. Add an init script: In our JBOSS_HOME/bin directory, you will see some init script example files. I used "jboss_init_redhat.sh" as a template, modified jboss home, jboss user, java path, jboss bind address(-b parameter value) settings. Find this line:
JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"} and above this line insert this one:
JBOSS_HOST=${JBOSS_HOST:-"ip_number"} If not specified Jboss server will start on localhost. 

Then, rename this file as "jboss" and move it to your "/etc/init.d" directory.
  • DO NOT forget to make this script executable. And again, take care of user access rights as necessary according to your needs. 
  • Use this command to create necessary symbolic links for yout init script:
    /etc/init.d/$ update-rc.d jboss defaults
    Now your script will run on boot up.
6. Test and update your init script: Run the following command:
$ service jboss start
It works as expected, you can check it by opening "localhost:8080". But when trying to stopping the server, I had many errors and server didn't shut down.  This is because, we need to add "host" parameter to our shutdown command. Find the line beginning with "JBOSS_CMD_STOP" and update it as the following:
JBOSS_CMD_STOP=${JBOSS_CMD_STOP:-"java -classpath $JBOSSCP org.jboss.Shutdown --shutdown -s jnp://${JBOSS_HOST}:1099"} Bold text is the part that you have to add to this line. 

After this modification use those commands for following actions:
service jboss start --> start jboss server
service jboss stop --> stop jboss server
service jboss restart --> restart jboss server

7. (optional) Adding logging feature to your init script: Default server log files are included in:
$JBOSS_HOME/server/$JBOSS_CONF/log/ directory. JBOSS_CONF is default, minimal etc as you specified in your script file. By default, it is set to be "default". So I prefered to log init script logging in this directory, you can specify any other folder if you want. To add logging functionality to your script, update your script as the following:
JBOSS_CONSOLE="$JBOSS_HOME/server/$JBOSS_CONF/log/init_script.log" So you replace "/dev/null" by a real file. 

8. (optional) Upload your java project: After opening "localhost:8080" page, click on "Administration Console" link. Default user/pass is "admin"/"admin". You can use this page to manage your Jboss server. Go to "Web Applications" link and upload your project. 

If you want to change user settings, or add new users for administration console, you can simply edit ..server/configuration/conf/props/jmx-console-users.properties
..server/configuration/conf/props/jmx-console-roles.properties
files in your system.

Hope this blog post will help you. Enjoy it :)