How to install OpenVZ Server in Linux


“OpenVZ is container-based virtualization for Linux. OpenVZ creates multiple secure, isolated containers 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”

Installing openvz in Linux

create a file called openvz.repo in the /etc/yum.repos.d directory.

[root@server~]# vim openviz.repo

[openvz-utils]

name=OpenVZ user-space utilities

#baseurl=http://download.openvz.org/current/

mirrorlist=http://download.openvz.org/mirrors-current

enabled=1

gpgcheck=1

gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ

# In addition to the above repo, you have to enable at least one the kernel repositories below. By default, openvz-kernel-rhel6 is enabled; you might want to change this.

## RHEL6-based OpenVZ kernels

[openvz-kernel-rhel6]

name=OpenVZ RHEL6-based stable kernels

#baseurl=http://download.openvz.org/kernel/branches/rhel6-2.6.32/current/

mirrorlist=http://download.openvz.org/kernel/mirrors-rhel6-2.6.32

enabled=1

gpgcheck=1

gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ

exclude=vzkernel-firmware

# You might need to enable debuginfo, if asked by developers

[openvz-kernel-rhel6-debuginfo]

name=OpenVZ RHEL6-based testing kernel debuginfo rpms

baseurl=http://download.openvz.org/kernel/branches/rhel6-2.6.32-testing/debuginfo

enabled=0

gpgcheck=1

gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ

Install OpenVZ
[root@server~]# yum install ovzkernel vzctl

Create a Partition Called /vz
Create a partition called /vz and enter the settings in the /etc/fstab.

Move Templates into the  /vz/template/cache/ directory.
The templates you will be using need to be moved into the template directory before you are able to build a VPS.  These pre-created templates are available from the OpenVZ site.

[root@server~]# cp centos-5-i386-default.tar.gz /vz/template/cache/

Disable SELinux
In order to set up the hardware node it is important to either not enable SELinux at installation or disable it after installation. 

Edit /etc/sysctl.conf
In order for networking to work for the virtual servers that you create, you will need to enable packet forwarding as the hardware node must forward all packets to the virtual servers. Edit the /etc/sysctl.conf file on the host.

# Controls IP packet forwarding
net.ipv4.ip_forward = 1

Once this is complete reboot your system and it will boot to the OpenVZ Kernel.  You can test if it installed correctly by using this command:

[root@server~]# vzlist -a

Create a Virtual Server with OpenVZ

Once you have OpenVZ installed you will be able to begin the process of installing individual containers.Using the vzctl command you will be able to create a virtual server in less than 5 minutes.  One of the steps that must be completed before you begin is to move the template you will use into the /vz/template/cache.

The first command uses a template and sets the configuration as a vps.basic.  The 26 is a identifier for the vps.  It makes sense to use the last octet of the IP Address for this identifier.  Thus this is used for 192.168.4.26.  In the example the centos template is used.

# vzctl create 26 – -ostemplate centos-5 –config vps.basic

Creating VE private area (centos-5-i386-default)
Performing postcreate actions
VE private area was created

This setting provides for the VE to start on boot.  This is probably what you want.  However, the default is not to start a VE on boot so if you do not use this setting it will remain off.

[root@server~]# vzctl set 26 – -onboot yes –save

[root@server~]# vzctl set 26 – -hostname admin26–save

[root@server~]# vzctl set 26 – -ipadd 192.168.4.26 –save

[root@server~]# vzctl set 26 – -nameserver 12.32.34.32 –save

[root@server~]# vzctl start 26

Starting VE …
VE is mounted
Adding IP address(es): 192.168.4.26
Setting CPU units: 1000
Set hostname: admin26
File resolv.conf was modified
VE start in progress…

[root@server~]# vzctl set 26 – -userpasswd root:bcrY67LD3 –save
Changing password for user root.
passwd: all authentication tokens updated successfully.
Saved parameters for VE 26

Now use vzlist to show which virtual servers are running.

[root@server~]# vzlist -a
VEID      NPROC STATUS  IP_ADDR         HOSTNAME
26         16 running 192.168.4.26    admin26

Cloning a Virtual Server with OpenVZ

There may be many reasons for cloning a VPS.  It could be to backup a server or it could be to have a template that makes it easy to create a new server.

Cloning a VPS to Create a New Server
a common goal would be to have a server set up exactly like you want and then clone it in less than five minutes have a new one running that is the same.  The best way to do this is to create a VPS and configure it exactly like you need.  That means you must install all of the necessary programs and modify them so they are working like you want.  Set up the security and networking as well.  Once you have a running VPS, then make sure it is turned off to clone it.

In this example, a VPS 26 is cloned to create 27.  The data that you will create for a VPS is located in the /vz/private/ directory.  Be sure to use the switch -a when you use cp as it is important in getting the permissions right.  The -a options maintains all of the archival attributes which is very important.

[root@server~]# cp -a /vz/private/26 /vz/private/27

Next you need to copy the configuration for the VPS so that all of the settings are available.  The configuration files are found in /etc/vz/conf.  Once you have copied the configuration file over you will need to edit two lines:
HOSTNAME=”admin26″
IP_ADDRESS=”192.168.4.26″

These two lines are important to set up the correct IP Address and the hostname to distinguish the virtual servers.

[root@server~]# cp /etc/vz/conf/26.conf /etc/vz/conf/27.conf

ONBOOT=”yes”

# UBC parameters (in form of barrier:limit)
# Primary parameters
AVNUMPROC=”40:40″
NUMPROC=”65:65″
NUMTCPSOCK=”80:80″
NUMOTHERSOCK=”80:80″
VMGUARPAGES=”6144: 2147483647 ″
# Secondary parameters
KMEMSIZE=”2752512:2936012″
TCPSNDBUF=”319488:524288″
TCPRCVBUF=”319488:524288″
OTHERSOCKBUF=”132096:336896″
DGRAMRCVBUF=”132096:132096″
OOMGUARPAGES=”6144: 2147483647 ″
# Auxiliary parameters
LOCKEDPAGES=”32:32″
SHMPAGES=”8192:8192″
PRIVVMPAGES=”49152:53575″
NUMFILE=”2048:2048″
NUMFLOCK=”100:110″
NUMPTY=”16:16″
NUMSIGINFO=”256:256″
DCACHESIZE=”1048576:1097728″

PHYSPAGES=”0: 2147483647 ″
NUMIPTENT=”128:128″

# Disk quota parameters (in form of softlimit:hardlimit)
DISKSPACE=”1048576:1153434″
DISKINODES=”200000:220000″
QUOTATIME=”0″

# CPU fair scheduler parameter
CPUUNITS=”1000″
VE_ROOT=”/vz/root/$VEID”
VE_PRIVATE=”/vz/private/$VEID”
OSTEMPLATE=”centos-4-i386-default”
ORIGIN_SAMPLE=”vps.basic”
HOSTNAME=”admin26″
IP_ADDRESS=”192.168.4.26″
NAMESERVER=”12.32.34.32″

Once this is complete and you have saved it you may start the VPS.

 

About Alex Hunt

Hi All I am Manish Kumar Jha aka Alex Hunt. I am currently working in VMware Software India Pvt Ltd as Operations System Engineer (vCloud Air Operations). I have around 5 Years of IT experience and have exposure on VMware vSphere, vCloud Director, RHEL and modern data center technologies like Cisco UCS and Cisco Nexus 1000v and NSX. If you find any post informational to you please press like and share it across social media and leave your comments if you want to discuss further on any post. Disclaimer: All the information on this website is published in good faith and for general information purpose only. I don’t make any warranties about the completeness, reliability and accuracy of this information. Any action you take upon the information you find on this blog is strictly at your own risk. The Views and opinions published on this blog are my own and not the opinions of my employer or any of the vendors of the product discussed.
This entry was posted in Linux/CentOS. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s