Friday, August 29, 2008

VMWare ESX Server Templates on the Cheap

When it came time to expand our internal server hosting beyond what the air conditioning and power in our small server room could support, VMWare ESX Server was a relatively easy sell. We are currently running 3 DL580 servers with about 24GB of RAM each and as many processors as we can jam in them. This solution is hosting roughly 65 environments, mostly quality assurance and user acceptance testing Java environments running WebSphere 5.1.1.8 and IIS. Generally they run happily, even though we don't constrain the CPU and memory usage of the VMs.

The main reason we don't restrict resources is because we have no central management of our VMs since we didn't purchase virtual center. We would want to use resource pools to allow our various teams of developers to allocate their allotted resources as appropriate for where they are in their release cycle. For example, I would create a resource pool for "ClientX", and then allow ClientX to determine if they want their QA environment to be allocated more hardware resources because they don't have an application in UAT at the moment, while still ensuring ClientY has their own resources and are not affected by the activities of ClientX. That's all great on paper, but when ClientX is spread out with environments on two or three different servers it really detracts from your ability to allocate accordingly without a way to centralize the resources.

Getting back to the topic at hand, not having VirtualCenter also prevents us from using templates. A large part of the appeal of VMWare is that it speeds up server deployments; what used to take us weeks of acquiring hardware, building, and racking now takes hours. However, without templates we would find ourselves building each OS from scratch, and that's lame.

What we did was build a VM called "2k3_template" on a SAN drive, installed our OS, patched it, installed our all standard software and tweaks, and then ran sysprep. Once it shut down, I removed it from the inventory but left the files. Now when I need a new server I ssh into the VMWare server, make an empty folder on the san that corresponds to the new server name, and run this:
vmkfstools -i /vmfs/volumes/san_volume/name_of_template/name_of_template.vmdk /vmfs/volumes/san_volume/new_server_name/newservername.vmdk

That will create a copy of the template called newservername. Then, you go into the Virtual Infrastructure console and create a VM, making sure to select a "custom" VM named the same thing as you named it from the command line. When it comes time to create a new VMDK or use an existing one, use the one you created with vmkfstools. Power it on, go through mini setup, and you have a new server ready to go.