For setting up an openvz server, first you need to change the custom kernel in the server and then install OpenVZ kernel in the node.
1. Downloading and Installing OpenVZ Kernel
a, yum pre-setup
If you want to use yum, you should set up OpenVZ yum repository first.
Download openvz.repo file and put it to your
/etc/yum.repos.d/ repository. This can be achieved by the following commands, as root:
# cd /etc/yum.repos.d
# wget http://download.openvz.org/openvz.repo
# rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ
First, you need to choose what “flavor” of the kernel you want to install. Please refer to Kernel flavors for more information.
For installing run the following command
# yum install ovzkernel[-flavor]
Configuring Boot Loader and other parameters
a, In case you use the GRUB loader, it will be configured automatically. You should only make
sure that the lines below are present in the /boot/grub/grub.conf file on the Node:
title Fedora Core (2.6.8-022stab029.1)
kernel /vmlinuz-2.6.8-022stab029.1 ro root=/dev/sda5 quiet rhgb
However, we recommend that you configure this file in the following way:
Change Fedora Core to OpenVZ (just for clarity, so the OpenVZ kernels will not be
mixed up with non OpenVZ ones).
Remove all extra arguments from the kernel line, leaving only the root=… parameter.
At the end, the modified grub.conf file should look as follows:
title OpenVZ (2.6.8-022stab029.1)
kernel /vmlinuz-2.6.8-022stab029.1 ro root=/dev/sda5
b, Once you’ve installed the kernel and the headers, you want to add a few parameters to /etc/sysctl.conf
to prep the system for running OpenVZ. For example, you need to tell the system to enable IP
forwarding so that the VPSes can have networking as well. Just add these lines to sysct.conf if they’re
not already present, or make sure they match:
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
To apply the changes issue the following command:
# sysctl -p
After installing the kernel and making these changes, you will need to reboot the system. Please set
single boot before rebooting the kernel, use the following command::
#echo “savedefault –default=0 –once” | grub –batch
Remember to replace “0” to match your own config.
SELinux should be disabled. # vi /etc/sysconfig/selinux
Add the following line to this file.
2. Downloading and Installing OpenVZ Packages
After you have successfully installed and booted the OpenVZ kernel, you can proceed with
installing the user-level tools for OpenVZ. You should install the following OpenVZ packages:
*vzctl: this package is used to perform different tasks on the OpenVZ Virtual Private
Servers (create, destroy, start, stop, set parameters etc.).
• vzquota: this package is used to manage the VPS quotas.
• vzpkg: this package is used to work with OpenVZ templates.
You can download the corresponding binary RPMs from http://openvz.org/download/utils/.
On the next step, you should install these utilities by using the following command:
# rpm –Uhv vzctl*.rpm vzquota*.rpm vzpkg*.rpm
After installation of all the above modules, Now you start the OpenVZ. Please use following
This will load all the needed OpenVZ kernel modules. During the next reboot, this script will be executed automatically.
Installing OS Templates
Template (or package set) is a set of package files to be installed into a VPS. Operating system templates are used to create new Virtual Private Servers with a pre-installed operating system.
You can also use one of the already pre-cached OS templates available at http://openvz.org/download/template/cache/ for the VPS creation. To this effect, you should download the corresponding OS template and place it to the /vz/template/cache
directory on the Node.
How to create a vps
You can use the following commands to create a vps.
First you need to select a vps id. The id 0 is used for the hardware node itself.
# vzlist -a
This command list all the vps in the host. You can create a vps using the default template or you can
define a template package and a configuration. The default creation is as follows,
# vzctl create 101
If you want to create a vps using a OS template as follows
# vzctl create 101 –ostemplate fedora-core-4 -i –config vps.basic
Here, 101: is the vp id
fedora-core-4: is the OS template
vps.basic: is the configurations defined in vps.basic.conf
#vzctl set 101 –onboot yes –save
–onboot yes : Make sure VPS boots automatically after a reboot.
### Set Hostname for VPS ###
# vzctl set 101 –hostname vps.example.com –save
### Set IP for VPS ###
#vzctl set 101 –ipadd 18.104.22.168 –save
### Set Nameservers IP for VPS ###
# vzctl set 101 –nameserver 22.214.171.124 –save
####Set user and password for the vps####
#vzctl set 101 –userpasswd root:HF%#&&TRUF%$F
####Command for setting memory limit in the Vps####
#vzctl set 101 –slmmemorylimit 1024M –save
##### Set Disk quota for VPS (10G min [soft] and 11G max hard limit) ###
#vzctl set 10 –diskspace 10G:11G –save
After compleating the above steps, now the time to start the vps.
Use the following command
#vzctl start 101