Tuesday, January 17, 2012

Complex development environments with VirtualBox

Having a local environment independent of any other existing environments has a big advantage: Development is not stopped when other environments are down and it even stops the "need" to hit production just because it is the only environment currently available. But perhaps the biggest advantage of all is to be able to work literally anywhere even if you have no internet connection at all.

Virtualization can help with this and here is how to host your whole environment locally in your machine using VirtualBox.

In an Enterprise you will find Solaris, Windows, OSX, Unix and what not. I personally use a Mac Book Pro with VirtualBox. In VirtualBox I can run as many VMs as I need to recreate the surrounded environment.

Ideally we should have an environment following the next features:
  1. The guest should have connectivity to internet taking advantage of your network configuration in the host
  2. The guest should communicate to the host even if no internet connection is available
  3. The guest should automatically work independent what network you are using, from work, from home or even on the road with no local network at all

Virtual box will allow these features if we just add a first network interface as NAT (for internet) and the second as host-only (for connectivity with the box)

We will show this process using a virtualized instance of an Advent Geneva Server (A Solaris Box with some proprietary Accounting Software). It is useful to have this server locally to be able to mess with RSL reports for example without affecting other members of the dev or operations team.

In the host find the vboxnet0 interface to be sure you use an IP in the same network later on in the guest:
$ ifconfig -a
vboxnet0: flags=8843 mtu 1500
 ether 0a:00:27:00:00:00 
 inet netmask 0xffffff00 broadcast

In the Solaris guest ...

Configure first interface (NAT) to use DHCP
$ touch /etc/dhcp.e1000g0
$ rm /etc/hostname.e1000g0
$ touch /etc/hostname.e1000g0
$ ifconfig e1000g0 plumb
$ ifconfig e1000g0 up
$ ifconfig e1000g0 dhcp start

And second interface (host-only) to use a static IP
$ vi /etc/hosts
... genevadev loghost
$ rm /etc/dhcp.e1000g1
$ vi /etc/hostname.e1000g0
$ ifconfig e1000g1 plumb
$ ifconfig e1000g1 genevadev up

Be sure to define DNS available from any network to connect to the internet (only to be used in the case you do need internet in the guest) If you really need to access local resources you might want to add local DNS as well.
$ vi /etc/resolv.conf

Make sure you see both interfaces (the NAT and host-only). They should show up as e1000g0 and e1000g1. The first with an internal 10.0.xxx.xxx IP and the second with the static IP you picked (for this example
$ ifconfig -a

Clearly the static IP must be in the same subnetwork (192.168.56.xxx).

You should be able to connect to the internet from the guest and at the same time ssh into it using its IP. Do not forget to add in your host the new created server resolution:
$ vi /etc/hosts

The question about sharing this environment or building it from scratch is one interesting topic. An even more interesting is left as homework and it deals with devops. In reality regardless the path you follow you should automate your actions and there is where things like http://vagrantup.com/ and puppet/chef can help you further.

No comments: