“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
name=OpenVZ user-space utilities
# 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
name=OpenVZ RHEL6-based stable kernels
# You might need to enable debuginfo, if asked by developers
name=OpenVZ RHEL6-based testing kernel debuginfo rpms
[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/
In order to set up the hardware node it is important to either not enable SELinux at installation or disable it after installation.
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 188.8.131.52 –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:
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
# UBC parameters (in form of barrier:limit)
# Primary parameters
VMGUARPAGES=”6144: 2147483647 ″
# Secondary parameters
OOMGUARPAGES=”6144: 2147483647 ″
# Auxiliary parameters
PHYSPAGES=”0: 2147483647 ″
# Disk quota parameters (in form of softlimit:hardlimit)
# CPU fair scheduler parameter
Once this is complete and you have saved it you may start the VPS.