Installing GlassFish on CentOS 6 (EC2)

We had a pretty old server Ubuntu server with GlassFish 2.1.1 running. At some point we decided to move it to a more recent OS version. Being a long time Fedora user and a sort Red Hat fan boy in general – CentOS on EC2 was a pretty straightforward choice for me. Moving there was not trivial but finally I got things running in the manner I really want and would like to highlight some problems you might come across.

Initial server configuration

So we purchased a one year m1.small reserved instance from Amazon and started the instance CentOS instance (centos-x32-6.0-core). Expanding root EBS size to 75Gb. Usual removal of the unneeded packages and yum update to get the latest versions of the packages. Trivial configuration of PostgreSQL (8.4 is still the default one in the CentOS repos). No problems here.

Trying to create a user and No space left on device
Well, how could it be? I have 75GB partition! Not at all, I have 75GB disk but 4GB partition:

[root /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvde1            4.0G  3.9G     0 100% /
tmpfs                 837M     0  837M   0% /dev/shm

(parted) print devices
/dev/xvde (75.2GB)

Okay, lets resize it.

[root /]# resize2fs /dev/xvde1
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 1048233 blocks long.  Nothing to do!

Nothing to do. Interesting. Lets detach it and attach it to another CentOS. Hopefully parted will help to resize it.

(parted) resize 1
Start?  [32.3kB]?
End?  [4294MB]? 75GB
Error: File system has an incompatible feature enabled.  Compatible features are has_journal, dir_index, filetype, sparse_super and large_file.  Use tune2fs or debugfs to remove features.

Well,

[root /] debugfs -w /dev/xvdf1
debugfs:  feature -resize_inode
Filesystem features: has_journal dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize


[root /] resize2fs /dev/xvdf1
resize2fs 1.42 (29-Nov-2011)
resize2fs: /dev/xvdf1: The combination of flex_bg and
!resize_inode features is not supported by resize2fs.

Trying recreating partition via fdisk. Still the same.Almost in desperation and about to go to Ubuntu Server LTS. But occasionally I find some patch available. It’s exactly about my problem! Great! Lets try the latest Fedora 19. Starting Fedora 19, attaching EBS volume and BINGO! I really love Fedora for being an upstream distro.

[fedora ~]$ sudo resize2fs /dev/xvdf1
resize2fs 1.42.7 (21-Jan-2013)
Resizing the filesystem on /dev/xvdf1 to 18350072 (4k) blocks.
The filesystem on /dev/xvdf1 is now 18350072 blocks long.

[fedora ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvdf1             69G  3.8G   62G   6% /
tmpfs                 837M     0  837M   0% /dev/shm

Okay done. Time to move forward and install GlassFish.

Running GlassFish on port 80 without root permissions

Creating GlassFish user and installing server with the help of instructions is pretty trivial. It worked fine for 2.1.1 with the exception of one thing. I definitely want to run it on port 80 but don’t want to to give root permissions. So the options are:
  1. Use authbind tool. Unfortunately it’s not available in CentOS repos, just Ubuntu/Debian ones.
  2. Use jsvc. Requires a bit of configuration.
  3. Using CAP_NET_BIND_SERVICE POSIX capabilities. It started working in 2.6.24 kernel. So why not using this one since it’s already available on the host.

[root /]# getcap /usr/java/default/bin/java
[root /]# setcap cap_net_bind_service=+ep /usr/java/default/bin/java
[root /]# getcap /usr/java/default/bin/java
/usr/java/default/bin/java = cap_net_bind_service+ep

Try running java as root:

[root /]# java -version
java version “1.7.0_25”
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)

Good. Running as glassfish user:

[glassfish ~]$ java -version
/usr/java/jdk1.7.0_25/bin/java: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory

But it’s there:

[root /]# locate libjli.so
/usr/java/jdk1.7.0_25/jre/lib/i386/jli/libjli.so

After a short research it appears that it’s a special feature to prevent library loading from the external places.

[root /]# ln -s /usr/java/jdk1.7.0_25/jre/lib/i386/jli/libjli.so /usr/lib/

And everything works now:

[glassfish ~]$ java -version
java version “1.7.0_25”
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing) 

And the last step is to add init.d script to be share that GlassFish starts automatically after reboot:

  1. Login as root
  2. vim /etc/init.d/glassfish and add script: http://pastebin.com/nyHqspUp
  3. chmod 755 /etc/init.d/glassfish
  4. chkconfig –add glassfish
  5. /sbin/chkconfig –level 3 glassfish on

As a result we now have GlassFish server running on port 80 without the requirement of having root permissions.