Showing posts with label OpenVZ. Show all posts
Showing posts with label OpenVZ. Show all posts

Monday, February 7, 2011

Installing vzdump for OpenVZ on CentOS

There are a few items required for installing vzdump for OpenVZ on CentOS.


First, you’ll need an MTA – I suggest making sure you have postfix installed; if you have postfix installed the initial RPM requirement for “MTA” will be handled for you. Next, you’ll need cstream. This installation is slightly more tricky because (as far as I know) there is no real way to gain this from yum unless you use the DAG Wieers repo. Also, depending on what you have already installed you will likely need the Simple Locking file I/O library for Perl.


Here is how you get vzdump on a clean version of CentOS (via the hostnode):

rpm -ivh "ftp://ftp.pbone.net/mirror/ftp.freshrpms.net/pub/freshrpms/pub/dag/redhat/el5/en/x86_64/RPMS.dag/cstream-2.7.4-3.el5.rf.x86_64.rpm"wget http://dag.wieers.com/rpm/packages/perl-LockFile-Simple/perl-LockFile-Simple-0.206-1.el5.rf.noarch.rpmrpm -ivh perl-LockFile-Simple-0.206-1.el5.rf.noarch.rpm/bin/rm perl-LockFile-Simple-0.206-1.el5.rf.noarch.rpmrpm -ivh "http://chrisschuld.com/centos54/vzdump-1.2-6.noarch.rpm"

Since version 1.2-6 of vzdump the location of the modules is not “automatic” and have found it necessary to export the location of the PVE libraries that vzdump requires via this command:

export PERL5LIB=/usr/share/perl5/

Setting VPS Disk Space with OpenVZ

Disk space can be easily controlled via OpenVZ but I have yet to find anyone to actually explain what the heck to “really” do when you need to add more! Everything I have found about OpenVZ just explains the parameters and never shows you how to do it easily. When I need to adjust disk space on an VPS it is usually when I have someone beating up my ear on the phone or my IM so I needed a fast way to expand the disk without worrying about the details.

There are three parameters in OpenVZ which are directly related to disk usage. They are disk_quota, diskspace and diskinodes. NOTE: there are a lot of other parameters that control and effect the disk but this tutorial will only cover the basics!

The parameter disk_quota is a YES or NO value which disables the file system quotas; if you are not worried about the quotas set it to NO and stop reading. Otherwise; leave it set at YES and continue.

The parameter diskspace is the count of 1K blocks available to the VPS in a soft and hard limit. The hard limit is a stop point similar to filling up a physical disk – when you are out, you are out. The soft limit is when the bean counters get angry and the quotatime timer starts. On a basic installation and VPS setup you will have a 1048576 1K blocks as a soft limit and 1153024 1K blocks as a hard limit. The numbers are not crazy as they are derived from base2. Thus, 1048576 1K blocks is 1GB of disk space. Add an additional 10.2MB to the disk space and you arrive at the 1048576 1K blocks. These are the basic numbers for the basic template that ships with OpenVZ.

The parameter diskinodes is the total number of files, directories and links you can have in the container. Think of them as Post-it® notes and each file, directory and link gets a single note. The default basic number is 200,000 for a soft limit for 1GB of disk space and 220,000 for the hard limit. Normally *nix systems will set aside enough inodes for one inode per 4K disk space block. In the default template for OpenVZ they are setting aside enough inodes for 5.2K blocks. Which I’ll write off as either (a) a magic number or (b) a unique calculation I am not familiar with. Thus, because the 4K block inode count for 1GB of disk space should be 262,144 inodes we’ll use the default template values for our calculations and simply multiply times the number of GB requested.

So…

Now…

The question is how do you adjust them quickly and easily. In this example we are going to work with units of GBs. If you need more granularity you will need to divide it back out to MBs but Gigabytes works great for our needs:

First, we need to define the soft and hard limits, next we apply the updated diskspace numbers and finally set the inode numbers correctly based on the ratio we know from the default template:

Here are the commands (and note below for a quick and easy Perl script):

cid=1324gb=5vzctl set ${cid} --diskspace $((1048576 * ${gb})):$((1153434 * ${gb})) --savevzctl set ${cid} --diskinodes $((200000 * ${gb})):$((220000 * ${gb})) --save#!/usr/bin/perl # display the commands to update an OpenVZ VPS with new disk space requirements# 2009/11/15 - Chris Schuld (chris@chrisschuld.com) use strict; print "Enter VPS CID: "; my $_CID = ; chomp($_CID);print "Enter SOFT Diskspace Limit (ex 10GB):"; my $_SOFT = ; chomp($_SOFT); $_SOFT =~ s/[^0-9]//g;print "Enter HARD Diskspace Limit (ex 11GB):"; my $_HARD = ; chomp($_HARD); $_HARD =~ s/[^0-9]//g;my $_INODE_SOFT = ( 200000 * $_SOFT );my $_INODE_HARD = ( 220000 * $_HARD );print "Run these commands:\n";print "vzctl set $_CID --diskspace ".$_SOFT."G:".$_HARD."G --save\n";print "vzctl set $_CID --diskinodes $_INODE_SOFT:$_INODE_HARD --save\n";

Tuesday, August 24, 2010

Installing And Using OpenVZ On Ubuntu 10.04

Follow me on Twitter
Last edited 08/18/2010

In this HowTo I will describe how to prepare an Ubuntu 10.04 server for OpenVZ. With OpenVZ you can create multiple Virtual Private Servers (VPS) on the same hardware, similar to Xen and the Linux Vserver project. OpenVZ is the open-source branch of Virtuozzo, a commercial virtualization solution used by many providers that offer virtual servers. The OpenVZ kernel patch is licensed under the GPL license, and the user-level tools are under the QPL license.

This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web.

This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

I'm using an x86_64 (amd64) system here. If you are on an i386 system, a few commands will be slightly different - I have added annotations to that parts.

 

2 Become root

Type

sudo su

to become root (or prepend all commands in this tutorial with the string sudo).

 

3 Change The Default Shell

/bin/sh is a symlink to /bin/dash, however we need /bin/bash, not /bin/dash. Therefore we do this:

dpkg-reconfigure dash

Install dash as /bin/sh? <-- No

 

 

4 Disable AppArmor

AppArmor is a security extension (similar to SELinux) that should provide extended security. In my opinion you don't need it to configure a secure system, and it usually causes more problems than advantages (think of it after you have done a week of trouble-shooting because some service wasn't working as expected, and then you find out that everything was ok, only AppArmor was causing the problem). Therefore I disable it.

We can disable it like this:

/etc/init.d/apparmor stop
update-rc.d -f apparmor remove
apt-get remove apparmor apparmor-utils

 

5 Installing OpenVZ

Unfortunately there are no OpenVZ packages in the official Ubuntu 10.04 repositories, therefore we have to build the OpenVZ kernel and the OpenVZ tools (vzctl, vzquota, vzpkg) ourselves.

First, run

uname -r

to find out your currently installed kernel version:

root