Wednesday, January 23, 2013

Guide to OpenVZ



Download openvz.repo file and put it to your /etc/yum.repos.d/ repository, and import OpenVZ GPG key used for signing RPM packages. This can be achieved by the following commands, as root:

# wget -P /etc/yum.repos.d/ http://download.openvz.org/openvz.repo

# rpm --import  http://download.openvz.org/RPM-GPG-Key-OpenVZ



# yum install ovzkernel

In GRUB boot loader, it will be configured automatically: lines similar to these will be added to the /boot/grub/grub.conf file:

title OpenVZ (2.6.8-022stab029.1)
        root (hd0,0)
        kernel /vmlinuz-2.6.8-022stab029.1 ro root=/dev/sda5
        initrd /initrd-2.6.8-022stab029.1.img






-----------------------------------------------------------------------------------------------------------------------------------

Configuring

Please make sure the following steps are performed before rebooting into OpenVZ kernel.


sysctl

There are a number of kernel parameters that should be set for OpenVZ to work correctly. These parameters are stored in /etc/sysctl.conf file. Here are the relevant portions of the file; please edit accordingly.

# On Hardware Node we generally need
# packet forwarding enabled and proxy arp disabled
net.ipv4.ip_forward = 1
net.ipv6.conf.default.forwarding = 1
net.ipv6.conf.all.forwarding = 1
net.ipv4.conf.default.proxy_arp = 0

# Enables source route verification
net.ipv4.conf.all.rp_filter = 1

# Enables the magic-sysrq key
kernel.sysrq = 1

# We do not want all our interfaces to send redirects
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0


SELinux

SELinux should be disabled. To that effect, put the following line to /etc/sysconfig/selinux:

SELINUX=disabled



Now reboot the machine and choose "OpenVZ" on the boot loader menu.


-----------------------------------------------------------------------------------------------------------------------------


OpenVZ needs some user-level tools installed. Those are:

vzctl
    A utility to control OpenVZ containers (create, destroy, start, stop, set parameters etc.)

vzquota
    A utility to manage quotas for containers. Mostly used indirectly (by vzctl).

Using yum

# yum install vzctl vzquota



 Starting OpenVZ

As root, execute the following command:

# /sbin/service vz start



Installing OS template caches


An OS template cache is a Linux distribution 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.

Download precreated template caches from download.openvz.org/template/precreated . Put those tarballs as-is (no unpacking needed) to the /vz/template/cache/ directory.


 Create and start a container

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

# vzctl create CTID --ostemplate osname
# vzctl set CTID --ipadd a.b.c.d --save
# vzctl set CTID --nameserver a.b.c.d --save
# vzctl start CTID



Example:

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



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

# vzctl exec CTID ps ax


Enter to and exit from the container


To enter container give the following command:

# vzctl enter CTID


To exit from container, just type exit and press Enter:

# exit


Stop and destroy the container

To stop container:

# vzctl stop CTID


And to destroy container:

# vzctl destroy CTID



Powered By Blogger

Followers