This blog post is part 3 of the “Buiding your own IaaS” series. Part 1 discussed different virtual machine hosting models, and focused on a service which provides physical machines preinstalled with virtualization software. Part 2 introduced an auxiliary machine running a DHCP server and a web proxy for the virtual machines. In this blog post we will actually start a new VM and install CentOS on it.
Step 1 – Start a new machine and install CentOS
Open XenCenter and click the “New VM” button.
Follow the XenCenter and centos installation steps in the slideshow below:
Step 2 – Setup web proxy settings for yum
Login as root to the new machine and update the yum installation proxy settings.
(scroll down to the end of the file and enter your squid’s ip address as proxy)
Use yum to install standard centos software components
Step 3 – Install Sun JDK
Get a download link of the latest Sun JDK RPM, or one of the previous Sun JDK versions. Download and install the RPM file:
wget (paste your link here)
mv *-rpm.bin jdk.bin
chmod +x jdk.bin
Step 4 – Install XenServer tools
Right click the virtual machine in XenCenter and choose “Install XenServerTools”. This tool installs an agent on the virtual machine monitoring (among other things) it’s IP Address, essentially exposing the machine’s IP Address tthrough the XenServer API.
Use the following set of commands to mount and install the xenserver tools on the virtual machine
wget (paste your link here) cd /mnt
mount /dev/xvdd /mnt/xs-tools/
Step 5 – Configure the firewall
CentOS comes with the iptables firewall. You would need to configure the firewall in order to connect to/from the machine.
Here are some instructions how to clear all firewall rules or enable only incoming SSH connections.
When using the –source (or –s) you can specify the whole subnet 10.24.82.197/27 (modify based on your network settings)
You can temporarily disable the firewall by executing
Step 6 – Copy other files over SSH
The next step is optional and that is to copy your files into the virtual machines.
This is done by first copying the files to the DHCP machine, and from there copying it to your virtual machine.
Use SCP to copy files into the virtual machine. The following example copies the petclinic directory to virtual machine’s root home folder. In this example 10.24.82.197 is the physical machine reachable via VPN, and 10.24.82.214 is the new CentOS virtual machine reachable only through the physical machine.
If you are running a Linux on your laptop, simlpy scp the files from your laptop to the physical machine. Windows users could use WinSCP instead
scp -r petclinic email@example.com:~
Once the files are copied, login to the physical machine and copy the files to the virtual machine
scp -r petclinic firstname.lastname@example.org:~
Step 7 – Clone new centos machines
After you’ve completed customizing the virtual machine you can shutdown it down.
In order to start a new machine, right click CentOS_5.3 machine and clone it.
XenServer has two clone mechanisms. Full copy duplicates the VM hardrive before starting the clone. Fast Clone uses hardware level cloning to start a new VM without actually copying the VM hardisk. Only when the new clone hardisk changes, it performs a copy (Copy-on-Write). This feature is designed to save disk space and allow fast clones, but may slightly slow disk performance.
You can automate this process by using the XenServer API from Java. Here is a quick cheat sheet for XenServer API .