Guide

How to Install OpenVZ 7 on CentOS 7

A complete guide to convert CentOS 7 server to OpenVZ host node
Pinterest LinkedIn Tumblr

This tutorial shows you how to install OpenVZ 7 a.k.a Virtuozzo 7 on CentOS 7 x86_64 node server.

It is basically easier and cleaner to install OpenVZ 7 from scratch using its ISO image file.

However, sometimes you may simply need to convert existing CentOS 7 OS to OpenVZ. This involves installing OVZ latest kernel.

Commonly, OpenVZ is used by many providers for its flexibility in cramming many containers in a single host node.

OpenVZ is a Linux-based operating-system-level virtualization technology.

OVZ allows a physical server to run multiple isolated OS instances, called containers, virtual private servers, or virtual environments.

Each container performs and executes exactly like a stand-alone server. You can reboot a container independently.

Each container can have root access, users, IP addresses, memory, processes, files, applications, system libraries and configuration files. It’s a virtual machine!

Unlike KVM which is a kernel-level virtualization, OVZ with its container technology allows better server utilization.

It’s not a fully dedicated separate OS container. Instead, we are not installing a full virtual machine but just a container to hold some of it.

OpenVZ uses a shared kernel with a layer of virtualization.

Here’s how to install it on CentOS 7 server.

Prerequisites

Make sure you have:

  • A Dedicated, local, or virtual server
  • CentOS 7 x86_64 distro
  • If you are on VPS, make sure it has Intel AES-NI or VM-x/AMD-V enabled
  • A clean minimal CentOS 7 is recommended
  • Make sure you have ext4 drive partition format

How to Convert CentOS 7 to OpenVZ 7

First, log in to your CentOS 7 server via SSH connection. Putty does a good job for this.

You can log in as a user with sudo privilege or simply log in as root.

Second, as usual, do a yum update.

yum update && yum upgrade

Third, install wget and nano editor to make everything easier.

yum install -y wget && yum install -y nano

Next, we need to install python sub-processes, the latest OpenVZ 7 release, and Epel repository using this command:

yum localinstall https://download.openvz.org/virtuozzo/releases/openvz-7.0.11-235/x86_64/os/Packages/p/python-subprocess32-3.2.7-1.vz7.5.x86_64.rpm
yum localinstall https://download.openvz.org/virtuozzo/releases/openvz-7.0.11-235/x86_64/os/Packages/o/openvz-release-7.0.11-3.vz7.x86_64.rpm
yum install epel-release -y

Now let’s install the vzlinux release. Issue these lines of command:

yum install python3
rpm -Uvh http://repo.virtuozzo.com/vzlinux/7/x86_64/os/Packages/r/readykernel-scan-0.11-1.vl7.noarch.rpm
rpm -Uvh http://repo.virtuozzo.com/vzlinux/7/x86_64/os/Packages/z/zstd-1.4.4-1.vl7.x86_64.rpm
rpm -Uvh http://repo.virtuozzo.com/vzlinux/7/x86_64/os/Packages/v/vzlinux-release-7-1.vl7.91.x86_64.rpm

Next, we have to move CentOS repositories to another location. This is useful to avoid package conflicts in the future. Use this command:

mv /etc/yum.repos.d/CentOS-* /root/

Then, remove any existing json-c and jansson packages so we can reinstall them using the ones from Virtuozzo repo:

rpm -e --nodeps --justdb json-c
yum erase jansson
yum localinstall http://repo.virtuozzo.com/vzlinux/7.7/x86_64/os/Packages/j/jansson-2.10-1.vl7.1.x86_64.rpm
yum localinstall http://repo.virtuozzo.com/vzlinux/7.7/x86_64/os/Packages/j/json-c-0.11-13.vl7.1.x86_64.rpm

Next, reinstall the necessary packages. This single line of command will do:

yum install prlctl prl-disp-service vzkernel *ploop*

This gonna take some time. Wait till the process done.

Now update the node:

yum update -y

Finally, issue this command to list all available boot options in grub:

awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg

You will see something like this:

Choose the option number that is OpenVZ kernel.

Change 1 in the command below to the number you see on your screen. Example: 0.

grub2-set-default 1
grub2-mkconfig -o /boot/grub2/grub.cfg
awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg

Alternatively, use this special step if you are on OVH Dedicated servers. You also need to generate the grub.cfg file:

mkdir /boot/efi/EFI/virtuozzo/
grub2-mkconfig -o /boot/efi/EFI/virtuozzo/grub.cfg

You can now reboot your server:

reboot

Initial OpenVZ7 Settings

Follow these basic setup after installing OpenVZ 7 on your CentOS 7 server.

First, enable ploop kernel modules. Issue all these lines of command:

modprobe ploop
modprobe pfmt_ploop1
modprobe pfmt_raw
modprobe pio_direct

Second, edit the OpenVZ 7 kernel parameter configuration.

nano /etc/sysctl.conf

Third, add the following lines of code:

# 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

#only use these if you build a NAT VPS
#otherwise, do not copy these lines
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.default.forwarding= 1

Save the configuration and exit Nano editor. Press Control+O then Control+X on keyboard.

Then issue this command:

sysctl -p

Next, make SELinux act permissive to ensure that OpenVZ works fine. If you want, you can leave it disabled also.

nano /etc/sysconfig/selinux

Change the SELINUX=permissive line. Save and exit Nano editor.

We can also install the OpenVZ usage statistics tools if needed:

yum -y install vzctl vzquota ploop

Next, edit the OpenVZ configuration file to set the same subnet for physical and virtual machines. Edit the vz.conf file:

nano /etc/vz/vz.conf

Set the NEIGHBOUR_DEVS line to all. You may need to add it if the line isn’t there already.

NEIGHBOUR_DEVS=all

Save and exit Nano editor.

Next, it’s a good habbit to reboot the server so that everything works as expected.

reboot

Finally, you can install all available Linux Distro templates by issuing this command:

yum install *ez.noarch

That’s all. Now you created an OpenVZ host node. You can now create many virtual machines (VM) depending on hardware specs of the host node server.

A blogger by hobby. He is an ordinary worker at day, a hybrid sys-admin at night. Sharing knowledge through blogs is his passion. He likes ice cream BTW.

Write A Comment