NOTE: all the commands in this exercise are run as the root user. If you are logged in as a regular user, use sudo -s
to get a root shell.
$ sudo -s
#
Before we create and install VMs, we need to change default settings in the cluster (this should have been done before, but we're doing it to be safe).
Do this on the MASTER node:
# gnt-cluster modify -H kvm:kernel_path=,initrd_path=,vnc_bind_address=0.0.0.0
We are going to install our VMs using debootstrap - we don't feel like spending time installing an OS using an ISO image: it takes too long, and that's not what we would be doing in production if we had many customers or users asking for VMs all the time.
First, we need to adjust a few things.
There is an old version of the package "ganeti-instance-debootstrap" in Debian wheezy, but a newer one in wheezy-backports (version 0.14 at the time of writing). So check that you have the newer version:
# apt-get install ganeti-instance-debootstrap/wheezy-backports
You will need to do this on all nodes in the cluster, because instances can be created on any node and you want them to be consistent.
Test that the "instance OS" type is recognized: on the master node,
# gnt-os list
This should show: debootstrap+default
Ganeti provides some sample "hooks" you can use to customize the VMs you create.
Normally you would do this once on the master node and then use gnt-cluster copyfile
to copy the files to the other nodes, but for this exercise, you can each do it on your own host.
For example, let's say we want all our instances to have a root password of our choosing. To do this we need a small shell script, and a data file containing the desired password.
First, we need to copy the script into the 'hooks' directory:
# cd /etc/ganeti/instance-debootstrap/hooks
# cp /usr/share/doc/ganeti-instance-debootstrap/examples/defaultpasswords .
# chmod +x defaultpasswords
(Notice the "." which means "into the current directory")
And now we need to give it a password file:
# mkdir confdata
# cd confdata
# cp /usr/share/doc/ganeti-instance-debootstrap/examples/confdata/defaultpasswords .
# chmod 600 defaultpasswords
Edit this file "defaultpasswords" and change the default password from s3cr3t
to the password we use in class. This file should be just one line:
root:XXXXXX
where XXXXXX is the password.
We're almost ready to build our VM. Before, we need to set a few parameters so it builds the version and architecture we want.
Have a look in the file /etc/default/ganeti-instance-debootstrap
, which contains the default debootstrap
settings for Ganeti.
You can see various options that we covered before in the scripted installs:
ARCH
, SUITE
and EXTRA_PKGS
in particular, control which version of the OS and architecture, as well as which package, get installed.
We need to override (change) two of these parameters: ARCH
and EXTRA_PKGS
, but we're not going to modify this file.
Instead, we'll edit the file /etc/ganeti/instance-debootstrap/variants/default.conf
, which allows us to make the change without touching the installed version. Like this, when Ganeti is upgraded, your settings file isn't overwritten.
Therefore:
# editor /etc/ganeti/instance-debootstrap/variants/default.conf
And add the following lines:
ARCH="amd64"
EXTRA_PKGS="acpi-support-base,console-tools,udev,linux-image-amd64,sudo,vim,grub-pc,openssh-server"
PROXY="http://apt.ws.nsrc.org:3142/"
Summary:
As with the previous exercise: each pair of people can create a VM called
debianX
and place it on your nodehostX
, but you will need to be logged into the MASTER node of your cluster to issue these commands
# gnt-instance add -t plain -o debootstrap+default \
--disk 0:size=4G -B minmem=256M,maxmem=512M \
-n hostX.ws.nsrc.org \
--no-name-check --no-ip-check \
debianX
Note: if you are only going to have one disk, instead of writing --disk 0:size=4G
, you could simply write -s 4G
.
The build is going to take a while the first time - it should fetch most packages from the local cache, which should speed things up.
It needs to fetch packages just like for debootstrap in the previous labs. Be patient...
Sat Jan 18 09:52:14 2014 * disk 0, size 4.0G
Sat Jan 18 09:52:14 2014 * creating instance disks...
Sat Jan 18 09:52:15 2014 adding instance debianX to cluster config
Sat Jan 18 09:52:15 2014 - INFO: Waiting for instance debianX to sync disks
Sat Jan 18 09:52:15 2014 - INFO: Instance debianX's disks are in sync
Sat Jan 18 09:52:15 2014 * running the instance OS create scripts...
Sat Jan 18 10:02:53 2014 * starting instance...
Ok, the build is done! The good thing is, in the future, Ganeti has cached the image of your host (by default, for two weeks), so if you install more VMs with the same command, it will only take a few seconds to create and start the machine 1.
Unfortunately, there is currently a problem currently with this way of installing VMs on Ganeti.
Your VM will not come up, and KVM will hang with 99% cpu:
# top
...
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
5981 root 20 0 765m 11m 3144 S 98.8 1.1 6:05.41 kvm
If you attach a VNC console you will see it stuck at "Booting from Hard Disk...". This is because the grub bootloader wasn't installed in the instance 2.
Let's fix it.
Bring down the host (immediate shutdown):
# gnt-instance shutdown --timeout=0 debianX
Waiting for job 211 for debianX ...
We're going to boot the instance using the kernel from the Host, just temporarily, so we can fix the bug:
# gnt-instance start \
-H kernel_path=/vmlinuz,initrd_path=/initrd.img,kernel_args="ro single" \
debianX
Wait a few seconds, then start a serial console:
# gnt-instance console debianX
Press ENTER
You should see:
Login incorrect.
Give root password for maintenance
(or type Control-D to continue):
Here, enter the password we set for the root (class password). If all goes well, you are in:
root@debianX:~#
Now we can fix the GRUB bootloader on the VM:
Note: you are typing this in the console, NOT ON YOUR HOST!
Update the GRUB config and install the bootloader in the boot sector of our VM disk:
# update-grub
Generating grub.cfg ...
cat: /boot/grub/video.lst: No such file or directory
Found linux image: /boot/vmlinuz-3.2.0-4-amd64
Found initrd image: /boot/initrd.img-3.2.0-4-amd64
done
# grub-install /dev/vda
Installation finished. No error reported.
Exit the serial console by pressing ^]
(control + right square bracket)
Back at the master node prompt, shutdown and restart the guest:
# gnt-instance reboot --shutdown-timeout=30 debianX
Wait until the prompt returns. If all goes well, you should now be able to get a console on your instance, either using gnt-instance console debianX
or using VNC 3
Our machine still doesn't have any network configuration - we will deal with it now.
One thing remains to be done - our machines still don't have any network connectivity.
Log in using VNC or serial to the console of your VM - if you're in doubt which node it's running on, use
# gnt-instance list -o +network_port
Once logged in to the guest:
# ifconfig eth0
Notice there isn't any IP.
Remember, that this VM is attached to br-svc
from the point of view of the HOST. That network's address and subnet is 10.10.255.0/24
.
You will give an IP address to your VM, from the following table:
Cluster/Group | IP address |
---|---|
Group 1 | 10.10.255.5 6 7 or 8 |
Group 2 | 10.10.255.21 22 23 or 24 |
Group 3 | 10.10.255.37 38 39 or 40 |
Group 4 | 10.10.255.53 54 55 or 56 |
Group 5 | 10.10.255.69 70 71 or 72 |
Group 6 | 10.10.255.85 86 87 or 88 |
Group 7 | 10.10.255.101 102 103 or 104 |
We need to edit /etc/network/interfaces
and give your VM an IP address from the table above. Do this now, and it should end up looking like this:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.255.XX
netmask 255.255.255.0
gateway 10.10.255.254
Replace XX
with the IP from the table above.
Finally, modify /etc/resolv.conf
and set the nameserver as follows:
nameserver 10.10.0.241
You can now bring up the interface:
# ifup eth0
Test that connectivity works, by pinging the class webserver:
# ping www.ws.nsrc.org
Does it work ?
Let's make sure we are using the in-class package cache:
Edit the file /etc/apt/apt.conf
and add this line:
Acquire::http::Proxy "http://apt.ws.nsrc.org:3142/";
Now we can install OpenSSH 4
# apt-get install openssh-server
You should now be able to log in to your VM as root
, on the IP address you gave it earlier (10.10.255.X).
Congratulations! The remainder of this worksheet is extra information in case you finish early, or which you can review at your leisure later
Here's an example of how to automatically customize your OS installation. Let's say we want to install /etc/resolv.conf
with particular contents.
Change to the hooks directory:
# cd /etc/ganeti/instance-debootstrap/hooks
Create a new file in this directory called resolv
with the following contents:
#!/bin/bash
if [ ! -d "$TARGET/etc" ]; then
echo "Missing target etc directory"
exit 1
fi
cat <<EOS >"$TARGET/etc/resolv.conf"
nameserver 10.10.0.241
nameserver 10.10.0.242
search ws.nsrc.org
EOS
Make it executable:
# chmod +x resolv
Now the next time you install a debootstrap image, it should have this customization applied automatically.
You can also create other Debian-derived OSes this way. Here is how to install Ubuntu 12.04 ("precise")
On the master node, create `/etc/ganeti/instance-debootstrap/variants/precise.conf'
MIRROR="http://archive.ubuntu.com/ubuntu/"
PROXY="http://apt.ws.nsrc.org:3142/"
SUITE="precise"
EXTRA_PKGS="acpid,console-tools,udev,linux-image-virtual,openssh-server"
COMPONENTS="main,restricted,universe,multiverse"
ARCH="amd64"
Update /etc/ganeti/instance-debootstrap/variants.list
so it looks like this:
default
precise
Distribute these files to the other nodes:
# gnt-cluster copyfile /etc/ganeti/instance-debootstrap/variants/precise.conf
# gnt-cluster copyfile /etc/ganeti/instance-debootstrap/variants.list
# gnt-os list
Now you can create an instance of Ubuntu Precise using the same gnt-instance add
command as before but with -o debootstrap+precise
as the operating system selection.
If you are curious: ls -l /var/cache/ganeti-instance-debootstrap/
↩
There is a hook for doing this, but it's broken. There is a modified version you can download - it only works when creating plain (non-drbd) images, but you can convert them to drbd afterwards. This is likely to be fixed with the OS installation redesign↩
Reminder: gnt-instance list -o name,pnode,network_port
then connect with VNC to the host & port listed ~↩
Note: would it not have been possible to add openssh-server
to the EXTRA_PKGS
section of the Ganeti debootstrap earlier ? Then we wouldn't need to install openssh manually on every instance we create.↩