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.
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.
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 -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
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:
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:
In this directory, fetch the repository key from the OpenVZ website using the utility wget to download the file:
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.
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:
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:
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
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:
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:
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:
In the open file, search for the following entry:
Change the line to the following:
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:
In the root home, use wget to download the installation script for the OpenVZ Web Panel:
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:
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:
Sign into the OpenVZ Web Panel interface using the default credentials shown below:
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 220.127.116.11/28. We would then, in this case, select 18.104.22.168 to be the primary address of the server, keeping 22.214.171.124 to 126.96.36.199 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
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?