| Linux Virtualisation with OpenVZ on CentOS |
| Written by Kwok Yao Chim | ||||||||||||||||||||
| Wednesday, 02 January 2008 00:00 | ||||||||||||||||||||
|
A few years ago I spoke to a friend of mine who blabbered on about Virtuozzo, which allowed him to run one server hardware with many instances of server operating systems on the one hardware. The topic blew way over my head! Recently these past few months I had some time to look into this "Virtualisation" technology and I was surprised that there were many open source versions of virtualisation. The one which really stood out was OpenVZ, this is developed by SWSoft/Parallels but further enhanced and commercialized in the form of Virtuozzo. OpenVZ allows you to host different flavours of Linux distros on one hardware node, take a look at the diagram below to see where it sits... More research on the web lead me to a really good website which I always frequent... www.howtoforge.org.
Within this article I will try and see if I can setup Virtualisation on CentOS 5.1 base OS system. We have five main parts to cover
1. RequirementsIf want to be able to run a lot of multiple VEs, you would probably need something along these specs:
2. Installing the Base OSI've chosen CentOS as my base OS because it is based on Redhat EL which means stability, reliability and performance. It is also easier and faster to configure since I'm more familiar with Redhat and Fedora plus the bonus of YUM (I love it).I used the network installation of CentOS 5.1 to get to the actual CentOS installation screen. If your familiar with the Redhat / Fedora / CentOS installation procedures then all you will need to know are these settings: Installation Type: Server Disk Partitioning: Automatic Create Partitions:
Network Config: Best to use static IP address and give a hostname of vznode0.yourdomain.com Firewall Config: No Firewall, and DISABLE SELinux Choose your language and choose your timezone Enter your ROOT password Next choose to install the bare OS, without any additional packages/applications Your installation will begin. After successful installation, update the the whole system. $ yum update -y And restart the system. $ shutdown -r now 3. Installing and Configuring OpenVZYou will need to download the OpenVZ repos in before you can start to install.
On most CentOS installations the GRUB boot loader is used as default, and after installing OpenVZ kernel, it will have automaitcally added and entry to the /boob/grub/grub.conf file and it should look like this:
Rename the title to OpenVZ so you know which one is which and remove last three parameters from the "kernel" line so it should now look like this:
and set it to boot off OpenVZ by editing the defult to 0 like this: default=0 We have to change some kernel parameters to allow OpenVZ to work properly. $ vi /etc/sysctl.conf in the file edit these lines:
Make sure SELinux is disabled if not then do so by editing /etc/sysconfig/selinux and add the line: SELINUX=disabled Enable conntracks for VE0, add the following line to /etc/modprobe.conf file: options ip_conntrack ip_conntrack_enable_ve0=1 Note: in kernels later than 2.6.8, connection tracking is enabled by default. Now reboot the machine. Now its time to install the utilities that allow you to create, control and destroy VPS. $ yum install vzctl vzquota Start the OpenVZ service. $ service vz start and also make it start on boot by going into ntsysv and marking it to startup. 4. OS TemplatesYou need to install some OS template utilites:$ yum install vzpkg vzyum vzrpm43-python vzrpm44-python After you have installed these utilies you can now start looking for some OS templates. $ yum search vztmpl OR $ yum list vztmpl* A list of available OS templates should be listed such as Fedora Core and CentOS. Choose and install an ostemplate. $ yum install vztmpl-centos-4.i386 OR $ yum install vztmpl-fedora-7.i386 now run the vzpkgcahe to update / download the latest OS template (this process may take some time. $ vzpkgcache The vzpkgcache commdn will update all the ostemplates as long as you have the necessary details (see part 6) You can also download some pre-created OS templates from OpenVZ.org http://openvz.org/download/template/cache/ and dump the OSname.tar.gz straight into /vz/template/cache/ , but be advised you will have to create your own OS template metadata in order to update it, more discussed later in the article. 5. Create and Control VEsNow lets begin to experiment by creating a VE.$ vzctl create 1020 --ostemplate centos-4-i386-default --ipadd 192.168.1.20 --hostname vps1020.domain.com The above command creates a VE with ID 1020 using centos-4 OS template and given an IP address and hostname (for more info $vzctl --help). You can add/change settings to the VE like this: $ vzctl set 1020 --nameserver 199.128.3.21 --userpasswd root:password --save Don't forget to add the --save parameter at the end Here are some commands to start, stop and destroy VE: $ vzctl start 1020 (this will start the VE) $ vzctl stop 1020 (this will stop the VE) $ vzctl destroy 1020 (this will destroy the VE and its saved settings and space) 6. Using Pre-Created Templates
|

