Mozilla Skin

OpenVZ

From ISSW

From wiki.openvz.org:

OpenVZ is container-based virtualization for Linux. OpenVZ creates multiple secure, isolated containers (otherwise known as 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.

It is tremendously popular among web hosting companies as it enables Virtual Private Servers (VPS) to be allocated to customers at a virtual:physical ratio up to (and beyond) 1000:1. The commercial offering is Virtuozzo.

For a free out-of-the-box solution, try Proxmox

WebSphere is not explicitly supported, but can work within OpenVZ containers, and enjoys the lower overhead of multiple OS instances within multiple VMWare (or similar) hypervirtualized virtual machines. OpenVZ itself runs fine within a VMWare virtual machine.

This page simply provides an overview of installing and configuring OpenVZ on a CentOS (or RedHat/Fedora) machine, along with an example container. For more detailed configuration instructions, visit the OpenVZ wiki.

OpenVZ can provide full high-availability using data replication. A how-to guide is here

Installation

From http://www.howtoforge.com/installing-and-using-openvz-on-centos5.2:

Add the OpenVZ repository to yum:

[root@OpenVZHost ~]# cd /etc/yum.repos.d;
[root@OpenVZHost yum.repos.d]# wget http://download.openvz.org/openvz.repo;
[root@OpenVZHost yum.repos.d]# rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ;

Install the OpenVZ kernel:

[root@OpenVZHost ~]# yum -y install ovzkernel;

This should automatically update the GRUB bootloader as well. Anyway, we should open /boot/grub/menu.lst; the first kernel stanza should now contain the new OpenVZ kernel. The title of that kernel just reads "CentOS". I think it's a good idea to change that title and add something with "OpenVZ" to it so that you know that it's the OpenVZ kernel. Also make sure that the value of default is 0 so that the first kernel (the OpenVZ kernel) is booted automatically instead of the default CentOS kernel.

[root@OpenVZHost ~]# vi /boot/grub/menu.lst;

Install some OpenVZ tools:

[root@OpenVZHost ~]# yum -y install vzpkg vzyum vzctl vzquota vzrpm43-python vzrpm44-python vzctl-lib;

Edit the sysctl.conf for network pass-thru:

[root@OpenVZHost ~]# vi /etc/sysctl.conf

# It should contain, amongst other things:
# 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

# If modified:
[root@OpenVZHost ~]# sysctl -p;

Open /etc/vz/vz.conf and set NEIGHBOUR_DEVS to all:

[root@OpenVZHost ~]# vi /etc/vz/vz.conf;

# NEIGHBOUR_DEVS=all

SELinux needs to be disabled if you want to use OpenVZ. Open /etc/sysconfig/selinux and set the value of SELINUX to disabled:

[root@OpenVZHost ~]# vi /etc/sysconfig/selinux;

# SELINUX=disabled

Then reboot, and ensure the OpenVZ kernel is in use:

[root@OpenVZHost ~]# uname -r;
2.6.18-53.1.19.el5.028stab053.14

Configuration

Before we can create virtual machines with OpenVZ, we need to have a template for the distribution that we want to use in the virtual machines in the /vz/template/cache directory. The virtual machines will be created from that template. You can find a list of precreated templates on http://wiki.openvz.org/Download/template/precreated.

I want to use CentOS 5 in my virtual machines, so I download a CentOS 5 template (a default CentOS 5 template in this case):

[root@OpenVZHost ~]# cd /vz/template/cache;
[root@OpenVZHost ~]# wget http://download.openvz.org/template/precreated/contrib/centos-5-i386-default.tar.gz;

Create the new container

[root@OpenVZHost ~]# vzctl create 101 --ostemplate centos-5-i386-default --config vps.basic;

To automatically boot the container when the host machine boots:

[root@OpenVZHost ~]# vzctl set 101 --onboot yes --save;

To set a hostname and IP address for the container:

[root@OpenVZHost ~]# vzctl set 101 --hostname test.example.com --save;
[root@OpenVZHost ~]# vzctl set 101 --ipadd 192.168.0.101 --save;

Next we set the number of sockets to 120 and assign a few nameservers to the container:

[root@OpenVZHost ~]# vzctl set 101 --numothersock 120 --save;
[root@OpenVZHost ~]# vzctl set 101 --nameserver 192.168.0.1 --nameserver 4.2.2.1 --save;

Instead of using the vzctl set commands, you can as well directly edit the container's configuration file which is stored in the /etc/vz/conf directory. If the ID of the container is 101, then the configuration file is /etc/vz/conf/101.conf.

To start the container:

[root@OpenVZHost ~]# vzctl start 101;

To set a root password for the container:

[root@OpenVZHost ~]# vzctl exec 101 passwd;

You can now either connect to the container via SSH (e.g. with PuTTY), or you enter it as follows:

[root@OpenVZHost ~]# vzctl enter 101;

To leave the container's console:

[root@OpenVZHost ~]# exit;

To stop a container:

[root@OpenVZHost ~]# vzctl stop 101;

To restart a container:

[root@OpenVZHost ~]# vzctl restart 101;

To delete a container from the hard drive (it must be stopped before you can do this):

[root@OpenVZHost ~]# vzctl destroy 101;

To get a list of your containers and their status:

[root@OpenVZHost ~]# vzlist -a;
     VEID      NPROC STATUS  IP_ADDR         HOSTNAME
      101         18 running 192.168.0.101   test.example.com

To find out about the resources allocated to a container:

[root@OpenVZHost ~]# vzctl exec 101 cat /proc/user_beancounters;
Version: 2.5
       uid  resource           held    maxheld    barrier      limit    failcnt
      101:  kmemsize        1508202    1661695   11055923   11377049          0
            lockedpages           0          0        256        256          0
            privvmpages        5430       7102      65536      69632          0
            shmpages            381        381      21504      21504          0
            dummy                 0          0          0          0          0
            numproc              19         21        240        240          0
            physpages          2489       2775          0 2147483647          0
            vmguarpages           0          0      33792 2147483647          0
            oomguarpages       2489       2775      26112 2147483647          0
            numtcpsock            5          5        360        360          0
            numflock              3          4        188        206          0
            numpty                0          1         16         16          0
            numsiginfo            0          2        256        256          0
            tcpsndbuf         44720          0    1720320    2703360          0
            tcprcvbuf         81920          0    1720320    2703360          0
            othersockbuf      13144      14356    1126080    2097152          0
            dgramrcvbuf           0       8380     262144     262144          0
            numothersock         11         13        120        120          0
            dcachesize            0          0    3409920    3624960          0
            numfile             503        531       9312       9312          0
            dummy                 0          0          0          0          0
            dummy                 0          0          0          0          0
            dummy                 0          0          0          0          0
            numiptent            10         10        128        128          0

For WebSphere products, several of these parameters (found in the appropriate /etc/vz/conf configuration file) will likely need to be increased in value:

KMEMSIZE (barrier): 24000000
KMEMSIZE (limit): 32000000
PRIVVMPAGES (barrier): 262144 (=1GB @ 4KB pagesize)
PRIVVMPAGES (limit): 262144 (=1GB @ 4KB pagesize)
NUMPROC (barrier): 3200
NUMPROC (limit): 4800
NUMTCPSOCK (barrier): 3000
NUMTCPSOCK (limit): 3000
TCPSNDBUF (barrier): 2400000
TCPSNDBUF (limit): 3200000
TCPRCVBUF (barrier): 2400000
TCPRCVBUF (limit): 3200000
NUMFILE (barrier): 50000
NUMFILE (limit): 50000