Showing posts with label OpenVZ. Show all posts
Showing posts with label OpenVZ. Show all posts

Tuesday, December 20, 2011

Installing OpenVZ on Amazon EC2

— SkyHi @ Tuesday, December 20, 2011
Imagine, that your system is pretty complicated and consists of a number of components, each deployed into separate machine.  For development & testing needs it’s always too costly to keep up & running all these machines.  It’s not that as easy to make modification into your system structure, i.e. adding new machines with different roles, etc.
One solution is a to virtualize all your stuff & isolate environments of each component.  One easy way would be to buy a hardware & setup hardware virtualization such as XEN for instance, but there is more popular approach — using Amazon EC2 cloud services.
In this post I’m going to show you how to setup OpenVZ virtualization on Amazon EC2 node (which, actually itself is virtualized XEN node)
We’re going to use as a base a CentOS 5.6 Amazon image with pv-grub enabled (this is required to be able to boot into custom kernel)
Ok, from the AWS console start CentOS 5.6/x64  (centos-5.6-64bit-ebs-pvgrub / ami-a14f1ce4), obtain public DNS name & make sure that default ssh 22 port is enabled:

ssh -i ~/aws_ssh.key root@ec2-50-18-60-65.us-west-1.compute.amazonaws.com

Install OpenVZ & some dependencies


yum -y install gcc.x86_64 gcc-c++.x86_64 java-1.6.0-openjdk iptables openssl-devel zlib-devel pkgconfig glib2-devel

#Open VZ, Install XEN-compatible kernel!
wget -O /etc/yum.repos.d/openvz.repo http://download.openvz.org/openvz.repo
rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ
yum --enablerepo=openvz-kernel-rhel5 -y install ovzkernel-xen.x86_64 ovzkernel-xen-devel.x86_64 vzctl.x86_64 vzquota.x86_64

Override some kernel parameters


echo "net.ipv4.ip_forward = 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
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.conf.default.forwarding=1
net.ipv4.conf.default.accept_source_route = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296" > /etc/sysctl.conf
# reload from disk
sysctl -p

#Substitute default kernel by OpenVZ
sed -i 's/kernel/ovzkernel/' /etc/sysconfig/kernel

Install ntpd

This will help to sync time between all virtual machines.
yum install -y ntp.x86_64
/usr/sbin/ntpdate 0.rhel.pool.ntp.org europe.pool.ntp.org
# start on next boot
chkconfig ntpd on

Enable rpmforge repo

Chances are pretty high that you’ll want something from this repo (latest git for example), so you’d better install it now.
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
wget -O /tmp/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
rpm -Uvh /tmp/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
yum -y install --enablerepo=rpmforge git.x86_64

Setup firewall

#Setup firewall
echo "*filter" > /etc/sysconfig/iptables
echo "COMMIT" >> /etc/sysconfig/iptables

Install OpenVZ kernel to boot by default

For some reason, yum installed does not adds OpenVZ kernel into grub bootlist, therefore we’re doing it manually:
#!/bin/bash

#detect newly installed OpenVZ kernel
VMLINUZ_XEN=`ls /boot/ | grep -i "^vmlinuz" | grep -i "stab"`
INITRD_XEN=`ls /boot/ | grep -i "^initrd" | grep -i "stab"`

if [ $VMLINUZ_XEN ]; then
echo "
title CentOS-openvz-xen
  root (hd0)
  kernel /boot/$VMLINUZ_XEN root=/dev/sda1
  initrd /boot/$INITRD_XEN" >> /boot/grub/menu.lst

#Make sure we'll boot into newly installed XEN kernel, which have INDEX=1
sed -i 's/default=0/default=1/' /boot/grub/menu.lst
fi

Check your /boot/grub/menu.lst, it should look like following:
default=1
title centos5.6
  root (hd0)
  kernel /boot/vmlinuz-2.6.18-238.5.1.el5xen root=/dev/sda1
  initrd /boot/initrd-2.6.18-238.5.1.el5xen.img

title CentOS-openvz-xen
  root (hd0)
  kernel /boot/vmlinuz-2.6.18-274.3.1.el5.028stab094.3xen root=/dev/sda1
  initrd /boot/initrd-2.6.18-274.3.1.el5.028stab094.3xen.img

Reboot and then login again to check that you’re on OpenVZ kernel:

ssh -i ~/aws_ssh.key root@ec2-204-236-152-176.us-west-1.compute.amazonaws.com
Last login: Tue Nov 29 05:34:50 2011 from 94.45.135.130
[root@ip-10-176-46-67 ~]# uname -a
Linux ip-10-176-46-67 2.6.18-274.7.1.el5.028stab095.1xen #1 SMP Mon Oct 24 21:00:35 MSD 2011 x86_64 x86_64 x86_64 GNU/Linux

Download & install OpenVZ CentOS5 template:

wget http://download.openvz.org/template/precreated/centos-5-x86_64.tar.gz

#Symlink OpenVZ CentOS template
[ -d /vz/template/cache ] || mkdir -p /vz/template/cache
ln -s /root/centos-5-x86_64.tar.gz /vz/template/cache

Create your first OpenVZ container(VM)

vzctl create 101 --ostemplate centos-5-x86_64 > /dev/null
vzctl set 101 --ipadd 10.0.102.101 --save > /dev/null
vzctl set 101 --nameserver 8.8.8.8 --save > /dev/null
vzctl set 101 --name "APP1" --save > /dev/null
vzctl set 101 --onboot yes --save > /dev/null
Try to login into APP1 shell:
vzctl enter 101
At this point, if you was able to create APP1 container, you can setup other components of your system — Database, Cache server, whatever you want.







REFERENCES
http://webapp.org.ua/sysadmin/installing-openvz-on-amazon-ec2/

Wednesday, September 22, 2010

How to install OpenVZ and Vtonf control panel in centos

— SkyHi @ Wednesday, September 22, 2010
OpenVZ is an operating system-level virtualization technology based on the Linux kernel and operating system. OpenVZ allows a physical server to run multiple isolated operating systemopenvz instances, known as containers, Virtual Private Servers (VPSs), or Virtual Environments (VEs). It is similar to FreeBSD Jails and Solaris Zones.
As compared to virtual machines such as VMware and paravirtualization technologies like Xen, OpenVZ is limited in that it requires both the host and guest OS to be Linux (although Linux distributions can be different in different containers). However, OpenVZ claims a performance advantage; according to its website, there is only a 1–3% performance penalty for OpenVZ
as compared to using a standalone server. One independent performance evaluation confirms this. Another shows more significant performance penaltie s  depending on the metric used.
In this tutorial will show you how to install OpenVZ in CentOS and how to install Vtonf, another web interface for OpenVZ

I- Install OpenVZ:

1-First add openVZ repository to Centos:
Open terminal and copy the commands:
wget http://download.openvz.org/openvz.reporpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ
cp openvz.repo /etc.recpo.d 

2-Install  openvz  kernel:


yum install ovzkernel

3- edit the /etc/systcl.conf

Open /etc/systcl.conf  and add these lines:
net.ipv4.ip_forward = 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 

4- Disable Selinux

To disable Selinux, first open the config file
vi  /etc/selinux/config  
Then look for the line bellow and make sure that is disabled
SELINUX=disabled

5- Install openvz tools and plugins
yum install vzctl vzquota

6- Restart openv Services:
service vz restart

II - Create Virtual OS /Containers

we have Openvz installed. Now is time to create a Virtual os /containers, for that we need to download an OS template.
An OS template cache is an OS template installed into a container and then packed into a gzipped tarball. Using such a cache, a new container can be created in a matter of minutes, if not seconds.
In the example bellow we used Slackware template, for other templates please visit this link.
First cd the cache folder
cd   /vz/template/cache 

and download the template :

[root@localhost cache]# wget  http://download.openvz.org/template/precreated/contrib/slackware-13.0-i386-minimal.tar.gz
--2010-06-27 16:55:33--  http://download.openvz.org/template/precreated/contrib/slackware-13.0-i386-minimal.tar.gz
Resolving download.openvz.org... 64.131.90.11
Connecting to download.openvz.org|64.131.90.11|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 39641862 (38M) [application/x-gzip]
Saving to: `slackware-13.0-i386-minimal.tar.gz'

100%[===============================================================>] 39,641,862  4.48M/s   in 14s     

2010-06-27 16:55:47 (2.71 MB/s) - `slackware-13.0-i386-minimal.tar.gz' saved [39641862/39641862]

 

  • Lets create the VPS 102 now

vzctl  create     102    --ostemplate    slackware-13.0-i386-minimal     --config   basic 
Output:
Creating container private area (slackware-13.0-i386-minimal)
Performing postcreate actions
Container private area was created


  • Make this VM(virtual machine start on boot)

[root@localhost cache]# vzctl set 102  --onboot yes --saveSaved parameters for CT 102make  a  Hostname  for  The  machien:vzctl set 102 --hostname  Hackers.example.com --saveGive  Ip  adress   192.168.0.130  to  the  machine:
[root@localhost cache]#  vzctl set 102 --ipadd 192.168.0.130  --saveSaved parameters for CT 102
[root@localhost cache]#
  • Now start the VM machine 102
  vzctl start
Output
102 Starting container ...Container is mountedAdding IP address(es): 192.168.0.130Setting CPU units: 1000Set hostname: Hackers.example.comContainer start in progress...
  • Make a root password for the machine:
  vzctl exec 102 passwd 
Output:
New password: Zz123456
Re-enter new password: Zz123456
Changing password for root
Enter the new password (minimum of 5, maximum of 127 characters)Please use a combination of upper and lower case letters and numbers.Password changed


  • Enter The slackware machine 102
  vzctl enter  102 
Output:
entered into CT 102
root@Hackers:/# cat /etc/slackware-version
Slackware 13.0.0.0.0
Stop of start or Exit
More commands :
To restart  use : vzctl restart To stop  use :   vzctl stop
to destroy the   vm machine user  : vzctl destro 102
For more commands use :vzctl -help

III- Install Vtonf a web interface manager for OpenVZ

VTONF is a Virtual private server (VPS) control panel. It is designed to perform VPS operations in a GNU/Linux server having OpenVZ virtualization technology. VTONF is a Free software distributed under GPL license.
  • Install  Vtonf :
Open terminal and type the commands bellow ( Don`t forget to change the version of vtonf  vtonfinstaller.x.x-beta1.tar.gz to the current version you are trying to install)
cd /tmp
 wget  http://mesh.dl.sourceforge.net/sourceforge/vtonf/vtonfinstaller.x.x-beta1.tar.gz
 tar xvfz vtonfinstaller.1.0-beta1.tar.gz
 cd vtonfinstaller.x.x-beta1
 ./install
When Vtonf control panel installation is completed, you can login to the control panel using the following informations:
http://192.168.0.109:8001/
 Login Name : admin
 Password : admin











REFERENCES
http://www.unixmen.com/linux-tutorials/1024-how-to-install-openvz-and-vtonf-control-panel-in-centos-

Wednesday, February 10, 2010

KVM VPS vs OpenVZ/Virtuozzo vs XEN VPS comparative chart.

— SkyHi @ Wednesday, February 10, 2010

PerfoHost Virtual Private Servers powered by Kernel Based Virtual Machine

Quote from linux-kvm.org: "KVM (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko. KVM also requires a modified QEMU although work is underway to get the required changes upstream.

Using KVM, one can run multiple virtual machines running unmodified Linux or Windows images. Each virtual machine has private virtualized hardware: a network card, disk, etc."

 

Main features of KVM VPS are:

  • RAM and disk are not shared with other virtual machines on the main server. This makes your KVM VPS even more stable and excludes a possibility of overselling.

  • KVM VPS allows you to choose custom kernels as well as custom kernel modules for your KVM VPS guest OS.

  • You may set up a VPN server in KVM VPS (PPTP, OpenVPN, IPSec).

  • Full guest OS support. Allows you to install Windows, Linux, BSD, OpenSolaris, etc.

  • Wirth KVM VPS you may run a Window manger such as Gnome or KDE and and iteract with it using VNC.


KVM VPS vs OpenVZ/Virtuozzo vs Xen

  KVM VPS OpenVZ / Virtuozzo Xen
Dedicated filesystem + limited support +
Dedicated RAM + – +
Dedicated server like isolation + – +
PPTP VPN + – +
OpenVPN + – +
IPSec VPN + – limited support
Firewall Configuration + limited support +
NFS + – –
Independent kernel + – limited support
Independent kernel modules + – limited support
Unlimited sokets and processes + – –
Full guest OS support (Windows, Linux, BSD, OpenSolaris, etc.) + – limited support
Full window manager (GNOME, KDE, etc.) + – limited support
VNC connection + – limited support



KVM VPS with PerfoHost

Performance & Flexibility & Security & Scalability

Selecting the PerfoHost KVM VPS for your hosting platform gives you more of everything. As a scalable, managed solution, the KVM VPS decreases your time to market, allows you to focus on your core competencies, and frees up limited resources.

With the KVM VPS you get a hosting environment with your own Unix or Windows virtual machine. Each VPS is a private and protected area that operates as an independent server.

A VPS accommodates the present hosting needs of your business, but also provides an easy upgrade path to meet future requirements. Even if you already have a Web site, moving to a VPS can improve the online presence of your business by hosting your company e-mail or intranet.


Unix KVM VPS plan Deposit Box KVM VPS Developer KVM VPS Enterprise KVM VPS Master KVM VPS
Type virtual server virtual server virtual server virtual server
Disk space, Mb 10000Mb 250000Mb 500000Mb 750000Mb
Guaranteed RAM 256+ MB 512+ MB 768+ MB 1024+ MB
Web sites/ Domains (yourname.com) 1 Unlimited Unlimited Unlimited
SSH root access + + + +
Static IP address (IPv4) + + + +
Unlimited static IPv6 IP addresses + + + +
Free increment (5 days) backups (one free restore per month) + + + +
Monthly data transfer, Gb Unlimited Unlimited Unlimited Unlimited
Apache processes per day 150000 300000 450000 600000
Web Visitors Unlimited Unlimited Unlimited Unlimited
Cost per month $25.55 $45.55 $65.55 $85.55
Cost per year (2 months free) $255.55 $455.55 $655.55 $855.55
  Order now! Order now! Order now! Order now!

REFERENCE
http://perfohost.com/kvm.vps.html


Xen, Virtuozzo, Vserver, and OpenVZ

— SkyHi @ Wednesday, February 10, 2010

Since 2bits moved into using VPS (Virtual Private Servers) when Xen became available we did not have to directly use other technologies, such as Virtuozzo, OpenVZ (free version of Virtuozzo), or the older User Mode Linux.

However, two recent cases proved what we have suspected for a long time: that indeed Xen is superior to competing technologies when it comes to performance.

In one case, a client contacted us for tuning a slow system. The system gets some 75,000 page views per day on weekdays, and page generation times were 2 seconds or more, and was running on a Virtuozzo host.

2bits cloned the site on a test machine ran timing benchmarks, and found that it peformed faster on the test machine. Then we cut off the external traffic from the live machine using Apache LIMIT directives, and found that page generation times have not improved. Our recommendation to the client was to move to another host. They chose to go for a dedicated server, and that solved their problems.

In a second case, someone posted a request in the forums, where he was getting page generation times of 2+ seconds, while the query components were only 700-800 ms. Upon checking the output of phpinfo, it was apparent that they used OpenVZ. The user was trusting enough to send over a copy of the site's database and files, and we installed it on a Xen VPS.

The results were page execution time of 300 to 600 ms on Xen, as opposed to 2000+ on OpenVZ.

So, the advice is: for Drupal hosting best performance: use Xen if you want a VPS. Avoid Virtuozzo and OpenVZ.

We vote for Xen we are

We vote for Xen we are running small VPS hosting company and I can say xen is the best virtuazliation ever we added http://hostbillapp.com to vps provisioning and we are reall happy for that.

This whole thing is rubbish -

This whole thing is rubbish - show benchmarks on the same hardware with the same loads.

So far the only empirical evidence presented is the HP study which says OpenVZ is faster.

I am not pro MS nor pro VZ, but in this case you have not presented anything other than circumstantial claims that Xen is better. Justify it.

Uhm you write about performance and don't mention hardware?

I've enjoyed reading other parts of this sites, but this particular article is utterly pointless because you gave zero indication what kind of hardware these servers were on.
If you compare an OpenVZ machine that shares a slow single core CPU between 10 VMs to a dedicated server with two quad cores of course the VZ is gonna loose.
Since you didn't give ANY information about hardware we have to assume that the differences you noted are entirely down to having stronger hardware in the Xen and the dedicated servers :(

Use the gearbox

Xen just can not be faster than OpenVZ/Virtuozzo, that's nonsense.

Apparently in those cases you haven't configured OpenVZ/Virtuozzo resource management properly, thus applications experienced resource shortages which is the reason of the slowdown.

Let me give you a clear example: it's like driving a sport car with manual gearbox, using only the low gear. The problem of slow car is you have to upper the gear while you increase the speed. Instead, you use a truck, and now claim that the truck is faster.

This article should help: wiki.openvz.org/Resource shortage

Your comment based on zero

Your comment based on zero personal experience with Xen and based totally on your biased assumption is the nonsense here, not that Xen is superior which it is. Nothing is superior no matter what hardware you are running than running Linux on Xen. Hardware issue is only brought up by Microsoft and VZ lovers who still hang on to old crap without even personally testing new stuff coming out which are far superior. And you point people to a crap written by VZ.org? That's absolutely laughable. Read again, Linux and Xen far superior to Microsoft and VZ.

Well, at the risk of

Well, at the risk of flogging a dead horse, I think any discussion about virutalization comparisons should reference:

http://wiki.openvz.org/Introduction_to_virtualization

My understanding is that OpenVZ/Virtuozzo is fundamentally different from Xen in how it does 'virtualization', so really, the issue is whether either technology is somehow more appropriate to Drupal. Obviously, generic comparisons can be made in favour of either, depending on your setup.

I think it would be fair to say that most of the time, there's no significant difference. I would guess that if the server's not overloaded, chances are VZ would have a slight edge. I think the key question your tests raise is: does Xen handle overload better? I'd bet your examples don't demonstrate this at all, but it's still a fair question.

From looking at your various examples, I'm going to wager that Xen degrades better because it can guarantee resources - i.e., the server can't get clobbered as easily by another virtual server on the same physical machine.

The flip side of this is that if you're lucky enough to have a VZ server on a mostly empty machine, then you can take better advantage of it.

So, if you've got issues running Drupal on a server and it's a VZ virtualization, moving it to Xen will probably work, but only because you're changing hosts!

You can not compare XEN with

You can not compare XEN with OpenVZ without detailed comparison of resources allocated to the virtual host. OpenVZ vm's by default are installed with very little resources and sometimes it is even impossible to install larger software - like java into those.

Therefore you need to examine /proc/user_beancounters and make sure that there are not any bottlenecks for your application.

Look in OpenVZ wiki for more information:
http://wiki.openvz.org/Resource_shortage

Out of interest - I noticed

Out of interest - I noticed that you said that in the second case, you installed the problem site on a Xen VPS. However it was not clear that the Xen and OpenVZ site instances were hosted and benchmarked on the same machine. If not, then I don't think you can really compare the results, since even the best resource scheduling can't make Xen on a dedicated unloaded server compete with OpenVZ on an underspecified shared server that happens to host a porn network ;)

Not a benchmark

Those were not formal benchmarks, but rather observations. So they are anecdotal evidence if you will. Jonathan Lambert seems to have observed a similar trend (see his comments).
--
2bits -- Drupal consulting

We run some OpenVZ VPSs and

We run some OpenVZ VPSs and find them very fast (well, pretty much as fast as the raw hardware...if you get better than that something is wrong!). Most things I read seem to indicate that OpenVZ has a much lower overhead, and most better resource management when under pressure (especially because of the two-level scheduler). While your results are interesting, they do seem a bit anecdotal to me :)

For example, here is part of the conclusion from the HP Xen vs. OpenVZ study.

  • For all the configurations and workloads we have tested, Xen incurs higher virtualization overhead than OpenVZ does, resulting in larger difference in application performance when compared to the base Linux case.
  • Performance degradation in Xen increases as application workloads increase. The average response time can go up by over 600% in the single-node case, and between 115% and 600% in the two-node case depending on the number of applications.
  • For all the cases tested, the virtualization overhead observed in OpenVZ is limited, and can be neglected in many scenarios.
  • For all configurations, the Web tier CPU consumptionfor Xen is roughly twice that of the base system or OpenVZ. CPU consumption of all systems and all containers goes up linearly as the workload increases. The slope of increase in the case of Xen is higher than in OpenVZ and the base cases.
  • Those who agree and those who don't

    Workhabit mention the same observation on Xen vs. Virtuozzo, in this article.

    And here are some benchmarks of Xen vs OpenVZ.
    --
    2bits -- Drupal consulting

    linux-vserver

    I moved to linux-vserver. These servers are for one organization on dedicated servers. Not vps for rent to others. So not really like the situation in your post.

    It is a chroot environment more like bsd jails. For my usage having the same kernel is not an issue. There is good support in Ubuntu and debian too.

    http://en.wikipedia.org/wiki/Linux-VServer

    Joe

    agree with you

    agree with you. I use vservers on my productive servers for some months, they now eat less system resouce compared to xen. Additionally...
    1, as for my exp.,vserver is much easier to manage.
    2, openvz is nearly the same as vserver, there's no absolute difference.

    What is the speed?

    They all work from a functionality point of view, whether it is OpenVZ/Virtuozzo, Xen, UML, or Linux Vserver.

    My point was performance. Xen is far superior over OpenVZ. How does Linux Vserver fare in this regard in your case?
    --
    2bits -- Drupal consulting

    linux-vserver performance

    I was moving from self-hosted user-mode-linux and a couple of rented vps accounts on uml too. There was a little performance lag on them but mostly a stability problem on the ones I hosted on our dedicated servers. UML development had slowed and seemed to have been leapfrogged by these others.

    I did not benchmark agains Xen but part of the decision making process was because the Linux-Vserver architecture could have performance advantages. It runs only one kernel for all virtual servers. The files in each virtual server are not in some COW like image so there isn't a slowdown there either.

    I'm going to try Virtualbox on my development desktop to see how it works.

    good subject again Khalid, thanks.

    Joe

    Agree

    I have to back up Khalid here. We are former SW-Soft Gold partners, and were involved with OpenVZ from as far back as having made the suggestion to them to not call it OpenVirtuozzo due to brand confusion. ;-)

    We have a massive cluster (several racks full) of XEN now running Drupal-based applications, and have found that in benchmarks, XEN and even VMWare bench far more reliably than OpenVZ and Virtuozzo.

    The performance question is secondary to the fact that we can get consistent results using VMWare and XEN (we use XEN now almost exclusively, VMWare only for very large clients or those with a specific requirement).

    It's the consistency that matters, because what you want to avoid is a couple of higher performance sites on a box crushing your performance when they get busy - that's something you don't get with "soft virtualization" systems like Virtuozzo, OpenVZ, or, sadly, even LVS (though proper architecture more than makes up for this with LVS). The only real sore point with Xen is the same point with any virtualization system - i/o constraint.

    This isn't really a problem until you start running intensive database-driven applications, which includes Drupal. Then you start getting into the joy of "which system-tuned variable gets crushed first" with soft virtualization systems.

    This isn't to say it can't be done, but default settings won't do it, and it's a LOT harder than just grabbing yourself a sliced up "hard virtualization" style box (XEN, VMWare, etc).

    As usual Khalid, nice comments.

    My 2c.

    Jonathan Lambert
    Principal & CEO

    WorkHabit, Inc.
    http://www.WorkHabit.com/
    http://www.WorkHabit.org/

    One advantage of Xen

    I'm far from an expert on virtualization technologies, but one Xen advantage over Virtuozzo (and maybe OpenVZ) is that you have /sys/kernel and all of the other directories that you would expect to see on under /sys on Xen. On Virtuozzo you don't see /sys/kernel and some of the others. I this has to do with how Virtuozzo shares a kernel between multiple containers on the host machine.

    A problem that I've run into is that standard Ubuntu init scripts will fail because their tests for /sys/kernel fail. This happens with the HAL init script. You can start HAL interactively and therefore you can probably script a work around and run it on boot, but a can of worms is probably opening...


    REFERENCE

    http://2bits.com/articles/hosting-virtualization-openvz-vs-xen-which-is-best.html



    Friday, January 22, 2010

    HA cluster with DRBD and Heartbeat

    — SkyHi @ Friday, January 22, 2010
    This article shows how to setup a OpenVZ high availability (HA) cluster using the data replication software DRBD and the cluster manager Heartbeat. In this example the two machines building the cluster run on CentOS 4.3. The article also shows how to do kernel updates in the cluster, including necessary steps like recompiling of new DRBD userspace tools. For this purpose, kernel 2.6.8-022stab078.10 (containing DRBD module 0.7.17) is used as initial kernel version, and kernel 2.6.8-022stab078.14 (containing DRBD module 0.7.20) as updated kernel version.
    Update: this howto currently does not describe details on OpenVZ Kernel 2.6.18, which contains DRBD version 8.*. Meanwhile, some hints on using OpenVZ Kernel 2.6.18 with DRBD 8 can be found in this thread in the forum.
    Additional information about clustering of virtual machines can be found in the following paper: (PDF, 145K)
    Some other additional information can be found in the documentation of the Thomas-Krenn.AG cluster (The author of this howto is working in the cluster development there, that is the reason why he was able to write this howto :-). The full documentation with interesting illustrations is currently only available in German:
    An excellent presentation and overview by Werner Fischer, Thomas-Krenn.AG is available here http://www.profoss.eu/index.php/main/content/download/355/3864/file/werner-fischer.pdf.


    Contents

    [hide]

    [edit] Prerequisites

    The OpenVZ kernel already includes the DRBD module. The DRBD userspace tools and the cluster manager Heartbeat must be provided seperately. As the API version of the DRBD userspace tools must exactly match the API version of the module, compile them yourself. Also compile Heartbeat yourself, as at the time of this writing the CentOS extras repository only contained an old CVS version of Heartbeat.
    On a hardware node for production use there should not be any application that is not really needed for running OpenVZ (any things which are not needed by OpenVZ should run in a VE for security reasons). As a result, compile DRBD and Heartbeat on another machine running CentOS 4.3 (in this example I used a virtual machine on a VMware Server).

    [edit] Compiling Heartbeat

    Heartbeat version 1.2.* has successfully been used in a lot of two-node-clusters around the world. As the codebase used in version 1.2.* is in production use for many years now, the code is very stable. At the time of writing, Heartbeat version 1.2.4 is the current version of the 1.2.* branch.
    Get the tar.gz of the current version of the 1.2.* branch from http://linux-ha.org/download/index.html, at the time of this writing this is http://linux-ha.org/download/heartbeat-1.2.4.tar.gz. Use rpmbuild to build the package:
    rpmbuild -ta heartbeat-1.2.4.tar.gz
    After that, you find four rpm packes in /usr/src/redhat/RPMS/i386 (heartbeat-1.2.4-1.i386.rpm, heartbeat-ldirectord-1.2.4-1.i386.rpm, heartbeat-pils-1.2.4-1.i386.rpm, heartbeat-stonith-1.2.4-1.i386.rpm). In this example only heartbeat-1.2.4-1.i386.rpm, heartbeat-pils-1.2.4-1.i386.rpm, and heartbeat-stonith-1.2.4-1.i386.rpm are needed.

    [edit] Compiling DRBD userspace tools

    When compiling the DRBD userspace tools, you have to take care to take the version that matches the DRBD version that is included in the OpenVZ kernel you want to use. If you are unsure about the version, do the following steps while running the OpenVZ kernel that you want to use on a test machine (I used another virtual machine on a VMware server to try this):
    [root@testmachine ~]# cat /proc/version
    Linux version 2.6.8-022stab078.10 (root@rhel4-32) (gcc version 3.4.5 20051201 (Red Hat 3.4.5-2)) #1 Wed Jun 21 12:01:20 MSD 2006
    [root@testmachine ~]# modprobe drbd
    [root@testmachine ~]# cat /proc/drbd
    version: 0.7.17 (api:77/proto:74)
    SVN Revision: 2093 build by phil@mescal, 2006-03-06 15:04:12
     0: cs:Unconfigured
     1: cs:Unconfigured
    [root@testmachine ~]# rmmod drbd
    [root@testmachine ~]#
    Here the version of the DRBD module is 0.7.17. So the userspace tools for 0.7.17 are neccessary.
    Back on the buildmachine, do the following to create the rpm:
    [root@buildmachine ~]# yum install kernel-devel gcc bison flex
    Setting up Install Process
    Setting up repositories
    Reading repository metadata in from local files
    Parsing package install arguments
    Nothing to do
    [root@buildmachine ~]# tar xfz drbd-0.7.17.tar.gz
    [root@buildmachine ~]# cd drbd-0.7.17
    [root@buildmachine drbd-0.7.17]# make rpm
    [...]
    You have now:
    -rw-r--r--  1 root root 288728 Jul 30 10:40 dist/RPMS/i386/drbd-0.7.17-1.i386.rpm
    -rw-r--r--  1 root root 518369 Jul 30 10:40 dist/RPMS/i386/drbd-km-2.6.9_34.0.2.EL-0.7.17-1.i386.rpm
    [root@buildmachine drbd-0.7.17]#
    Note that in this way the kernel-devel from CentOS is used, but this does not matter as the created drbd-km rpm will not be used (the DRBD kernel module is already included in OpenVZ kernel). If the kernel-devel package is not the same version as the kernel package that is currently running, it is possible to execute 'make rpm KDIR=/usr/src/kernels/2.6.9-34.0.2.EL-i686/' to directly point to the kernel sources.

    [edit] Installing the two nodes

    Install the two machines in the same way as you would install them for a normal OpenVZ installation, but do not create a filesystem for the /vz. This filesystem will be installed later on on top of DRBD.
    Example installation configuration
    Parameter node1 node2
    hostname ovz-node1 ovz-node2
    / filesystem hda1, 10 GB hda1, 10 GB
    swap space hda2, 2048 MB hda2, 2048 MB
    public LAN eth0, 192.168.1.201 eth0, 192.168.1.202
    private LAN eth1, 192.168.255.1 (Gbit Ethernet) eth1, 192.168.255.2 (Gbit Ethernet)
    other install options no firewall, no SELinux no firewall, no SELinuxt vim-enhanced

    [edit] Installing OpenVZ

    Get the OpenVZ kernel and utilities and install them on both nodes, as described in quick installation. Update grub configuration to use the OpenVZ kernel by default. Disable starting of OpenVZ on system boot on both nodes (OpenVZ will be started and stopped by Heartbeat):
    [root@ovz-node1 ~]# chkconfig vz off
    [root@ovz-node1 ~]# 
    Then reboot both machines.

    [edit] Setting up DRBD

    On each of the two nodes create a partition that acts as underlying DRBD device. The partitions should have exactly the same size (I created a 10 GB partition hda3 using fdisk on each node for this example). Note that it might be necessary to reboot the machines to re-read the partition table.
    Install the rpm of the DRBD userspace tools on both nodes:
    [root@ovz-node1 ~]# rpm -ihv drbd-0.7.17-1.i386.rpm
    Preparing...                ########################################### [100%]
       1:drbd                   ########################################### [100%]
    [root@ovz-node1 ~]#
    Then create the drbd.conf configuration file and copy it to /etc/drbd.conf on both nodes. Below is the example configuration file that is used in this article:
    resource r0 {
      protocol C;
      incon-degr-cmd "echo '!DRBD! pri on incon-degr' | wall ; sleep 60 ; halt -f";
    
      startup {
        degr-wfc-timeout 120;
      }
    
      net {
        on-disconnect reconnect;
      }
    
      disk {
        on-io-error   detach;
      }
    
      syncer {
        rate 30M;
        group 1;
        al-extents 257;
      }
    
      on ovz-node1 {
        device     /dev/drbd0;
        disk       /dev/hda3;
        address    192.168.255.1:7788;
        meta-disk  internal;
      }
    
      on ovz-node2 {
        device     /dev/drbd0;
        disk       /dev/hda3;
        address    192.168.255.2:7788;
        meta-disk  internal;
      }
    
    }
    Start DRBD on both nodes:
    [root@ovz-node1 ~]# /etc/init.d/drbd start
    Starting DRBD resources:    [ d0 s0 n0 ].
    [root@ovz-node1 ~]# 
    Then check the status of /proc/drbd:
    [root@ovz-node1 ~]# cat /proc/drbd
    version: 0.7.17 (api:77/proto:74)
    SVN Revision: 2093 build by phil@mescal, 2006-03-06 15:04:12
     0: cs:Connected st:Secondary/Secondary ld:Inconsistent
        ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0
    [root@ovz-node1 ~]#
    Both nodes are now Secondary and Inconsistent. The latter is because the underlying storage is not yet in-sync, and DRBD has no way to know whether you want the initial sync from ovz-node1 to ovz-node2, or ovz-node2 to ovz-node1. As there is no data below it yet, it does not matter.
    To start the sync from ovz-node1 to ovz-node2, do the following on ovz-node1:
    [root@ovz-node1 ~]# drbdadm -- --do-what-I-say primary all
    [root@ovz-node1 ~]# cat /proc/drbd
    version: 0.7.17 (api:77/proto:74)
    SVN Revision: 2093 build by phil@mescal, 2006-03-06 15:04:12
     0: cs:SyncSource st:Primary/Secondary ld:Consistent
        ns:627252 nr:0 dw:0 dr:629812 al:0 bm:38 lo:640 pe:0 ua:640 ap:0
            [=>..................] sync'ed:  6.6% (8805/9418)M
            finish: 0:04:51 speed: 30,888 (27,268) K/sec
    [root@ovz-node1 ~]#
    As you see, DRBD syncs with about 30 MB per second, as we told it so in /etc/drbd.conf. On the SyncSource (ovz-node1 in this case) the DRBD device is already useable (although it is syncing in the background).
    So you can immediately create the filesystem:
    [root@ovz-node1 ~]# mkfs.ext3 /dev/drbd0
    [...]
    [root@ovz-node1 ~]# 

    [edit] Copy necessary OpenVZ files to DRBD device

    Move the original /vz directory to /vz.orig and recreate the /vz directory to have it as a mount point (do this on both nodes):
    [root@ovz-node1 ~]# mv /vz /vz.orig
    [root@ovz-node1 ~]# mkdir /vz
    [root@ovz-node1 ~]#
    Afterwards move the necessary OpenVZ directories (/etc/vz, /etc/sysconfig/vz-scripts, /var/vzquota) and replace them with symbolic links (do this on both nodes):
    [root@ovz-node1 ~]# mv /etc/vz /etc/vz.orig
    [root@ovz-node1 ~]# mv /etc/sysconfig/vz-scripts /etc/sysconfig/vz-scripts.orig
    [root@ovz-node1 ~]# mv /var/vzquota /var/vzquota.orig
    [root@ovz-node1 ~]# ln -s /vz/cluster/etc/vz /etc/vz
    [root@ovz-node1 ~]# ln -s /vz/cluster/etc/sysconfig/vz-scripts /etc/sysconfig/vz-scripts
    [root@ovz-node1 ~]# ln -s /vz/cluster/var/vzquota /var/vzquota
    [root@ovz-node1 ~]#
    Currently, ovz-node1 is still Primary of /dev/drbd0. You can now mount it and copy the necessary files to it (only on ovz-node1!):
    [root@ovz-node1 ~]# mount /dev/drbd0 /vz
    [root@ovz-node1 ~]# cp -a /vz.orig/* /vz/
    [root@ovz-node1 ~]# mkdir -p /vz/cluster/etc
    [root@ovz-node1 ~]# mkdir -p /vz/cluster/etc/sysconfig
    [root@ovz-node1 ~]# mkdir -p /vz/cluster/var
    [root@ovz-node1 ~]# cp -a /etc/vz.orig /vz/cluster/etc/vz/
    [root@ovz-node1 ~]# cp -a /etc/sysconfig/vz-scripts.orig /vz/cluster/etc/sysconfig/vz-scripts
    [root@ovz-node1 ~]# cp -a /var/vzquota.orig /vz/cluster/var/vzquota
    [root@ovz-node1 ~]# umount /dev/drbd0
    [root@ovz-node1 ~]#

    [edit] Setting up Heartbeat

    Install the neccessary Heartbeat rpms on both nodes:
    [root@ovz-node1 ~]# rpm -ihv heartbeat-1.2.4-1.i386.rpm heartbeat-pils-1.2.4-1.i386.rpm heartbeat-stonith-1.2.4-1.i386.rpm
    Preparing...                ########################################### [100%]
       1:heartbeat-pils         ########################################### [ 33%]
       2:heartbeat-stonith      ########################################### [ 67%]
       3:heartbeat              ########################################### [100%]
    [root@ovz-node1 ~]#
    Create the Heartbeat configuration file ha.cf and copy it to /etc/ha.d/ha.cf on both nodes. Details about this file can be found at http://www.linux-ha.org/ha.cf. Below is an example configuration which uses the two network connections and also a serial connection for heartbeat packets:
    # Heartbeat logging configuration
    logfacility daemon
    
    # Heartbeat cluster members
    node ovz-node1
    node ovz-node2
    
    # Heartbeat communication timing
    keepalive 1
    warntime 10
    deadtime 30
    initdead 120
    
    # Heartbeat communication paths
    udpport 694
    ucast eth1 192.168.255.1
    ucast eth1 192.168.255.2
    ucast eth0 192.168.1.201
    ucast eth0 192.168.1.202
    baud 19200
    serial /dev/ttyS0
    
    # Don't fail back automatically
    auto_failback off
    
    # Monitoring of network connection to default gateway
    ping 192.168.1.1
    respawn hacluster /usr/lib64/heartbeat/ipfail
    Create the Heartbeat configuration file authkeys and copy it to /etc/ha.d/authkeys on both nodes. Set the permissions of this file to 600. Details about this file can be found at http://www.linux-ha.org/authkeys. Below is an example:
    auth 1
    1 sha1 PutYourSuperSecretKeyHere
    Create the Heartbeat configuration file haresources and copy it to /etc/ha.d/haresources on both nodes. Details about this file can be found at http://www.linux-ha.org/haresources. Note that it is not necessary to configure IPs for gratuitous arp here. The gratuitous arp is done by OpenVZ itself, through /etc/sysconfig/network-scripts/ifup-venet and /usr/lib/vzctl/scripts/vps-functions. Below is an example for the haresources file:
    ovz-node1 drbddisk::r0 Filesystem::/dev/drbd0::/vz::ext3 vz MailTo::youremail@yourdomain.tld
    Finally, you can now start heartbeat on both nodes:
    [root@ovz-node1 ~]# /etc/init.d/heartbeat start
    Starting High-Availability services:
                                                               [  OK  ]
    [root@ovz-node1 ~]#

    [edit] Before going in production: testing, testing, testing, and ...hm... testing!

    The installation of the cluster is finished at this point. Before putting the cluster in production it is very important to test the cluster. Because of all the possible different kinds of hardware that you may have, you may encounter problems when a failover is necessary. And as the cluster is about high availability, such problems must be found before the cluster is used for production.
    Here is one example: The e1000 driver that is included in kernels < 2.6.12 has a problem when a cable gets unplugged while broadcast packets are still being sent out on that interface. When using broadcast communication in Heartbeat on a crossover link, this fills up the transmit ring buffer on the adapter (the buffer is full after about 8 minutes after the cable got unplugged). Using unicast communication in Heartbeat fixes the problem for example. Details see: http://www.osdl.org/developer_bugzilla/show_bug.cgi?id=699#c22
    Without testing you may not be aware of such problems and may face them when the cluster is in production and a failover would be necessary. So test your cluster carefully!
    Possible tests can include:
    • power outage test of active node
    • power outage test of passive node
    • network connection outage test of eth0 of active node
    • network connection outage test of eth0 of passive node
    • network connection outage test of crossover network connection
    • ...
    As mentioned above, some problems only arise after an outage lasts longer than some minutes. So do the tests also with a duration of >1h for example.
    Before you start to test, build a test plan. Some valueable information on that can be found in chapter 3 "Testing a highly available Tivoli Storage Manager cluster environment" of the Redbook IBM Tivoli Storage Manager in a Clustered Environment, see http://www.redbooks.ibm.com/abstracts/sg246679.html. In this chapter it is mentioned that the experience of the authoring team is that the testing phase must be at least two times the total implementation time for the cluster.

    [edit] Before installing kernel updates: testing again

    New OpenVZ kernel often include driver updates. This kernel for examples includes an update of the e1000 module: http://openvz.org/news/updates/kernel-022stab078.21
    To avoid to overlook problems with new components (such as a newer kernel), it is necessary to re-do the tests mentioned above. But as the cluster is already in production, a second cluster (test cluster) with the same hardware as the main cluster is needed. Use this test cluster to test updates of the kernel or main OS updates for the hardware node before putting them on the production cluster.
    I know this is not an easy task, as it is time-consuming and needs additional hardware only for testing. But when really business-critical applications are running on the cluster, it is very good to now that the cluster works fine also with new updates installed on the hardware node. In many cases a dedicated test cluster and the time efford for the testing of updates may cause too much costs. If you cannot do such test of updates, keep in mind that over time (when you must install security updates of the OS or the kernel) you have a cluster that you have not tested in this configuration.
    If you need a tested cluster (also with tested kernel updates), you may take a look on this Virtuozzo cluster: http://www.thomas-krenn.com/cluster

    [edit] How to do OpenVZ kernel updates when it contains a new DRBD version

    As mentioned above, it is important to use the correct version of the DRBD userspace tools. When an OpenVZ kernel contains a new DRBD version, it is important that the DRBD API version of the userspace tools matches the API version of the DRBD module that is included in the OpenVZ kernel. The API versions can be found at http://svn.drbd.org/drbd/branches/drbd-0.7/ChangeLog. The best way is to always use the version of the DRBD userspace tools that matches the version of the DRBD module that is included in the OpenVZ kernel.
    In this example the initial cluster installation contained OpenVZ kernel 2.6.8-022stab078.10, which contains the DRBD module 0.7.17. The steps below show the update procedure to OpenVZ kernel 2.6.8-022stab078.14, which contains the DRBD module 0.7.20. In the first step build the DRBD userspace tools version 0.7.20 on your buildmachine. Then stop Heartbeat and DRBD on the passive node (hint: you can use 'cat /proc/drbd' to get a hint which node is active and which one is passive):
    [root@ovz-node2 ~]# cat /proc/drbd
    version: 0.7.17 (api:77/proto:74)
    SVN Revision: 2093 build by phil@mescal, 2006-03-06 15:04:12
     0: cs:Connected st:Secondary/Primary ld:Consistent
        ns:60 nr:136 dw:196 dr:97 al:3 bm:3 lo:0 pe:0 ua:0 ap:0
    [root@ovz-node2 ~]# /etc/init.d/heartbeat stop
    Stopping High-Availability services:
                                                               [  OK  ]
    [root@ovz-node2 ~]# cat /proc/drbd
    version: 0.7.17 (api:77/proto:74)
    SVN Revision: 2093 build by phil@mescal, 2006-03-06 15:04:12
     0: cs:Connected st:Secondary/Primary ld:Consistent
        ns:60 nr:136 dw:196 dr:97 al:3 bm:3 lo:0 pe:0 ua:0 ap:0
    [root@ovz-node2 ~]# /etc/init.d/drbd stop
    Stopping all DRBD resources.
    [root@ovz-node2 ~]# cat /proc/drbd
    cat: /proc/drbd: No such file or directory
    [root@ovz-node2 ~]#
    Then install the new kernel and the DRBD userspace tools on this node:
    [root@ovz-node2 ~]# rpm -ihv ovzkernel-2.6.8-022stab078.14.i686.rpm
    warning: ovzkernel-2.6.8-022stab078.14.i686.rpm: V3 DSA signature: NOKEY, key ID a7a1d4b6
    Preparing...                ########################################### [100%]
       1:ovzkernel              ########################################### [100%]
    [root@ovz-node2 ~]# rpm -Uhv drbd-0.7.20-1.i386.rpm
    Preparing...                ########################################### [100%]
       1:drbd                   ########################################### [100%]
    /sbin/service
    Stopping all DRBD resources.
    [root@ovz-node2 ~]#
    Now set the new kernel as default kernel in /etc/grub.conf and then reboot this node.
    After the reboot, the new DRBD version is visible:
    [root@ovz-node2 ~]# cat /proc/drbd
    version: 0.7.20 (api:79/proto:74)
    SVN Revision: 2260 build by phil@mescal, 2006-07-04 15:18:57
     0: cs:Connected st:Secondary/Primary ld:Consistent
        ns:0 nr:28 dw:28 dr:0 al:0 bm:2 lo:0 pe:0 ua:0 ap:0
    [root@ovz-node2 ~]#
    To update the other node, switch-over the services to make the current active node the passive node. Execute the following on the still active node (it could be that the hb_standby command is located in /usr/lib/heartbeat):
    [root@ovz-node1 ~]# /usr/lib64/heartbeat/hb_standby
    2006/08/03_21:09:41 Going standby [all].
    [root@ovz-node1 ~]#
    Now do the same steps on the new passive node to update it: stop Heartbeat and DRBD, install the new kernel and the new DRBD userspace tools, set the new kernel as default kernel in /etc/grub.conf and reboot the node.

    [edit] How to do updates of vzctl, vzctl-lib, and vzquota

    Ensure after every update of OpenVZ tools that OpenVZ is not started on system boot. To disable starting of OpenVZ on system boot execute on both nodes:
    [root@ovz-node1 ~]# chkconfig vz off
    [root@ovz-node1 ~]# 

    [edit] Live-Switchover with the help of checkpointing

    With the help of checkpointing it is possible to do live switchovers.
    Important: although this HOWTO currently describes the use of DRBD 0.7, it is necessary to use DRBD 8 to be able to use this live-switchover feature reliable. Some hints on using OpenVZ Kernel 2.6.18 with DRBD 8 can be found in this thread in the forum.
    The following scripts are written by Thomas Kappelmueller. They should be placed at /root/live-switchover/ on both nodes. To activate the scripts execute the following commands on both nodes:
    [root@ovz-node1 ~]# ln -s /root/live-switchover/openvz /etc/init.d/
    [root@ovz-node1 ~]# ln -s /root/live-switchover/live_switchover.sh /root/bin/
    [root@ovz-node1 ~]# 
    It is also necessary to replace vz by an adjusted initscript (openvz in this example). So /etc/ha.d/haresources has the following content on both nodes:
    ovz-node1 drbddisk::r0 Filesystem::/dev/drbd0::/vz::ext3 openvz MailTo::youremail@yourdomain.tld

    [edit] Script cluster_freeze.sh

    #!/bin/bash
    #Script by Thomas Kappelmueller
    #Version 1.0
    LIVESWITCH_PATH='/vz/cluster/liveswitch'
    
    if [ -f $LIVESWITCH_PATH ]
    then
            rm -f $LIVESWITCH_PATH
    fi
    
    RUNNING_VE=$(vzlist -1)
    
    for I in $RUNNING_VE
    do
            BOOTLINE=$(cat /etc/sysconfig/vz-scripts/$I.conf | grep -i "^onboot")
            if [ $I != 1 -a "$BOOTLINE" = "ONBOOT=\"yes\"" ]
            then
                    vzctl chkpnt $I
    
                    if [ $? -eq 0 ]
                    then
                            vzctl set $I --onboot no --save
                            echo $I >> $LIVESWITCH_PATH
                    fi
            fi
    done
    
    exit 0

    [edit] Script cluster_unfreeze.sh

    #!/bin/bash
    #Script by Thomas Kappelmueller
    #Version 1.0
    
    LIVESWITCH_PATH='/vz/cluster/liveswitch'
    
    if [ -f $LIVESWITCH_PATH ]
    then
            FROZEN_VE=$(cat $LIVESWITCH_PATH)
    else
            exit 1
    fi
    
    for I in $FROZEN_VE
    do
            vzctl restore $I
    
            if [ $? != 0 ]
            then
                    vzctl start $I
            fi
    
            vzctl set $I --onboot yes --save
    done
    
    rm -f $LIVESWITCH_PATH
    
    exit 0

    [edit] Script live_switchover.sh

    #!/bin/bash
    #Script by Thomas Kappelmueller
    #Version 1.0
    
    ps -eaf | grep 'vzctl enter' | grep -v 'grep' > /dev/null
    if [ $? -eq 0 ]
    then
      echo 'vzctl enter is active. please finish before live switchover.'
      exit 1
    fi
    ps -eaf | grep 'vzctl exec' | grep -v 'grep' > /dev/null
    if [ $? -eq 0 ]
    then
      echo 'vzctl exec is active. please finish before live switchover.'
      exit 1
    fi
    echo "Freezing VEs..."
    /root/live-switchover/cluster_freeze.sh
    echo "Starting Switchover..."
    /usr/lib64/heartbeat/hb_standby

    [edit] Script openvz

    #!/bin/bash
    #
    # openvz        Startup script for OpenVZ
    #
    
    start() {
            /etc/init.d/vz start > /dev/null 2>&1
            RETVAL=$?
            /root/live-switchover/cluster_unfreeze.sh
            return $RETVAL
    }
    stop() {
            /etc/init.d/vz stop > /dev/null 2>&1
            RETVAL=$?
            return $RETVAL
    }
    status() {
            /etc/init.d/vz status > /dev/null 2>&1
            RETVAL=$?
            return $RETVAL
    }
    
    # See how we were called.
    case "$1" in
      start)
            start
            ;;
      stop)
            stop
            ;;
      status)
            status
            ;;
      *)
            echo $"Usage: openvz {start|stop|status}"
            exit 1
    esac
    
    exit $RETVAL