OpenVZ on CentOS

August 9, 2007 by hejian

Install OpenVZ
Install OpenVZ kernel:

cd /etc/yum.repos.d
wget http://download.openvz.org/openvz.repo
yum install ovzkernel

Install OpenVZ utilities after reboot:

yum install vzctl vzquota

Starting OpenVZ:

/sbin/service vz start

Install OpenVZ Template

yum install vztmpl-centos-4

I can’t “yum install vztmpl-centos-4″ in CentOS5 because it breaks with an Error: Missing Dependency: cElementTree.so is needed by package vzyum
So I have to download it first and then install it:

wget -c http://download.openvz.org/template/utils/vzyum/2.4.0-11/vzyum-2.4.0-11.noarch.rpm
rpm --nodeps -Uvh vzyum-2.4.0-11.noarch.rpm

Fix issues for x86_64 system
There is a known problem with vzpkg-2.7.0 and vzyum-2.4.0 in x86_64 computers: Vzyum, vzpkgcache and vzrpm are broken in 64 bit systems, so we are unable to create new cache templates in a x86_64 computer or update each VE using vzyum or vzrpm.

Create a x86_64 template from the i386:

cd /vz/template/centos/4/
mkdir x86_64
cp -a /vz/template/centos/4/i386/* /vz/template/centos/4/x86_64
cd /vz/template/centos/4/x86_64/config
sed -i 's/i386/x86_64/g' yum.conf

Substitute the 32 bit module “rpmmodule.so” from vzrpm43-python to the 64 bit module that rpm-python-x86_64 provides.
For CentOS 4:

cd /usr/share/vzpkgtools/vzrpm43/lib/python2.3/site-packages/
cp /usr/lib64/python2.3/site-packages/rpmmodule.so .
cd /usr/share/vzpkgtools/vzrpm43/lib/python2.3/site-packages/rpmdb
cp /usr/lib64/python2.3/site-packages/rpmdb/_rpmdb.so .

For CentOS 5:

rm /usr/share/vzpkgtools/vzrpm43/lib/python2.4/site-packages/rpmmodule.so

Fix /usr/share/vzpkg/functions:

change: YUM=/usr/share/vzyum/bin/yum
to: YUM=`which yum`
change: ARCHES="x86 i386 x86_64 ia64"
to: ARCHES="i386 x86_64 ia64 x86"
change: export RPM=`get_rpm $tdir`
to: export RPM=`which rpm`
change: rpm=`get_rpm $tdir`
to: rpm=`which rpm`

Fix “no such option: –vps”:
Edit /usr/share/vzpkg/cache-os:

change: --vps=$VEID check-update
to: check-update
change: YUM_CMD="--installroot=$VE_ROOT --vps=$VEID $YUM_CONF_FILE -y $YUM_CMD"
to: YUM_CMD="--installroot=$VE_ROOT $YUM_CONF_FILE -y $YUM_CMD"

Edit /usr/bin/vzyum:

change: YUM_ARGS="$YUM_ARGS --installroot $VE_ROOT --vps=$VEID"
to: YUM_ARGS="$YUM_ARGS --installroot $VE_ROOT"

Fix MAKEDEV conflicts:
Edit the files menimal.list and default.list in /vz/template/centos/4/x86_64/config:

change:
MAKEDEV
to:
MAKEDEV-3.3.13 (the version must be the same as in /vz/template/centos/4/x86_64/vz-addons)

Create VPS tarball

vzpkgcache -f centos-4-x86_64-default
vzpkgcache -f centos-4-x86_64-minimal

Operations with VE
Creating VE:
vzctl create 11 –ostemplate centos-4-x86_64-default
Adding IPs to VE:
vzctl set 11 –ipadd 192.168.0.11 –save

List VEs:
vzlist -a
Starting VE:
vzctl start 11
Enter VE:
vzctl enter 11
Stop VE:
vzctl stop 11
Destory VE:
vzctl destory 11

Install packages:
vzyum 11 install mysql-server
Running ps command from Hardware Node:
vzctl exec 11 ps ax

Leave a Reply

You must be logged in to post a comment.

Wordpress template made by HeJian