Posts Tagged ‘glassfish’

Installing Glassfish v2.1 and configuring a cluster

I have been a Tomcat guy for the longest time but from time to time I like to play with the other guys software so it was either Jetty or Glassfish. I choose Glassfish. I’ve used Glassfish before for development testing and running rails but have not had any real J2ee apps running inside. Let’s have a look at the installation procedures for Glassfish and what you get after a few minutes of clicking.


Glassfish can be downloaded from we are going to use the latest stable (production ready) build of v2.1 b60.


I’m running this on a Linux (Centos) server so here are the steps to install and setup Glassfish WITH the cluster configurations:

[root@heimdull]# java -Xmx256m -jar glassfish-installer-v2.1-b60e-linux-ml.jar [root@heimdull]# cd glassfish [root@heimdull]# chmod -R +x lib/ant/bin [root@heimdull]# lib/ant/bin/ant -s setup-cluster.xml bla bla bla .... BUILD SUCCESSFUL Total time: xx seconds


Before we configure some custom settings lets just get this thing started…

[root@heimdull]# export PATH=~/glassfish/bin:$PATH
[root@heimdull]# asadmin start-domain

Now you can access the administration console at http://localhost:4848/ by default the server does NOT bind to localhost but so if you do not have a firewall you can access the console from outside the server too.

PS. There is a issue where the admin console might keep logging you out and asking for your credentials on every click. This is a cookie problem. Clear your browser cookies and you should be fine.

Change admin password

If you want to change the default admin user password (which is adminadmin) run the following command:

[root@heimdull]# asadmin change-admin-password --user=admin

Creating the cluster

Go to http://localhost:4848 and login. After this click on the Clusters menu option and select new, name the cluster something like my-cluster and click ok. You have now created the shell configuration for our cluster.

Now lets repeat the installation process on the cluster node. After you have installed Glassfish on the “node-agent” you are going to run a command to connect this server to the running admin-node that we installed in the initial installation steps. (Do not start the domain on the node-agent before it is connected to the admin server)

[root@heimdull]# asadmin create-node-agent --host admin-node --port 4848 --user admin my-cluster-agent-1
[root@heimdull]# asadmin start-node-agent my-cluster-agent-1
Please enter the admin user name>admin
Redirecting application output to /opt/glassfish/nodeagents/slave.local/agent/logs/server.log
Command start-node-agent executed successfull
Please enter the admin user name>admin Please enter the admin password>password Please enter the master password [Enter to accept the default]:> Redirecting output to /opt/glassfish/nodeagents/slave.local/agent/logs/server.log Redirecting application output to /opt/glassfish/nodeagents/slave.local/agent/logs/server.log Command start-node-agent executed successfully.

You now have a running cluster of 1 node. Login to the admin console and have a look, cluster of one, nice!

Create the server instance

You do now need to create the server instance which will be running in the cluster. Click on the clusters menu and select my-cluster. Now click the Instances menu button and click new.

Name the instance instance-1 and select the newly added node agent.

You now have the following components running/installed:

– (DAS) Domain Admin Server: This is the server that will controller the “cluster”.

– (NA) Node agent: All members of the cluster needs a nodeagent that connects to the admin server. The nodeagent needs to be started on the cluster member before the admin server can do any monitoring/administration of the member.

– (SI) Server Instance: This is where all the action is, this is the actual “server” that will be added to the server and this is where you application will be running.

Mac(OSX) Jruby and Rails 2.2 — Part 2

Running webrick isn’t doing what we want… How about Tomcat? Or maybe Glassfish? Well I have heard that glassfish is VERY EASY, lets checkit out…

Step 1:
~$ sudo jruby -S gem install glassfish
Successfully installed glassfish-0.9.0-universal-java
1 gem installed
Installing ri documentation for glassfish-0.9.0-universal-java…
Installing RDoc documentation for glassfish-0.9.0-universal-java…

DONE… no I’m serious… THAT WAS IT!!!

Lets start the server:

~$ jruby -S glassfish_rails myapp
Nov 17, 2008 7:21:23 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
INFO: Launching GlassFish on Apache Felix OSGi platform
Nov 17, 2008 7:21:23 PM com.sun.enterprise.glassfish.bootstrap.ASMainOSGi findDerbyClient
INFO: Cannot find javadb client jar file, jdbc driver not available

Now I can access the rails app at http://localhost:3000/


Here is some more information about the glassfish gem:

-c, –contextroot PATH: change the context root (default: ‘/’)
-p, –port PORT: change server port (default: 3000)
-e, –environment ENV: change rails environment (default: development)
-n –runtimes NUMBER: Number of JRuby runtimes to crete initially
–runtimes-min NUMBER: Minimum JRuby runtimes to crete
–runtimes-max NUMBER: Maximum number of JRuby runtimes to crete
APPLICATION_PATH (optional): Path to the application to be run (default:

This is almost too easy for a development environment…

THIS IS NOT A BENCHMARK BUT even so here is the info…

My laptop with a test app I have and seed data installed thin 1.0 and Glassfish…

With threading:
Requests per second: Thin 10 [#/sec]
Requests per second: Glassfish 14 [#/sec]

Without threading:
Requests per second: Thin 3 [#/sec]
Requests per second: Glassfish 2.6 [#/sec]

🙂 Not what I was hoping for …

Mac(OSX) Jruby and Rails 2.2

Not Sure why but I wanted to try JRuby and Rails(2.2) new threads…

These are the steps I used to get a application on my mac running with Rails 2.2 and JRuby 1.1.3(I used ports to install JRuby thats why 1.1.3).

Here are the steps:

– First Install JRuby .. # sudo port install jruby

– Fix an annoying warning .. # sudo jruby -S gem install jruby-openssl

– Install rails .. # sudo jruby -S gem install rails

– Install the database connector .. # sudo jruby -S gem install activerecord-jdbc-adapter

– Upgrade the gem environment .. # sudo jruby -S gem update

– Install latest RubyGems (Rails 2.2 Needs 1.3.1 or higher.. ) .. # sudo jruby -S gem install rubygems-update

– Now you have to force install the update .. # sudo jruby -S update_rubygems

– Install Rails 2.2.1 .. # jruby -S gem install rails -s

# jruby -S rails myapp
# cd myapp
# vi config/database.yml

adapter: jdbc
driver: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost/testapp_development
username: root

# vi config/environment.rb
Add this code:

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), ‘boot’)
if RUBY_PLATFORM =~ /java/
require ‘rubygems’

# jruby script/server
=> Booting WEBrick…
=> Rails 2.2.1 application started on
=> Ctrl-C to shutdown server; call with –help for options
[2008-11-17 16:40:34] INFO WEBrick 1.3.1
[2008-11-17 16:40:34] INFO ruby 1.8.6 (2008-11-17) [java]
[2008-11-17 16:40:34] INFO WEBrick::HTTPServer#start: pid=13484 port=4000