Sandeep Koul
As mentioned in our previous article, we're going to build a private cloud on two hosts with shared NFS. This setup will allow you to move VMs across hosts. Before installing anything, you must ensure that you have created an isolated network. You'll need to have at least the following four machines on this network:
1. A server to create the NFS storage
2. Two Server Hosts
3. A machine for the web UI of the Xen Cloud platform
As we are going to create a pool of resources, both hosts must have the same CPU. In our case, each host had an AMD Phenom processor and 4 GB of memory. We're not going to store VMs on the local hard drives of these hosts, so you just need around 16 GB of disk space on each host.
Installing XCP
Take Xen XCP from this month's PCQuest DVD, or download it from http://www.xen.org/products/cloud_ source.html. Burn this ISO on a DVD. It's a bootable DVD, so simply insert it into each host server and boot from it. The installation is pretty straight forward as there are only a few configurations you have to make.
Just keep the following in mind while installing:
a. If a host is having multiple disks you would be prompted to select one from amongst them.
b. When the wizard prompts for the source of installation packages, specify 'Local media'.
c. In the network configuration, it's recommended that you assign static IP addresses to each host or select the option that says 'Automatic Configuration (DHCP)'. As we were only running a test case, we selected 'Automatic Configuration (DHCP)' in most of the places i.e for 'DNS Configuration' and 'NTP configuration'.
d. You would be prompted for NTP configuration if you have not manually added system time in the host. Once the installation is over you would get an interface that is quite similar to VMware's ESX/ESXi (if you have worked on it).
Repeat the same procedure for both hosts and they'll be ready.
Creating NFS
For storing VMs we have used network file storage or NFS. For creating NFS we have used Red Hat Linux distribution. Once you have installed Linux (or any other Linux distribution) it is recommended to give its machine a static IP address. Next, open a terminal window and type commands as mentioned below. We would start by checking if portmap daemon is running:
# chkconfig --list portmap
If the output is something like this
portmap 0:off 1:off 2:off 3:on 4:on 5:on 6:off
runlevels 3, 4, and 5 are set to on. This means that at boot, for runlevels 3, 4 and 5, the portmap daemon is started automatically. If either 3, 4 or 5 are set to off, set them to on by running the following command:
chkconfig portmap on
Next check if NFS daemon is running.
# chkconfig --list nfs
again check if output is something like this:
nfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off
if 3,5,5 are set offt run
chkconfig nfs on
Now create a directory for shared storage as follows (I've used my own name for the directory. You're free to use the name you like).
mkdir /sandeepxen
Edit the /etc/exports file to add the line
/sandeepxen *(rw,no_root_squash,sync)
Finally restart both portmap and NFS daemon by running:
service portmap restart
service nfs restart
We now have NFS and hosts on same subnet; in next section we would see how to make each one aware of other.
Gluing everything
First we would join two XCP hosts into a pool and then set NFS as default storage for each of them. Two hosts that we are using in this setup would act as master and slave. Choose the host you want to act as slave (we assigned it an IP address of 192.168.5.55) and open console window in it and type the following commands:
xe pool-join master-address=192.168.5.60 master-username=root master-password=pppppp
Here 192.168.5.60 is the IP address of master host. Xen Cloud Platform hosts belong to an unnamed pool by default; run following commands to name ('xenpool' in our case) your pool:
xe pool-param-set name-label=xenpool uuid=76045ec4-91fa-3ab9-3e35-57f60e7e1d12
UUID is the universal unique identifier that can be obtained by pressing the tab key. If you are not comfortable with typing commands simply go to slave host and from the configuration window select 'Resource Pool Configuration' and enter credentials.
Second step is to add shared NFS storage to this pool. Again there are two ways of doing it: one from command line and other from the XCP interface. Just go to either the master or slave host and from interface select 'Storage and Disk Repositories>Create New Storage Repository' in next window, select 'NFS Storage' and enter credentials of NFS storage. Otherwise open up console on either of the two hosts and run:
xe sr-create content-type=user name-label=srsandeep shared=true device-config:server=192.168.5.64 device-config:serverpath=/sandeepxen
Here 'device-config:server' refers to the hostname of the NFS server and 'device-config:serverpath' refers to the path on the NFS server. Since shared is set to true, the shared storage will be automatically connected to every Xen Cloud Platform host in the pool and any Xen Cloud Platform hosts that subsequently join will also be connected to the storage. The UUID of the created storage repository will be printed on the screen. Find the UUID of the pool so that you can set default SR (shared resource) of the pool:
xe pool-list
xe pool-param-set uuid=76045ec4-91fa-3ab9-3e35-57f60e7e1d12 default-SR=333a424e-b2b7-9c02-d751-d7ba683a9b45
Both UUIDs used in the above example need to be replaced by corresponding UUIDs in your setup.
Creating VMs
Our cloud is ready and the next logical step is to create some VMs on top of them. XCP comes with a comprehensive set of VM templates, here we would create two VMs, one with Linux (Debian Lenny) and the other with Windows 7 OS. To create Linux VM, open console of host (where you want to run it) and run commands as mentioned below:
xe vm-install template=Debian\ Lenny\ 5.0 \ \(32-bit\) new-name-label=xendebian
This will give UUID of installed VM. Now to install OS simply type:
xe vm-param-set uuid=9c58ff09-f399-48f4-b649-a185fce4f747 other-config:install-repository=http://ftp.debian.org/debian
There are two ways you can start this VM, one is by running:
xe vm-start uuid=9c58ff09-f399-48f4-b649-a185fce4f747
or you can go to interface of XCP by typing 192.168.5.60 in the browser, enter credentials of master host. A window with 'Xapi objects' would pop up. In this window click 'VM' and then click on 'Start' button. To check the console, click on the 'Console' button and then click the corresponding VM (xendebian) and you can start installing the OS on the VM.
The other VM that we would create in this implementation is that with Windows 7. The steps remain the same. Start with creating a VM from a template by typing the following command on the host of your choice:
xe vm-install template=Windows\ 7\ \(32-bit\) new-name-label=xenwin7
We are installing Windows 7 from CD drive, therefore we need to add a CD drive to the created VM. Before you do this, find out the list of CD drives on the host:
xe cd-list
Note down the name of CD drive (IDE 0.0). Now add this drive to the VM:
xe vm-cd-add cd-name=IDE\0.0 device=3 vm=xenwin7
Now start the VM in the same manner as you started the one with Debian Lenny:
xe vm-start vm=xenwin7
What now have two VMs running different OS on a pool of resources. One can move from one host to the other. This can be accomplished by installing xentools or paravirtulization drivers.