Thursday, March 12, 2015

[Quick Install]: Install And Configure OpenVZ

Install And Configure OpenVZ On CentOS

About OpenVZ

OpenVZ is a container-based virtualization solution for Linux. We can create ‘n’ number of Virtual machines depending upon the configuration of our physical system. Each virtual machine will act like a separate standalone physical system, and doesn’t conflict with one another. The virtual machines created using OpenVZ can be rebooted independently, and have root access, users, IP addresses, memory, processes, files, applications, system libraries and configuration files. Since it uses operating system level virtualization technology, unlike other virtualization methods such as VirtualBox, KVM, and Vmware, the guest systems uses the same kernel of the host system. Each virtual machine will efficiently share the CPU, Memory, Disk space, and network of your Physical server.

Installing OpenVZ on CentOS 6.5

System Requirements:

  • A decent Intel or AMD PC;
  • Atleast 128MB of RAM;
  • Hard drives with atleast 4GB free disk space;
  • Atleast 2NICs;
  • Internet connection.
It is recommended to use a separate partition for containers (by default /vz) and format it to ext4. You need to have set two IP addresses to your physical machine. One is for the original host and another IP is for Virtual machine.

1. Add OpenVZ Repository

Download OpenVZ Repository and put it in /etc/yum.repos.d/ directory.
yum install wget
wget -P /etc/yum.repos.d/ http://ftp.openvz.org/openvz.repo
Import OpenVZ GPG key:
rpm --import http://ftp.openvz.org/RPM-GPG-Key-OpenVZ

2. Install OpenVZ kernel

yum install vzkernel

3. Setting up Kernel parameters

Make sure you have added the following kernel parameters before logging into vz kernel.
vi sysctl.conf
Add the following lines:
# 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

4. Disable SELinux

Edit /etc/sysconfig/selinux file:
vi /etc/sysconfig/selinux
Set as disabled:
SELINUX=disabled

5. Install OpenVz usage statistics tools

The following tools to be installed to gather the OpenVZ usage statistics. Here is the reason why you should install these tools.
yum install vzctl vzquota ploop
That’s it. We have successfully installed OpenVZ.
Now, it’s time to reboot and log in to OpenVZ kernel(it should be the default choice in the boot loader).
CentOS 6.5 OpenVZ [Running] - Oracle VM VirtualBox_001
We’ll see how to create virtual machines using OpenVZ in our upcoming tutorials.
While creating VMs, make sure you have the same subnet on both physical and virtual machine. If you want to use different subnet, you have to edit /etc/vz/vz.conf file,
vi /etc/vz/vz.conf
Find and uncomment the line:
NEIGHBOUR_DEVS=detect
And, change it to:
NEIGHBOUR_DEVS=all
That’s it.
 ===============================================

Install And Configure OpenVZ In Ubuntu

In this tutorial, we will see how to install OpenVZ in Ubuntu 14.04.

1. Add OpenVZ Repository

Switch to root user:
sudo su
First, we will add OpenVZ Repository.
cat << EOF > /etc/apt/sources.list.d/openvz-rhel6.list
deb http://download.openvz.org/debian wheezy main
# deb http://download.openvz.org/debian wheezy-test main
EOF
Import OpenVZ GPG key:
wget http://ftp.openvz.org/debian/archive.key
apt-key add archive.key

2. Install OpenVZ kernel

apt-get install linux-image-openvz-amd64
Or, if you still have i686:
apt-get update && apt-get install linux-image-openvz-686

3. Setting up Kernel parameters

Make sure you have added the following kernel parameters before logging into vz kernel.
vi sysctl.conf
Add the following lines:
# 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

5. Install OpenVz usage statistics tools

The following tools to be installed to gather the OpenVZ usage statistics. Here is the reason why you should install these tools.
apt-get install vzctl vzquota ploop vzstats
That’s it. We have successfully installed OpenVZ.
Now, it’s time to reboot and log in to OpenVZ kernel(it should be the default choice in the boot loader). In Ubuntu 14.04, it should be under Advanced options in the boot loader menu.
Ubuntu 14.04 [Running] - Oracle VM VirtualBox_003
Ubuntu 14.04 [Running] - Oracle VM VirtualBox_002
We’ll see how to create virtual machines using OpenVZ in our upcoming tutorials.
While creating VMs, make sure you have the same subnet on both physical and virtual machine. If you want to use different subnet, you have to edit /etc/vz/vz.conf file,
vi /etc/vz/vz.conf
Find and uncomment the line:
NEIGHBOUR_DEVS=detect
And, change it to:
NEIGHBOUR_DEVS=all
That’s it.


OpenVZ Home page:
 --------------------------

OpenVZ Web Panel: Managing OpenVZ Containers Graphically


In this tutorial, let us see how to manage OpenVZ using OpenVZ web panel.

Why OpenVZ Web panel?

Very simple, just to make the OpenVZ management more easier. Working on command line might be tedious to new and intermediate users. Using openVZ Web panel, anyone can easily create, delete, manage VMs via a web browser in minutes without having to know all OpenVZ commands.

Installing OpenVZ Web panel

Well, let us install the Web panel.
Run the following command under root user to install OpenVZ Web Panel:
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh
The above command will work on almost all Linux operating systems.
Sample output:
 Removing downloaded archive: rm -f /opt/ovz-web-panel//ovz-web-panel-2.4.tgz
 Installation finished.
 Product was installed into: /opt/ovz-web-panel/
 [...]
 Starting services...
 Starting OpenVZ Web Panel...
 Starting watchdog daemon...
 [OK] Watchdog daemon was started.
 Starting web server webrick on 0.0.0.0:3000...
 [OK] Web server was started.
 Starting hardware node daemon...
 [OK] Hardware node daemon was started.
 Syncing hardware nodes states...
 [OK] Hardware nodes information was synced.
 Adding localhost to the list of controlled servers...
 Panel should be available at:
 hostname: Unknown host

http://:3000

 Default credentials: admin/admin
 -----------------------------------
That’s it. OpenVZ Web panel has been installed now.

Adjust IPTABLES for RPM based distributions

If you’re accessing the URL from a remote system, you should allow the web panel default port 3000 through your firewall/router.
To do that edit:
vi /etc/sysconfig/iptables
Add the following line:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3000 -j ACCEPT
Save and exit. Restart iptables service.
service iptables restart

Accessing OpenVZ Web panel

Open up your web browser and enter the following URL in the address bar.
http://<your-host>:3000
Default administrator’s credentials are: admin/admin. Don’t forget to change default password.
Login - OpenVZ Web Panel 2.4 - Mozilla Firefox_001
Now, you’ll be redirected to the OpenVZ web panel dashboard:
Dashboard - OpenVZ Web Panel 2.4 - Mozilla Firefox_002
The Dashboard will have the information about logged user and statistics of panel usage. By default, the physical server is localhost itself. Also, it is possible to many physical servers without having to install Web panel on every physical server.

Changing Default Admin user password

As I mentioned before, the default user name and password to login to Wen panel is admin/admin. It is hightly recommended to change the admin user password to something different and stronger.
To do that, Click on the My Profile on the left pane of the Dash board. Enter the new password twice and click the Save button.
IP Addresses - OpenVZ Web Panel 2.4 - Mozilla Firefox_007
Now, let us see how to create Virtual machines, Virtual servers, and users etc.

Download And Install OS Templates

Before creating Virtual machines or VPS, the first step is to install OS templates.
To do that, click on the Physical server (localhost) on the left pane of the Dashboard. Then, click on the OS Templates button on the right side.
Physical Server localhost - OpenVZ Web Panel 2.4 - Mozilla Firefox_003
The installed OS templates will be listed here. As you see above I have already installed a CentOS 7 template. To create a new Template, click on the Install New OS Template button.
OS Templates on Physical Server localhost - OpenVZ Web Panel 2.4 - Mozilla Firefox_004
The list of available OS templates will be shown in the next window. Select the OS template of your choice and click Install button. In my case, I selected Ubuntu 14.04 minimal template.
OS Templates on Physical Server localhost - OpenVZ Web Panel 2.4 - Mozilla Firefox_005
The installing process will be scheduled and new templates will be appeared soon.
OS Templates on Physical Server localhost - OpenVZ Web Panel 2.4 - Mozilla Firefox_006
After few minutes(depending upon the size of the template), refresh the OS templates list. You’ll, there, see the newly installed OS templates.
OS Templates on Physical Server localhost - OpenVZ Web Panel 2.4 - Mozilla Firefox_008
As you see above, the Ubuntu 14.04 OS template has been installed now.

Creating Virtual Servers

We have installed the OS templates in our previous steps. Now, we will create new Virtual servers using the OS templates.
Go back to the localhost (Just click on the localhost button under the Physical Servers section) window. Click Create New Virtual Server button.
Physical Server localhost - OpenVZ Web Panel 2.4 - Mozilla Firefox_009
Enter the Server ID, select the OS template, enter IP address and hostname, enter the root password etc. Also, you can define the disk space size, RAM, Swap, DNS server etc,, in the Additional Settings. I go with default values. Finally, click Create button.
Physical Server localhost - OpenVZ Web Panel 2.4 - Mozilla Firefox_011
Hurray! We have created a new Virtual server.
Physical Server localhost - OpenVZ Web Panel 2.4 - Mozilla Firefox_012
If you don’t want the Virtual server, select the Virtual server, and click Remove Virtual server button.
Physical Server localhost - OpenVZ Web Panel 2.4 - Mozilla Firefox_013
Also, you can change the settings of the Virtual server by clicking on the Change Settings button next to the Remove Virtual Server button. And, you also can start/stop/restart the virtual server using the Change state button next to the Change Settings button..

Creating Server Templates

Server templates are used as a source of quality of service limits during virtual server creation. They could be used to simplify new virtual servers creation for different purposes. You can create, edit and remove templates, but, you can’t remove the default template for the physical server.
Click on the localhost button under the Physical Servers section on the left pane of the Dashboard. Then, click Server Templates on the right side.
Physical Server localhost - OpenVZ Web Panel 2.4 - Mozilla Firefox_014
The list of available Server Templates will be shown. Select the template of your Choice and Click Add Template button.
Server Templates on Physical Server localhost - OpenVZ Web Panel 2.4 - Mozilla Firefox_015

Adding more Physical servers

As I mentioned before, the localhost itself is the default Physical server. You can add more physical server if you want. You don’t have to install OpenVZ web panel on extra physical servers.
To add an extra physical server, click on the Physical Servers button on the left pane of the Dashboard. Then, click Connect new server button.
Physical Servers - OpenVZ Web Panel 2.4 - Mozilla Firefox_016
Enter the hostname, and root password of the new OpenVZ server. Then, click Connect.
Physical Servers - OpenVZ Web Panel 2.4 - Mozilla Firefox_017
New virtual servers or OS templates can be installed directly on the server using command line tools. In such case need to select physical server and click “Synchronization” button to perform synchronization between panel’s database and actual state of the server.

Creating Users

By default, there will be two users automatically created while installing OpenVZ. One is admin, the infrastructure administrator, and the another is virtual server owner. If you want new users, you can add them too. Also, you can assign any user as a owner to any VPS. The owners can manage, edit the particular VPS details.
To create a new user, Click on the Users button on the left. Then, click Add user.
Users - OpenVZ Web Panel 2.4 - Mozilla Firefox_019
Fill up the user details, and select the role of the new user(infrastructure owner or Virtual server owner). Finally, click Create.
Users - OpenVZ Web Panel 2.4 - Mozilla Firefox_020
Now, we can assign the new user to any VPS.
Physical Server localhost - OpenVZ Web Panel 2.4 - Mozilla Firefox_021

Viewing Event logs

Event logs will give you the recent activities of the OpenVZ server.
Events Log - OpenVZ Web Panel 2.4 - Mozilla Firefox_022

Conclusion

In this series of tutorials, we have seen how to install and configure OpenVZ on CentOS and Ubuntu systems. Also, we have seen how to create and manage VMS both in text and graphical mode methods. As far as I know, OpenVZ will be very useful in development environments and other R&D departments that are using multiple and different kind of Virtual machines. You can easily create, edit, delete VM in minutes using OpenVZ within minutes. Hope this tutorial series will give you a basic usage and ideas about OpenVZ. 

For more details, refer the OpenVZ official website.

OpenVZ Web Panel Home page:

No comments: