OpenVZ virtualization uses the concept of containers to run Linux only instances on the same hadware.

OpenVZ is an operating system-level virtualization technology. It allows a physical server to run multiple
isolated different Linux distributions operating system instances
====
Default Locations

/vz – Main directory for OpenVZ.
/vz/private – Each VPS is stored here i.e. container’s private directories
/vz/template/cache – You must download and store each Linux distribution template here.
/etc/vz/ – OpenVZ configuration directory.
/etc/vz/vz.conf – Main OpenVZ configuration file.
/etc/vz/conf – Softlinked directory for each VPS configuration.
Network port – No network ports are opened by OpenVZ kernel.

=====

###############################################################################################
Creating virtual machines with OpenVZ
——————————————————-
Creating virtual machines in Openvz is simple.

download one from http://wiki.openvz.org/Download/template/precreated.
Let’s download a CentOS 6 template:

[root@ovz:~]# cd /vz/template/cache
[root@ovz:~]# wget http://download.openvz.org/template/precreated/centos-6-x86_64.tar.gz

Setup the container and make it start on boot:

[root@ovz:~]# vzctl create 10 –ostemplate centos-6-x86_64 –config basic
[root@ovz:~]# vzctl set 10 –onboot yes –save

Note that each container must have an unique Id, in this case 10.Now let’s setup a hostname and IP address:

[root@ovz:~]# vzctl set 10 –hostname haproxyvz.example.com –save
[root@ovz:~]# vzctl set 10 –ipadd 10.24.6.230 –save

Next lets set the maximum number of non-TCP sockets (local sockets, UDP and other types of sockets) and use Google DNS inside the container:

[root@ovz:~]# vzctl set 10 –numothersock 100 –save
[root@ovz:~]# vzctl set 10 –nameserver 8.8.8.8 –nameserver 8.8.4.4 –save

Let’s start the container:

[root@ovz:~]# vzctl start 10

This will create a virtual interface with a name similar to this:

[root@ovz:~]# ifconfig
–snip–
veth101.2 Link encap:Ethernet HWaddr 00:18:51:11:2D:6E
inet6 addr: fe80::218:51ff:fe11:2d6e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:185139 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
–snip–

Now lets create a bridge and add our external interface p2p1 and the interface of the container to the bridge br0, so that we can access it from outside:

[root@ovz:~]# cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
BOOTPROTO=static
IPADDR=10.24.6.211
NETMASK=255.255.240.0
GATEWAY=10.24.0.1
ONBOOT=yes
TYPE=”Bridge”

[root@ovz:~]# cat /etc/sysconfig/network-scripts/ifcfg-p2p1
DEVICE=p2p1
HWADDR=00:26:6C:FE:F2:80
TYPE=Ethernet
UUID=cfe0d3f2-8bc9-45c9-91a5-c0cdb9a5644f
ONBOOT=yes
BRIDGE=br0

[root@ovz:~]# /etc/init.d/network restart
[root@ovz:~]# brctl addif br0 veth101.2
[root@ovz:~]# vzctl set 10 –netif_add ethp2p1,,,,br0 –save

Time to change the root password:

[root@ovz:~]# vzctl exec 10 passwd

To enter the container use:

[root@ovz:~]# vzctl enter 10

To stop, restart or destroy the container run:

[root@ovz:~]# vzctl stop 10
[root@ovz:~]# vzctl restart 10
[root@ovz:~]# vzctl destroy 10

##################################################################

Leave a Reply

Your email address will not be published. Required fields are marked *