OpenVZ is a container-based virtualization for Linux. OpenVZ creates multiple secure, isolated Linux containers (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.OpenVZ is easy to install if you already have Linux installed on your machine.OpenVZ is free open source software, available under GNU GPL.

How to install OpenVz on Centos

1. Download the openvz repo.

 #cd /etc/yum.repos.d
 #wget http://download.openvz.org/openvz.repo
 #rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ

2. Search for the vzkernel

#yum search vzkernel

3. Install vzkernel

#yum install vzkernel

4.Reboot the system to boot from vzkernel.

#reboot

5.Install vzctl,vzquto and vzdump for backup

#yum install vzctl vzquota vzdump

6.Enable ipforwarding

#vi /etc/sysctl.conf
 file content should be as;
[...]
 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
 [...]

7. force kernel to update the ip forwarding.

#sysctl -p

8.The following step is important if the IP addresses of your virtual machines are from a different subnet than the host system’s IP address. If you don’t do this, networking will not work in the virtual machines!

#vi /etc/vz/vz.conf
Content should be like;
[...]
 NEIGHBOUR_DEVS=all
[...]

9.Disable Selinux

#vi /etc/sysconfig/selinux
 and reboot the box and verify you boot from vzkernel.

 

To create and start a container, run the following commands:

[host-node]# vzctl create CTID --ostemplate osname
[host-node]# vzctl set CTID --ipadd x.x.x.x --save
[host-node]# vzctl set CTID --nameserver a.b.c.d --save
[host-node]# vzctl start CTID

CTID—> The numeric ID for the container(unique)
osname—-> OS template for the container
x.x.x.x —-> IP address to be assigned to the container.

Example:

[host-node]# vzctl create 101 --ostemplate fedora-core-5-minimal
[host-node]# vzctl set 101 --ipadd 10.1.2.3 --save
[host-node]# vzctl set 101 --nameserver 10.0.2.1 --save
[host-node]# vzctl start 101

Your freshly-created container should be up and running now; you can see its processes:

you can also execute the command into the container from outside/from OVZ server where opnevz is installed with login to the server by following way.

[host-node]# vzctl exec CTID ps ax

Enter to and exit from the container

How to enter container.

[host-node]# vzctl enter CTID
 entered into container CTID
 [container]#

How to loged out or exit from container.

[container]# exit
 exited from container VEID
 [host-node]#

How to Stop and destroy the container.

To stop container:

[host-node]# vzctl stop CTID
 Stopping container ...
 Container was stopped
 Container is unmounted

And to destroy container:

[host-node]# vzctl destroy CTID
 Destroying container private area: /vz/private/CTID
 Container private area was destroyed

How to takeĀ  backup of container.

vzdump --compress --dumpdir /vz/vzbackup/ CTID

How to restore the backup.

vzdump --restore /vz/vzbackup/dumpfile new CTID

Warning: count(): Parameter must be an array or an object that implements Countable in /home/vhosts/howtolinuxblog.orgfree.com/wp-includes/class-wp-comment-query.php on line 399

Leave a Reply

Free Web Hosting