Recently, the use of virtualization in building server infrastructure is becoming more common. Flexibility, scalability, economy make this technology very promising. Now on the market there are a sufficient number of solutions, both proprietary and open source, allowing you to deploy virtual servers. One of these options I want to consider in this article.
Having played with the GUY virtualization platforms from Microsoft, VMware and Sun, I decided to try to do the same through the console. Having installed the ubuntu distribution for a long time I liked linux, I began to choose which implementation of virtual machines (VM) to stop at. There is an interesting
tablet on Wikipedia, although after seeing the official
help to ubuntu, I realized that it is better to start with KVM.
The installation procedure of the host server is generally standard, but there are some nuances. During the installation, I turned on LVM (as I understood, guest OSs can be placed on LVM volumes, which will give additional flexibility), and in the selection window of the pre-installed software I noted OpenSSH server and Virtual Machine host.

The host server is configured with a static ip 172.16.4.24, which can be seen later in the configurations listed.
After installing the host server, connect to it via ssh (with the same command from linux or putty / kitty from windows).
')
First you need to check if the server hardware supports hardware virtualization with the command
egrep '(vmx | svm)' / proc / cpuinfoIf the command output is not empty, then it supports.
Download into the home folder an iso-image of the distribution of the operating system, which later will be a guest. I have the same ubuntu-9.04-server-amd64.iso
Install the necessary packages:
sudo apt-get install kvm libvirt-bin python-virtinst bridge-utilsAdd a user who will drive virtuals (in the simplest case, this is the user we started during the installation of the system, and under which we perform all the described actions):
sudo adduser $ USER libvirtdAfter this, it is better to rebuy.
Check how KVM was established with the command:
virsh -c qemu: /// system list --allThe following should appear in the console:
az @ vsrvs: ~ $ virsh -c qemu: /// system list --all
Connecting to uri: qemu: /// system
Id Name State
----------------------------------if so, continue.
In order for virtual servers to work in our real local area network on the host machine, we create a network bridge. To do this, edit the file / etc / network / interfaces
So he looked before the modification:
# This file is the network interfaces available on your system
# and how to activate them. For more information, see interfaces (5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 172.16.4.24
netmask 255.255.255.192
network 172.16.4.0
broadcast 172.16.4.63
gateway 172.16.4.1
So after:
# This file is the network interfaces available on your system
# and how to activate them. For more information, see interfaces (5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet manual
auto br0
iface br0 inet static
address 172.16.4.24
netmask 255.255.255.192
network 172.16.4.0
broadcast 172.16.4.63
gateway 172.16.4.1
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off
Next, proceed to the installation of VM:
sudo virt-install -n vsrv1 -r 384 -f vsrv1.img -s 10 -c ubuntu-9.04-server-amd64.iso --accelerate --os-type = linux --os-variant = generic26 -v - vnc -w bridge: br0Where:
-n vsrv1 - VM name;
-r 384 - allocated amount of RAM for it;
-f vsrv1.img - file that is a virtual hard disk for the guest OS;
-s 10 - volume of this disk in gigabytes;
-c ubuntu-9.04-server-amd64.iso - the cd image of the guest OS distribution, which is connected as a virtual cdrom;
--accelerate --os-type = linux --os-variant = generic26 -v - we accelerate, optimize VM for a specific guest OS and enable hardware virtualization capabilities;
--vnc - we start a vnc-server for VM;
-w bridge: br0 - specify the use of a network bridge.
If, after running this command, no errors occurred, but the following is displayed:
Starting install ...
Creating domain ... 0 B 00:01
/usr/lib/python2.6/dist-packages/virtinst/Guest.py:1086: DeprecationWarning: integer argument expected, got float
for ignore in range (1, (5 / .25)): # 5 seconds, .25 second sleeps
Unable to connect to graphical console: virt-viewer not installed. Please install the 'virt-viewer' package.
Domain installation still in progress. You can reconnect to
complete the installation process.Everything is fine, the virtual machine has started, which can be checked with the command:
virsh -c qemu: /// system list --allTherefore, we violate the installation of the guest OS.
First you need to connect to the vnc server that displays the VM screen. I did it from WinXP, although from almost any linux distribution, it is done in a similar way.
Install (if you did not install at the very beginning, but set up a server locally) ssh-client, for example,
kitty (modified putty version). Run, customize:
- In the Session tab, the Host Name (or IP address) is the address of our host server (in my case, 172.16.4.24).
- In the Windows Translation tab, select UTF-8.
- In the Connection-SSH-Tunnels tab - fill in the fields Source port 59000, Destination localhost: 5900, click Add. The following entry should appear:

- We press Open and we must connect via SSH to the host server. At the same time, we will redirect the port 5900 of the host server (port of the vnc server) to our local 59000 port.
Note. When you start another VM, the vnc server port will increase by 1, so in order to see its screen, you need to redirect the port 5901 of the host server to, for example, port 59001.
Install the vnc client, for example
UltraVNC , run the UltraVNC Viewer and connect to localhost: 59000. If everything is done correctly, then we will see the screen of our VM running the guest OS installer.
Install the guest OS.
So it starts to load after installation:

After installing and configuring the guest OS, the VM can be cloned with the command
sudo virt-clone -o vsrv1 -n vsrv2 -f vsrv2.img --connect = qemu: /// systemUPD: After cloning, in order for the network interface to work, you must delete the /etc/udev/rules.d/70-persistent-net.rules file on the clone and at the same time change the name of the server in / etc / hostname and in / etc / hosts new.
TIP:
Commands to control VM:
virsh -c qemu:///system help
virsh -c qemu:///system list --all
virsh -c qemu:///system start vsrv1
vsrv1 virsh -c qemu:///system shutdown vsrv1
virsh -c qemu:///system destroy vsrv1
virsh -c qemu:///system undefine vsrv1
virsh -c qemu:///system help
virsh -c qemu:///system list --all
virsh -c qemu:///system start vsrv1
vsrv1 virsh -c qemu:///system shutdown vsrv1
virsh -c qemu:///system destroy vsrv1
virsh -c qemu:///system undefine vsrv1
virsh -c qemu:///system help
virsh -c qemu:///system list --all
virsh -c qemu:///system start vsrv1
vsrv1 virsh -c qemu:///system shutdown vsrv1
virsh -c qemu:///system destroy vsrv1
virsh -c qemu:///system undefine vsrv1
virsh -c qemu:///system help
virsh -c qemu:///system list --all
virsh -c qemu:///system start vsrv1
vsrv1 virsh -c qemu:///system shutdown vsrv1
virsh -c qemu:///system destroy vsrv1
virsh -c qemu:///system undefine vsrv1
virsh -c qemu:///system help
virsh -c qemu:///system list --all
virsh -c qemu:///system start vsrv1
vsrv1 virsh -c qemu:///system shutdown vsrv1
virsh -c qemu:///system destroy vsrv1
virsh -c qemu:///system undefine vsrv1
virsh -c qemu:///system help
virsh -c qemu:///system list --all
virsh -c qemu:///system start vsrv1
vsrv1 virsh -c qemu:///system shutdown vsrv1
virsh -c qemu:///system destroy vsrv1
virsh -c qemu:///system undefine vsrv1
virsh -c qemu:///system help
virsh -c qemu:///system list --all
virsh -c qemu:///system start vsrv1
vsrv1 virsh -c qemu:///system shutdown vsrv1
virsh -c qemu:///system destroy vsrv1
virsh -c qemu:///system undefine vsrv1
Used materials:
- man-s of the programs presented
- https://help.ubuntu.com/9.04/serverguide/C/virtualization.html
- http://www.howtoforge.com/virtualization-with-kvm-on-ubuntu-9.04