Glassfish over a Zone over OpenSolaris
By Marcelo Vitor Moretti Arbore on Feb 04, 2009
Today I'll try to show you guys how to create a zone in OpenSolaris and install a glassfish application server on the top of it.
First of all, you need a native installation of Solaris10/OpenSololaris or a virtual machine with one of these installed. Here you can find how to set up a vm with OpenSolaris.
You can refer to the Zones Administration Guide too.
To see the zones on the system:
# zoneadm list -vi ID NAME STATUS PATH BRAND IP 0 global running / native shared
Let's configure one more called glasszone for us:
zonecfg -z glasszone glasszone: No such zone configuredUse 'create' to begin configuring a new zone. zonecfg:glasszone> create zonecfg:glasszone> set zonepath=/export/home/glasszone zonecfg:glasszone> set autoboot=true
Zonepath is the place that solaris will create the filesystem for the new zone. If you don't want your zone to start running automatically at the boot time, you can set autoboot=false or just leave it.
Now, let's add a virtual network interface, commit the zone, install it on the system, boot and login( -C option is used in the first time you start the zone to configure the hostname, dns server, root password and some other stuff).
zonecfg:glasszone> add net zonecfg:glasszone:net> set address=10.0.2.20/24 zonecfg:glasszone:net> set physical=e1000g0 zonecfg:glasszone:net> set defrouter=10.0.2.2 zonecfg:glasszone:net> end zonecfg:glasszone> commit zonecfg:glasszone> exit # zoneadm -z glasszone install # zoneadm -z glasszone boot # zlogin -C glasszone
The address is the ip of your subnet that the zone will use, and 24 is the number of 1's of the bitmask of the subnet mask that you have. More info on this here.
Remember that the interface will be shared, and the glasszone will be visible to the outsiders. This means that the glasszone and the globalzone will need different ip addresses of the net, and your interface will act like a router.
INFO: Zones doesn't support dhcp yet.
In my case, I'm using VirtualBox to virtualize the OpenSolaris system. It created a subnet for the system with the default router 10.0.2.2 and the default dns server 10.0.2.3 .
Physical is the interface that glasszone will share (must be a configured, plumbed, working interface).
You can see the interfaces information through the ifconfig command in the globalzone.
# ifconfig -a [...] e1000g0: flags=201004843
mtu 1500 index 2 inet 10.0.2.15 netmask ffffff00 broadcast 10.0.2.255 ether 8:0:27:31:8b:21 e1000g0:1: flags=201000843 mtu 1500 index 2 zone glasszone inet 10.0.2.20 netmask ffffff00 broadcast 10.0.2.255 [...]
Now the zone should be up and running:
# zoneadm list -vi ID NAME STATUS PATH BRAND IP 0 global running / native shared 1 global running /export/home/glasszone ipkg shared
Login to it. We're going to install the glassfish app. Since a zone is an instance of the OpenSolaris operational system, if the fs is not mounted anywhere, the only way to communicate with it is though the network interface (remember that it is a virtual interface, so if you are communicating between zones, minimum delay is expected).
Basically you need two things: The jdk and the glassfish app.
My tip: Download both at once:
Of course you can install it separately, but you will have to set some environment variables such as JAVA_HOME and the PATH. It isn't so hard, but it isn't so fast too, so I'll keep my advise.
You can download it logged to globalzone and then move it to the glasszone space. You can use wget to download it directly into your zone too.
TIP: Use -console option to install, because you have just a console in the zone.
You may have to set the execution permission for the downloaded file.
chmod +xxx runnable.bin
Now that you have installed it, you should be able to start a sample domain:
# asadmin start-domain domain1
Once it started, you should be able to see it on the hole subnet by typing in your browser:
http://10.0.2.20:8080 or http://glasszone:8080
TIP: Probably you will have add the glasszone entry in the /etc/hosts in the globalzone.
#echo “10.0.2.20 glasszone” >> /etc/hosts #cat /etc/hosts […] 127.0.0.1 localhost 10.0.2.20 glasszone
Now you have a "ready to use" web application server enviroment inside a zone inside the OpenSolaris OS.
Please post a comment or send me a email if you have any doubts, suggestions or if you find something here that isn't that right. We're a community and your help is very welcome a encouraged. =)
References and related links: http://blogs.sun.com/observatory/entry/screencast_installing_opensolaris_in_virtualbox http://opensolaris.org/os/community/zones/ http://www.sun.com/bigadmin/content/zones/opensolaris_zones_preso.pdf http://number9.hellooperator.net/articles/2007/03/29/glassfish-in-a-zone http://docs.sun.com/app/docs/doc/817-1592 ⁞