
What's OpenVZ ?
"OpenVZ is container-based virtualization for Linux. OpenVZ creates multiple secure, isolated containers (otherwise known as VEs or VPSs) on a single physical server enabling better server utilization and ensuring that applications do not conflict. Each container performs and executes exactly like a stand-alone server; a container can be rebooted independently and have root access, users, IP addresses, memory, processes, files, applications, system libraries and configuration files."
How to install it ?
Pretty easy!
With Yum :
First of all, update yum's repositories, like this :
# cd /etc/yum.repos.d
# wget http://download.openvz.org/openvz.repo
# rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ
Next, install OpenVZ Kernel :
# yum install ovzkernel[-flavor]
(The "[-flavor]" is the "kernel-type" for each hardware you have, for example :)
(yum install ovzkernel[-UP]) <- This is for Uniprocessor computers only!
(yum install ovzkernel[-SMP]) <- This is for symmetric multiprocessor (Core2Duo .. etc ..)
(yum install ovzkernel[-enterprise/ent]) <- Big servers only, up to 64gb of memory and from 20 to 30 containers ...
Ok, then, we'll have the OpenVZ installed, we need now to configure the boot loader :
Like this :
# vi /boot/grub/grub.conf
The file will look like this :
title CentOS (2.6.8-022stab029.1)
root (hd0,0)
kernel /vmlinuz-2.6.8-022stab029.1 ro root=/dev/sda5 quiet rhgb vga=0x31B
initrd /initrd-2.6.8-022stab029.1.img
Probably, you've got 3 "like" these in your file, it should be the first one you should edit, like this :
title OpenVZ (2.6.8-022stab029.1)
root (hd0,0)
kernel /vmlinuz-2.6.8-022stab029.1 ro root=/dev/sda5
initrd /initrd-2.6.8-022stab029.1.img
Remove the "rhgb" and "vga", just leave the "root=...".
Change de "default=1" to "0", so everytime it boots, it boots on the OpenVZ kernel.
Now, we'll edit the Kernel parameters:
# vi /etc/sysctl.conf
Add/Change this values to your configuration file :
net.ipv4.ip_forward = 1
net.ipv6.conf.default.forwarding = 1
net.ipv6.conf.all.forwarding = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.all.rp_filter = 1
kernel.sysrq = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
Now, let's shutdown our SELINUX:
# vi /etc/sysconfig/selinux
SELINUX=disabled
Now, just to make sure we are good at the job we'll just enable conntracks, like this :
# vi /etc/modprobe.conf
and add this -> options ip_conntrack ip_conntrack_enable_ve0=1
Ok, almost there!
Just a few awsome utils we should install ...
# yum install vzctl vzquota
And that's it ... reboot the system and we have OpenVZ working ...!
Now ... Creating the containers ...
# vzctl create VEID_NUMBER --ostemplate centos-4-i386-default
# vzctl set VEID_NUMBER --userpasswd root:YOURPASSWORD --save
# vzctl set VEID_NUMBER --hostname yourservername.mydomain.com --save
# vzctl set VEID_NUMBER --ipadd IP_ADDRESS_HERE --save
The VEID_NUMBER is the number of your machine, the way you'll recognize it!
# vzctl start VEID_NUMBER
And that's it! We have a virtual machine!
Your container's data is stored here : /vz/private/VEID_NUMBER
And the configuration file here : /etc/vz/conf/VEID_NUMBER.conf
Explore it, the utilities too, vzquota and vzctl.
Labels: centos5, containers, openvz, openvz on centos how to, virtual machines