How to install OpenVZ in CentOS 5.6


Follow the steps below.
1. Turn off SELinux

vi /etc/selinux/config

/************************************************************************/
SELINUX=disabled
SELINUXTYPE=targeted
SETLOCALDEFS=0
/************************************************************************/

2. Reboot the machine then type the command below to see the status of the selinux if it is completely disabled.

Reboot

3. Remove the firewall

chkconfig iptables –level 2345 off
chkconfig iptables –list

cd /etc/yum.repos.d

wget http://download.openvz.org/openvz.repo
rpm –import  http://download.openvz.org/RPM-GPG-Key-OpenVZ

vi openvz.repo  <– to see which repo you want to enable. I just use the rhel5 “[openvz-kernel-rhel5]” as the rhel6 make the kernel of centos 5.6 corrupt. I think rhel6 is for centos 6 and above.

/************************************************************************/
[openvz-utils]
name=OpenVZ utilities
mirrorlist=http://download.openvz.org/mirrors-current
enabled=1
gpgcheck=1
gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ

# Stable branches
[openvz-kernel-rhel5]
name=OpenVZ RHEL5-based kernel
#baseurl=http://download.openvz.org/kernel/branches/rhel5-2.6.18/current/
mirrorlist=http://download.openvz.org/kernel/mirrors-rhel5-2.6.18
enabled=1
gpgcheck=1
gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ
/************************************************************************/

yum update

yum install openvz-kernel-rhel5 vzctl vzquota bridge-utils -y

Or

Manually install of ovzkernel
wget http://download.openvz.org/kernel/branches/rhel5-2.6.18/028stab101.1/ovzkernel-2.6.18-308.8.2.el5.028stab101.1.i686.rpm
yum install ovzkernel-2.6.18-308.8.2.el5.028stab101.1.i686.rpm

vi /boot/grub/grub.conf

/************************************************************************/
default 0
title OpenVZ (…)
—–
default=0
….
title OpenVz (2.6.18-128.2.1.el5.028stab064.7)
root (hd0,0)
kernel /vmlinuz-2.6.18-128.2.1.el5.028stab064.7 ro root=LABEL=/
initrd /initrd-2.6.18-128.2.1.el5.028stab064.7.img
title CentOS (2.6.18-128.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-128.el5 ro root=LABEL=/
initrd /initrd-2.6.18-128.el5.img
—–
/************************************************************************/

vi /etc/sysctl.conf

/************************************************************************/
net.ipv4.ip_forward = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
kernel.core_uses_pid = 1
/************************************************************************/

Next is to install a template for the distribution.

You may follow the link below to download your desired template.

http://wiki.openvz.org/Download/template/precreated

cd /vz/template/cache
wget http://download.openvz.org/template/precreated/contrib/centos-5-i386-default.tar.gz

 

To set up a VPS from the default CentOS 5 template, run:

vzctl create 101 –ostemplate centos-5-i386-default –config vps.basic

 

Set to start on boot. Type the commands below to the terminal.

vzctl set 101 –onboot yes –save

vzctl set 101 –hostname openvz.com –save
vzctl set 101 –ipadd 192.168.2.127 –save

Set the number of sockets to 120 and assign a few nameservers to the vm:

vzctl set 101 –numothersock 120 –save

vzctl set 101 –nameserver 8.8.8.8  –save

I just use google name server for this example.

vzctl start 101

vzctl exec 101 passwd

You can now connect using ssh or terminal client.

You may also try to upload your website at this location

/vz/private/101/var/www/html

/*****index.html*********/

<html>
<body>
This is my test index file inside my /vz/private/101/var/www/html
</body>
</html>

/****end of my code******/

This is my test index file inside my /vz/private/101/var/www/html

then type the ip address that you have assigned in your openvz.

http://192.168.2.127


Leave a Reply