How to Create an OpenVZ VPS Server on CentOS 6

Open Virtuozzo, often abbreviated as OpenVZ, is a technology for Linux systems that allows users to run isolated operating system instance, referred to as containers, virtual private servers (VPS), or a virtual environment (VE). Similar to other virtualization technology providers, OpenVZ runs multiple operating systems. However, OpenVZ uses a single Linux kernel; this means OpenVZ can only run Linux-based operating system virtualization.

Getting Started

Before we start with creating the OpenVZ VPS server and installing the web panel, make sure you have root access to your CentOS 6 server. The setup will not work properly if root access is not utilized.

Creating an OpenVZ VPS Server

Preparing the Server
Now that you’re running root access on your CentOS server, it’s time to verify that your server is up-to-date by running the following command:
yum -y update

Once you’ve confirmed that your server is current, you need to disable SELinux:
sed -i 's|enabled|disabled|' /etc/sysconfig/selinux

Installing OpenVZ
After disabling SELinux, we can start installing OpenVZ on your CentOS system. The first step for this is adding the OpenVZ repository:
wget -P /etc/yum.repos.d/ http://ftp.openvz.org/openvz.repo
rpm --import http://ftp.openvz.org/RPM-GPG-Key-OpenVZ

When the installation of the repository has completed, you can proceed with installing the OpenVZ kernel:
yum install vzkernel

Configuring the Kernel Parameters
Now it’s time to work on configuring some parameters for your server by editing the sysctl.conf file. The parameters listed below may already exist in the file, but the values should be adjusted to the illustrated values. Any parameters that are not included should be added:
nano /etc/sysctl.conf

Once you’ve adjusted the sysctl.conf file, confirm that each of the required parameters is included:
net.ipv4.ip_forward = 1
net.ipv6.conf.default.forwarding = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv6.conf.all.forwarding = 1
net.ipv4.conf.all.rp_filter = 1
kernel.sysrq = 1

After confirming the values are listed, save the file and then reload the sysctl parameters for your server:
sysctl -p

The final configuration step, now that you’ve reloaded the parameters, is to install the OpenVZ utilities:
yum -y install vzctl vzquota ploop

Reboot the Server
Now that the OpenVZ kernel has been installed, the parameters have been adjusted, and the OpenVZ utilities have been added, it’s time to reboot your server. Usually your server will reboot into the OpenVZ kernel automatically. If that is not the case, you may need to edit the grub menu and comment out the other entries.

Additionally, you can choose to enable neighbor devices using different subnets between the OpenVZ host and guests:
nano /etc/vz/vz.conf
Find out the following entry in the vz.conf file:
#NEIGHBOUR_DEVS=detect
Change it for:
NEIGHBOUR_DEVS=all

Installing the OpenVZ Web Panel
First, we need to install the web panel dependencies:
yum install rubygems ruby ruby-sqlite3.x86_64 git

Once completed, collect the installation script and hotfix it:
cd /root
wget https://raw.githubusercontent.com/sibprogrammer/owp/master/installer/ai.sh
sed -i 's|http://ovz-web-panel.googlecode.com/files/|https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/ovz-web-panel/|' ai.sh

That installation script should be run after completing the previous step:
sh ai.sh

After the installation script has completed running, it’s time to adjust the firewall rules:
nano /etc/sysconfig/iptables

The following line needs to be added to the existing iptables configuration file:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3000 -j ACCEPT

Once you’ve added the line to the iptables configuration file, the iptables service needs to be restarted for the change to take effect:
service iptables restart

Configuring the OpenVZ Web Panel
Now that OpenVZ has been installed and the web panel has been installed, it’s time to start the initial configuration of the environment. Shortly we’ll discuss acquiring virtual machine templates and setting up your web panel.

Access the OpenVZ Web Panel Interface
To begin our configuration of the web panel, use your web browser to access the following address: http://server.ip:3000

The default login credentials for http://server.ip:3000 are:
Login: admin
Password: admin

Once you’ve logged in, the default interface should resemble the following screenshot:
OpenVZ Web Panel

Change the Administrator Password
Changing the administrator account password is essential since the default password is “admin.” This generic password makes changing the default administrator password a priority.

To modify the password, click on MyProfile. During this step, you can also specify an email address and name for your account:
OpenVZ - My Profile

Once you’ve changed your password and included any optional details, you can click save to complete the reset.

Configure Your IP Addresses
Now we’re moving on to set up the IP addresses for your web panel. On the left menu click on IP Addresses

There are currently no IP addresses configured by default, so we need to add a new “IP Pool” by clicking on Create IP Pool

To provide an example, we’re going to imagine the server was assigned a few IP addresses in the form of a single subnet. For this example, we’re going to say it is 67.215.1.0/28.

We would then select 67.215.1.2 to be our new server’s primary address while keeping 67.215.1.3 through 67.215.1.14 for our virtual machines. We would populate that information in the IP Pool selection like in the below picture:

Create IP Pool

Once you’ve similarly filled in your addresses, press the create icon. This then creates your IP address pool that can be attributed to virtual machines in the future.

Configuring Operating System Templates
To correctly provision our virtual machines, we need to make sure to add operating system templates to the system.

The web panel allows you to download them in a convenient manner directly from the interface, so follow the below steps to configure these easily.

On the left navigation panel, click on localhost

This option will open the host’s server page. Click on OStemplates and you’ll be taken to the templates section, which will resemble the following screenshot:
OS templates on physical server localhost

To open the selection menu, click on Install New OS Template

A menu will open that gives you the option to select different templates to download. After making your selections, press the install icon to begin the download:
Installation of New OS Template

Allow the system to run for a few minutes while the images download. The base templates are small, so the installation process should be quick. Once the download completes, you can begin creating your first virtual machine.

Create Your First Virtual Machine
You’ve completed your deployment of your OpenVZ server and web panel, configured your IP addresses, and downloaded operating system templates, so now it’s time to deploy your first virtual machine.

To start setting up your first virtual machine, click on localhost and we’ll be taken here:

Physical Server localhost

Click through Create Virtual Server to continue setting up your virtual machine. Dialog boxes will open, prompting you to fill in details for your new machine.

During this process, you will select the operating system template you would like to use, as well as any resources you’d like to attribute to your virtual machine. You will also need to select an IP address and assign a root password to your virtual machine. The below screenshot is an example:
Create New VM

After filling in this information and documenting it someplace safe, press the create icon, and your virtual machine will generate shortly.

Congratulations! You’ve completed configuring your new OpenVZ VPS server, installed the management panel, and created your first virtual machine on your CentOS 6 server.

Conclusion

You’ve successfully created an OpenVZ VPS Server and installing the Web Panel on CentOS 6. You’re now ready to move your VPS server into production and get started with your virtual operating system desktop. If you found this guide helpful during your setup process, please share it with other users that are going through the same process or may be interested.

How to create an OpenVZ VPS server on Ubuntu 12.04

OpenVZ, short for Open Virtuozzo, is a popular virtualization technology for Linux systems that functions on the operating system-level. OpenVZ enables the setup and running of multiple operating system instances, known as virtual private servers (VPS) or containers, on one physical server. These virtual instances run isolated to each other and possess their own file systems. One limitation of OpenVZ is that all containers share the same architecture and Linux kernel version. However, due not being a true hypervisor, OpenVZ virtual private servers lack a large amount of overhead and are extremely fast. With soft memory allocation enabling efficient memory sharing between containers, OpenVZ is a useful tool for companies seeking more flexibility in their physical servers through virtualization and isolation. In order to manage various OpenVZ virtual private servers on the Linux node, OpenVZ Web Panel can be used instead of the command line in order to simplify OpenVZ management.

This tutorial will show you how you can create OpenVZ virtual private servers on your Ubuntu 12.04 Linux instance. It will also explain how to manage the created virtual private servers using the OpenVZ Web Panel so that you can best take advantage of the power of OpenVZ virtualization for your business.

Getting Started

In order to complete this guide, you will need the following:
• 1 server (Cloud Server or Dedicated Server) running Ubuntu 12.

Before proceeding, please note that all commands listed in this tutorial must be executed as the root user. You can also optionally use a user that has superuser privileges, in which case you will have to append the superuser command sudo to the beginning of every command. However, it is recommended to be signed in directly as root.

Tutorial

The first step when introducing any new software or applications to your server is always to ensure that your server is adequately prepared. First, we will ensure that the server is up to date. Using the command apt-get update, we will fetch updates available and then apply them with apt-get upgrade. apt is the default package manager for Ubuntu, and by calling it with the -y flag, we can save some time and skip a few prompts for “yes” when updating.

Make sure your server is up to date

apt-get update
apt-get -y upgrade

You will need the web utility wget in this tutorial. This utility will allow you to download files from the web If it is not already installed on your system, you can install it using apt.

apt-get -y install wget

Installing OpenVZ
With our Ubuntu system freshly updated, the server is now ready to install OpenVZ. First, we will need to create a new file for OpenVZ. Use the text editor nano to open up the new file openvz-wheezy.list. This file will contain the repository information for OpenVZ so that your Ubuntu system will know where to fetch it from:

nano /etc/apt/sources.list.d/openvz-wheezy.list

In the open file, insert the following lines containing links to the OpenVZ repository:

deb http://download.openvz.org/debian wheezy main
# deb http://download.openvz.org/debian wheezy-test main

After adding the lines, save and close the file. Next, we will need to add a key for the repository in order to be able to use it. Change directory to the root home using the command cd:

cd /root

In this directory, fetch the repository key from the OpenVZ website using the utility wget to download the file:

wget http://ftp.openvz.org/debian/archive.key

Once the file is downloaded, you can tell apt to use the new key with the following command:

apt-key add archive.key

Next, we will have to rerun apt-get update so that apt fetches the information from the new OpenVZ repository we just added as well.

apt-get update

After running the above command, we can finally install the OpenVZ kernel using apt:

apt-get install linux-image-openvz-amd64

When the OpenVZ kernel installation completes, we will have to configure some kernel parameters in the sysctl.conf file. Open the configuration file using the nano text editor:

nano /etc/sysctl.conf

Ensure that all of the following parameters are in the file. Add or modify existing parameters when necessary.

net.ipv4.ip_forward = 1
net.ipv6.conf.default.forwarding = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv6.conf.all.forwarding = 1
net.ipv4.conf.all.rp_filter = 1
kernel.sysrq = 1

Save and close the sysctl.conf file when you are finished. For your changes to take into effect, you will need to reload systctl using:

sysctl -p

Next, we will set the OpenVZ kernel to boot per default. This step is more complicated as depending on how many kernels are currently installed on your system, various parameters may have to be modified. For the purposes of our tutorial, we will consider this as a fresh install of your system.

When we installed the kernel, the kernel grub was regenerated using the new OpenVZ kernel. However by default, it is not set to boot. We will need to readjust some settings and recompile the grub for OpenVZ to boot automatically. Use the command sed to make the parameter modifications:

sed -i 's|GRUB_DEFAULT="0"|GRUB_DEFAULT="Previous Linux versions>0"|' /etc/default/grub
update-grub

Once the grub has been recompiled, we can install some OpenVZ utilities on our server using the package manager apt:

apt-get install vzctl vzquota ploop vzstats

After the installation of the packages has completed, the Ubuntu server will need to be rebooted. Having modified the default boot process, the OpenVZ kernel should be booted up automatically. If this is not the case, you may have to edit the grub menu and comment out other entries. Reboot your Ubuntu node with:

reboot

When the server is back up, log back into the root user. To verify that OpenVZ is installed, we will need to check the kernel using the command uname. Execute the following command:

uname -a

The output of the command above should show the word “OpenVZ” inside the kernel name as shown in the example below:

Linux ub12vz 2.6.32-openvz-042stab117.16-amd64 #1 SMP Fri Sep 9 22:00:20 MSK 2016 x86_64 x86_64 x86_64 GNU/Linux

Having confirmed that our OpenVZ kernel is active, we can now do the optional step of enabling neighbor devices to use different subnets between the OpenVZ host and its guests. To do this, open the vz.conf file using nano. Before proceeding, note that this step is optional and so it is entirely up to you whether you require it for your use case. Open the configuration file:

nano /etc/vz/vz.conf

In the open file, search for the following entry:

#NEIGHBOUR_DEVS=detect

Change the line to the following:

NEIGHBOUR_DEVS=all

Save and close the file. Congratulations! You’ve now completed installing OpenVZ. Keep reading in order to install the OpenVZ Web Panel on your server to manage your host’s virtual private servers.

Installing OpenVZ Web Panel

Prior to installing the OpenVZ Web Panel, we will need to install its various Ruby (a coding language) dependencies using apt:

apt-get -y install ruby1.8 rubygems1.8 ruby-net-ssh ruby-net-sftp ruby-sqlite3

Once the installation of the dependencies completes, we will fetch the install script for OpenVZ Web Panel and apply some hotfixes. First, change directory to the root home using cd:

cd /root

In the root home, use wget to download the installation script for the OpenVZ Web Panel:

wget https://raw.githubusercontent.com/sibprogrammer/owp/master/installer/ai.sh

Next, you will need to make some changes to the installation script, which we can make using the command sed to replace particular lines:

sed -i 's|http://ovz-web-panel.googlecode.com/files/|https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/ovz-web-panel/|' ai.sh

Run the installation script for the OpenVZ Web Panel:

sh ai.sh

Before proceeding, you will need to make a small adjustment to your firewall rules in order for the web panel to work. Use the command ufw allow to allow TCP connections as shown to complete the web panel installation:

ufw allow 3000/tcp

Configuring the Environment

Now that both OpenVZ and OpenVZ Web Panel are installed on your Ubuntu server, we can proceed to the initial configuration of our environment. We will begin by acquiring some virtual machine templates and setting up the web panel.

Start by accessing the OpenVZ Web Panel Interface. In a browser window, navigate to the following URL, replacing YOUR_SERVER_IP with the IP address of your server:

http://YOUR_SERVER_IP:3000

Sign into the OpenVZ Web Panel interface using the default credentials shown below:

Username: admin
Password: admin

Once you are signed in, you can change the administrator password. Keeping it as the default “admin” is highly not recommended as it greatly weakens your security setup. Instead, we will change it as quickly as possible. Follow the following steps to change your password:

1. Click on “My Profile” on the left pane of the Dashboard
2. Enter the new password two times
3. (Optional) Specify a contact name and an email address for the account
4. Click save when you are finished

After changing the default password, we can configure some IP addresses. On the lefthand menu of the OpenVZ Web Panel dashboard, cick on IP Addresses.

Since this is a clean installation, we will have no IPs configured here by default. Click on the following:
Create new IP pool

For our tutorial, we will pretend that our server has a few IPs assigned in the form of a single subnet with the addresses 67.215.1.0/28. We would then, in this case, select 67.215.1.2 to be the primary address of the server, keeping 67.215.1.3 to 67.215.1.14 for our virtual machines. Fill in the IP Pool information with the corresponding IP addresses for each server, and once filled in, press the button Create.

Your new IP addresses are now added to the system and can be used to attribute to any virtual machines we create now using OpenVZ.

To provision virtual machines for the Ubuntu server, we will now need to add some OS Templates to our system. Thanks to the OpenVZ Web Panel, these templates can be conveniently downloaded directly from the web interface. Execute the following steps:

1. Click on “Physical Server” > “localhost” on the lefthand dashboard pane
2. Click the “OS Templates” button on the top right of the physical server window
3. The next page will show all installed OS templates
4. To add new templates, click the button “Install New OS Template”
5. A popup will show all available OS templates. Select any one you choose and click “install”

After several minutes, the download of the images you select should complete. Given the small size of the base templates provided, this download should be fairly fast. Once finished, you will be able to create your first virtual machine.

To create a virtual machine, complete the following:
1. Go to “Physical Server” > “localhost” in the lefthand dashboard pane
2. Select “Create virtual server” under the menu “Virtual Servers List”
3. In the open dialog box, you will be prompted to setup a name for the virtual machine
4. Next, you can set the operating system template to use and the resources you want to attribute to the VM
5. Finally, select an IP address to use for the VM and specify its root password
6. Click “Create” to finish and spawn the VM

Conclusion

Congratulations! Not only have you installed OpenVZ on your Ubuntu node, you also have the OpenVZ Web Panel to manage your server landscape and have created your first virtual machine. If this guide was useful, why not share it?