Since I am now testing VirtualBox performance, I need to clone existing guest image for multi-testing. This mini-HOWTO will guide you though the procedure for cloning a guest storage file for a new guest, under MS Windows host.
When following the official guideline and document, using VBoxManage clonehd command for disk clone, the result image is ALWAYS not functioning. Finally I figure out that a non-documented internal command is required: VBoxManage internalcommands sethduuid.
Within this artical, I am using the following system setup:
VirtualBox: v2.1.0
Host: MS Windows Vista Home Basic
Guest: Debian Lenny
Official procedure for cloning disk image (not function on MS Windows host)
Cloning an existing disk image for VirtualBox is much more than a simple copy command: it is because VirtualBox assigns a unique identity number (UUID) to each disk image, which also stored inside the image. VirtualBox will refuse to work with two image that use the same number. You need some extra handling.
According to official document, what you need is the console command VBoxManage clonehd, e.g. (host with MS Windows):
"C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe" clonehd hda.vdi hdb.vdi
or (host with Linux):
VBoxManage clonehd hda.vdi hdb.vdi
Therefore VirtualBox will copy your disk image, assign a new UUID for it, and import to its virtual media manager. You can now use it for your new guest system.
Alternative non-documented solution
As now you understand how the vboxmanage clonehd work around, what we needed is a new-and-unique UUID for our cloned disk image. There is a non-documented internal command which target for this procedure: VBoxManage.exe internalcommands sethduuid.
So what you needed for are:
(Optional) Shutdown your target guest before disk clone.
Manually copy the existing disk image, e.g.
copy hda.vdi hdb.vdi
Set a new UUID for the cloned disk, e.g.
"C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe" internalcommands sethduuid hdb.vdi
Manually add this newly cloned disk image though VirtualBox "Virtual Media Manager".
Create a new guest profile as old system, and point the primary harddisk to your newly cloned disk image.
(Document is retrieved from Google cache http://209.85.229.132/search?q=cache:http://edin.no-ip.com/content/clone-virtualbox-disk-image-ms-windows-mini-howto )
Thursday, October 29, 2009
Monday, October 19, 2009
Managing Disk space with OpenVZ
You can increase the limit from the host system (VE0) only. This is how:
1. Get the current values for disk quota:
# vzquota stat 123
resource usage softlimit hardlimit grace
1k-blocks 327664 1048576 1153434
inodes 18857 200000 220000
2. To increase the disk space quota, use vzctl set --diskspace. For example, we want to increase it by a factor of 2:
vzctl set 123 --diskspace $(( 1048576*2 )):$(( 1153434*2 )) --save
3. To increase the disk inodes quota, use vzctl set --diskinodes. For example, we want to increase it by a factor of 3:
vzctl set 123 --diskinodes $(( 200000*3 )):$(( 220000*3 )) --save
Note: shell does not support floating-point arithmetics, i.e. you can not use expressions like $(( 220000*1.5 )). To use floating point, try bc instead, something like this: $(echo 220000*1.5 | bc).
Disk space and inodes are different things. Inodes identify the physical location on a disk where a file resides in unix filesystems. The inode count reflects the number of files on the server, not the amount of space used. This allows for multiple paths (hard links) to point to a single file.
1. Get the current values for disk quota:
# vzquota stat 123
resource usage softlimit hardlimit grace
1k-blocks 327664 1048576 1153434
inodes 18857 200000 220000
2. To increase the disk space quota, use vzctl set --diskspace. For example, we want to increase it by a factor of 2:
vzctl set 123 --diskspace $(( 1048576*2 )):$(( 1153434*2 )) --save
3. To increase the disk inodes quota, use vzctl set --diskinodes. For example, we want to increase it by a factor of 3:
vzctl set 123 --diskinodes $(( 200000*3 )):$(( 220000*3 )) --save
Note: shell does not support floating-point arithmetics, i.e. you can not use expressions like $(( 220000*1.5 )). To use floating point, try bc instead, something like this: $(echo 220000*1.5 | bc).
Disk space and inodes are different things. Inodes identify the physical location on a disk where a file resides in unix filesystems. The inode count reflects the number of files on the server, not the amount of space used. This allows for multiple paths (hard links) to point to a single file.
A guide to running OpenVZ
By Joe 'Zonker' Brockmeier
One of the many virtualization options for Linux is OpenVZ, the free software component of SWsoft's Virtuozzo. OpenVZ, and Virtuozzo, are OS-level virtualization solutions that allow you to partition servers into multiple virtual private servers (VPS). Plowing through the OpenVZ documentation can be a bit intimidating, so let's walk through the easy way of getting started with OpenVZ on a Debian Etch system.
Last year, I reviewed Virtuozzo 3.0 for Linux, and I'd had some hands-on experience with prior versions of Virtuozzo from my days working with a hosting company in Denver. My budget doesn't have room for the Virtuozzo licensing, but OpenVZ fits my pocketbook just fine.
When would you want to use OpenVZ rather than VMware Server or Xen? It depends on the situation. For tasks where you don't want to run multiple OSes, but rather just multiple guests, in order to make the most of hardware or provide separation between services (for instance, separating your Web server from your file and print server) with minimal overhead, OpenVZ is a good choice. However, when you want to run non-Linux operating systems (such as FreeBSD or Windows Server) on top of a Linux host, you'd want to go with VMware rather than OpenVZ (or its commercial and proprietary big brother, Virtuozzo), since OpenVZ doesn't offer the ability to run multiple OSes.
OpenVZ also supports more processor platforms than the alternatives. VMware Server and Xen are available for x86 and AMD64, while OpenVZ is available for x86, AMD64, Itanium (IA64), PowerPC, and UltraSPARC.
Note that there are no pre-built PowerPC kernels for Debian at the moment, but OpenVZ is supported on PowerPC.
Installing OpenVZ
You can run OpenVZ guests on any host system. I'm running my guests on a Debian system, but you can use Ubuntu, Fedora Core, Gentoo, or any other distro that has an OS template. The OS template is the set of packages used to populate a VPS, AKA virtual environment (VE) in OpenVZ lingo.
Debian kernels for OpenVZ guests are available from the OpenVZ repository, but only for Etch. Grab the most recent kernel and linux-headers package from the OpenVZ repository, and install them using
dpkg -i linux-image-2.6.18-openvz-686_02_i386.deb
and
dpkg -i linux-headers-2.6.18-openvz-686_02_i386.deb .
Replace the package name with the name of the file that you download, of course. When I installed the packages, dpkg complained about two symlinks pointing to missing directories, but I haven't seen any problems while using OpenVZ, so as far as I can tell this isn't a problem.
Once you've installed the kernel and the headers, you'll want to add a few parameters (found on the the OpenVZ wiki) to /etc/sysctl.conf to prep the system for running OpenVZ. For example, you need to tell the system to enable IP forwarding so that the VPSes can have networking as well. Just add these lines to sysct.conf if they're not already present, or make sure they match:
net.ipv4.ip_forward = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.all.rp_filter = 1
kernel.sysrq = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
After installing the kernel and making these changes, you'll need to reboot the system. The OpenVZ kernel should be set to the default kernel in the GRUB menu already, so just rebooting should do the trick.
Next, you'll need to grab the OpenVZ utilities, using apt-get install vzctl. This will install the vzctl and vzquota packages, which include the utlities (like vzctl) that you need to use to manage OpenVZ.
OpenVZ will be set to start up at boot after you install these utilities, but if you want to start playing right away, you need to start up OpenVZ manually this time (or reboot). Start up OpenVZ by running the init script:
/etc/init.d/vz start
Setting up a guest system
So far so good. Now it's time to grab a few templates and set up a guest operating system. You can find precreated templates on the OpenVZ download site, including several versions of Fedora Core, Debian Sarge and Debian Etch, CentOS, Gentoo, Mandriva, and openSUSE. Note that templates are processor-specific, so be careful not to download the AMD64 or UltraSPARC version of a template if you're going to be running it on a x86 system.
You'll also notice that there's a contrib directory with OS templates from the OpenVZ community. These aren't "official" templates, but if you want to run Ubuntu, Slackware, AltLinux, or another distro not found with the OpenVZ templates, look here.
If you want to run a distro that doesn't have a template, see the OpenVZ wiki for documentation on creating OS templates. This is one area where OpenVZ is at a disadvantage to VMware and some of the other virtualization technologies. Installing a Linux distro in VMware Server or VMware Workstation is usually as simple as running through that distro's installation procedure. In OpenVZ it's much more complicated, and you'll need to learn a lot more about OpenVZ than you might want to just to run a couple of guest instances.
Downloaded OS templates need to be stored in /var/lib/vz/template/cache. The templates are tarred and gzipped when you download them, and you want to leave them that way -- don't uncompress them.
To set up a system, use the vzctl utlity. The bad news is that the vzctl utility is nowhere near as easy to use as the GUI tools that come with Virtuozzo. The good news is that vzctl isn't that difficult to use, it's scriptable, and it's free in every sense of the word. If you manage a lot of OpenVZ systems, you'll have the syntax down in no time, and if you don't create or muck with your OpenVZ guest systems very often, it shouldn't be too time-consuming to whip out the vzctl utlity man page and figure out the options you want. Let's take a look at the most common commands.
The syntax for creating a guest system is vzctl create vpsid --ostemplate ostemplatename . The vpsid is the number assigned to the new system. OpenVZ reserves IDs below 100 for internal use, so I usually start assigning IDs at 1001. So, for instance, if you download the Debian Sarge OS template for x86, you'd run:
vzctl create 1001 --ostemplate debian-3.1-i386-minimal
Once a guest host is set up, you can find its filesystem under /var/lib/vz/root/vpsid, and its private area under /var/lib/vz/private/vpsid -- unless you change the defaults using the --root or --private options. The private directory contains files specific to the virtual environment (VE).
So, if you created the guest as vz number 1001, its root filesystem would be under /var/lib/vz/root/1001. This may come in handy if you ever need to access the files directly for some reason -- for example, if the guest's admin has made a configuration that prevents the guest from booting normally -- or for backup purposes.
Now, let's set up networking. Again, this isn't terribly difficult:
vzctl set --ipadd ipaddr --nameserver nameserverIP --hostname hostname --save
The --ipadd parameter assigns the IP address to the first venet interface in the guest OS, the --hostname assigns the VPS its hostname, and the --nameserver paramter provides the first nameserver. The venet interface provided to OpenVZ guest systems by default does not have a MAC address, which means that (among other things) you cannot grab an address via DHCP for an interface.
However, the OpenVZ folks have added a new type of interface called a veth, which can provide a MAC address. The veth device also allows users to set up a DHCP server within the guest OS, and users can set their own network settings -- which is not possible using the venet devices. Whether this is desirable is another question. If you'd like to provide veth interfaces rather than venet interfaces, see the OpenVZ wiki for setup instructions.
Managing OpenVZ
Once the VPS is set up, go ahead and start the guest by running vzctl start vpsid , where vpsid is the ID that you assigned to the guest when you created it.
You should see a few messages logged to the console about starting the VPS, ending with "VPS start in progress..." You can see what VPSes are running with the vzlist command. After running vzlist, you should see something like this:
VPSID NPROC STATUS IP_ADDR HOSTNAME
1002 4 running 10.0.1.34 vroomfondle
Use the -a option to display all VPSes, whether they are running or not. You might also want to see what resources are being consumed by a VPS. To see how much memory is being used by a VPS, run
vzcalc -v vpsid
You should see something like this:
Resource Current(%) Promised(%) Max(%)
Low Mem 0.13 1.20 1.20
Total RAM 0.55 n/a n/a
Mem + Swap 0.36 1.83 n/a
Alloc. Mem 0.67 1.83 13.82
Num. Proc 0.06 n/a 0.40
--------------------------------------------------------------
Memory 0.67 1.83 13.82
This will show you how much memory is being used by the VPS, how much is allocated to the VPS, and what it can grow to.
You can also see other VPS parameters using the -o option. See the vzcalc man page for more information.
By default, VPSes will not be started up when you boot the system. In most situations, though, you probably do want VPSes to load after a system has restarted. You can change this setting using vzctl:
vzctl set vpsid --onboot yes --save
The vzctl utility is also used to set system parameters, including the amount of memory, CPU resources, access to iptables modules, and more. Let's look at a few examples.
One of the things that is frustrating about OpenVZ is that it's not straightforward to say "give a VPS 256MB of RAM"; instead, you have to adjust a couple of parameters and read through some fairly technical docs to try to make sense of the way that OpenVZ deals with memory.
To make things a bit simpler, let's look at setting a VPS with a minimum of 256MB of RAM, and up to 1GB. To do that, set the vmguarpages (that's the memory that's guaranteed to the VPS) and privvmpages (that's the maximum amount of memory that will be granted) parameters:
vzctl set vpsid --vmguarpages 65536 --save
vzctl set vpsid --privvmpages 262144 --save
I found another way to do this that is much more intuitive than calculating the amount of RAM by "pages" on the SWsoft forum. Just multiply the amount of RAM that you want by 256 as an easy way to arrive at the right amount of RAM:
vzctl set vpsid --vmguarpages $((256 * 256)) --save
vzctl set vpsid --privvmpages $((256 * 1024)) --save
Read the vzctl man page, as well as the OpenVZ wiki and other documentation, for more information.
As you set parameters for each VPS, the configuration settings are stored in /etc/vz/conf/vpsid.conf. If you make any changes to this file manually, you can use the vzcfgvalidate utility to make sure that the configuration file is correct.
Often, in hosting situations, you need to get into a system where the admin has changed the root password. With physical systems, you need to reboot the system and enter single-user mode to get root access to handle administrative tasks. With OpenVZ, all you need to do is log into the hardware node and use vzctl to log in:
vzctl enter vpid
That will log you into the VPS as root. After you've finished whatever admin tasks you need to perform, just type exit and you'll be returned to the session on the host system. Or, if you want to reset a password for a user, you can just use the --userpasswd option:
vzctl set vpsid --userpasswd user:passwd
If the user does not exist, it will be created.
If you'd like to run a command in a VPS without actually entering the VPS, you can use the exec parameter for vzctl to run a command as root. For example, if you want to run a quick upgrade inside a Debian VPS:
vzctl exec vpsid apt-get upgrade
This will run apt-get upgrade within the VPS itself.
To shut down a VPS, run vzctl stop vpsid, which will execute a clean shutdown within the VPS.
Running vzctl restart vpsid will restart the VPS. VPSes can also be shut down or rebooted normally from within the VPS.
So long, goodbye
So, your guest system has had a good run, but it's time to pack it in. For whatever reason, if you have a VPS that you'd like to get rid of, use the destroy command with vzctl:
vzctl destroy veid
A note of caution here: the vzctl utility does not ask for confirmation before destroying the VPS. As soon as you press Enter, that's all she wrote -- the VPS will be removed, its private data directories removed, and if you don't have a backup, you are up a creek without a paddle if you need to retrieve the data.
One of the many virtualization options for Linux is OpenVZ, the free software component of SWsoft's Virtuozzo. OpenVZ, and Virtuozzo, are OS-level virtualization solutions that allow you to partition servers into multiple virtual private servers (VPS). Plowing through the OpenVZ documentation can be a bit intimidating, so let's walk through the easy way of getting started with OpenVZ on a Debian Etch system.
Last year, I reviewed Virtuozzo 3.0 for Linux, and I'd had some hands-on experience with prior versions of Virtuozzo from my days working with a hosting company in Denver. My budget doesn't have room for the Virtuozzo licensing, but OpenVZ fits my pocketbook just fine.
When would you want to use OpenVZ rather than VMware Server or Xen? It depends on the situation. For tasks where you don't want to run multiple OSes, but rather just multiple guests, in order to make the most of hardware or provide separation between services (for instance, separating your Web server from your file and print server) with minimal overhead, OpenVZ is a good choice. However, when you want to run non-Linux operating systems (such as FreeBSD or Windows Server) on top of a Linux host, you'd want to go with VMware rather than OpenVZ (or its commercial and proprietary big brother, Virtuozzo), since OpenVZ doesn't offer the ability to run multiple OSes.
OpenVZ also supports more processor platforms than the alternatives. VMware Server and Xen are available for x86 and AMD64, while OpenVZ is available for x86, AMD64, Itanium (IA64), PowerPC, and UltraSPARC.
Note that there are no pre-built PowerPC kernels for Debian at the moment, but OpenVZ is supported on PowerPC.
Installing OpenVZ
You can run OpenVZ guests on any host system. I'm running my guests on a Debian system, but you can use Ubuntu, Fedora Core, Gentoo, or any other distro that has an OS template. The OS template is the set of packages used to populate a VPS, AKA virtual environment (VE) in OpenVZ lingo.
Debian kernels for OpenVZ guests are available from the OpenVZ repository, but only for Etch. Grab the most recent kernel and linux-headers package from the OpenVZ repository, and install them using
dpkg -i linux-image-2.6.18-openvz-686_02_i386.deb
and
dpkg -i linux-headers-2.6.18-openvz-686_02_i386.deb .
Replace the package name with the name of the file that you download, of course. When I installed the packages, dpkg complained about two symlinks pointing to missing directories, but I haven't seen any problems while using OpenVZ, so as far as I can tell this isn't a problem.
Once you've installed the kernel and the headers, you'll want to add a few parameters (found on the the OpenVZ wiki) to /etc/sysctl.conf to prep the system for running OpenVZ. For example, you need to tell the system to enable IP forwarding so that the VPSes can have networking as well. Just add these lines to sysct.conf if they're not already present, or make sure they match:
net.ipv4.ip_forward = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.all.rp_filter = 1
kernel.sysrq = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
After installing the kernel and making these changes, you'll need to reboot the system. The OpenVZ kernel should be set to the default kernel in the GRUB menu already, so just rebooting should do the trick.
Next, you'll need to grab the OpenVZ utilities, using apt-get install vzctl. This will install the vzctl and vzquota packages, which include the utlities (like vzctl) that you need to use to manage OpenVZ.
OpenVZ will be set to start up at boot after you install these utilities, but if you want to start playing right away, you need to start up OpenVZ manually this time (or reboot). Start up OpenVZ by running the init script:
/etc/init.d/vz start
Setting up a guest system
So far so good. Now it's time to grab a few templates and set up a guest operating system. You can find precreated templates on the OpenVZ download site, including several versions of Fedora Core, Debian Sarge and Debian Etch, CentOS, Gentoo, Mandriva, and openSUSE. Note that templates are processor-specific, so be careful not to download the AMD64 or UltraSPARC version of a template if you're going to be running it on a x86 system.
You'll also notice that there's a contrib directory with OS templates from the OpenVZ community. These aren't "official" templates, but if you want to run Ubuntu, Slackware, AltLinux, or another distro not found with the OpenVZ templates, look here.
If you want to run a distro that doesn't have a template, see the OpenVZ wiki for documentation on creating OS templates. This is one area where OpenVZ is at a disadvantage to VMware and some of the other virtualization technologies. Installing a Linux distro in VMware Server or VMware Workstation is usually as simple as running through that distro's installation procedure. In OpenVZ it's much more complicated, and you'll need to learn a lot more about OpenVZ than you might want to just to run a couple of guest instances.
Downloaded OS templates need to be stored in /var/lib/vz/template/cache. The templates are tarred and gzipped when you download them, and you want to leave them that way -- don't uncompress them.
To set up a system, use the vzctl utlity. The bad news is that the vzctl utility is nowhere near as easy to use as the GUI tools that come with Virtuozzo. The good news is that vzctl isn't that difficult to use, it's scriptable, and it's free in every sense of the word. If you manage a lot of OpenVZ systems, you'll have the syntax down in no time, and if you don't create or muck with your OpenVZ guest systems very often, it shouldn't be too time-consuming to whip out the vzctl utlity man page and figure out the options you want. Let's take a look at the most common commands.
The syntax for creating a guest system is vzctl create vpsid --ostemplate ostemplatename . The vpsid is the number assigned to the new system. OpenVZ reserves IDs below 100 for internal use, so I usually start assigning IDs at 1001. So, for instance, if you download the Debian Sarge OS template for x86, you'd run:
vzctl create 1001 --ostemplate debian-3.1-i386-minimal
Once a guest host is set up, you can find its filesystem under /var/lib/vz/root/vpsid, and its private area under /var/lib/vz/private/vpsid -- unless you change the defaults using the --root or --private options. The private directory contains files specific to the virtual environment (VE).
So, if you created the guest as vz number 1001, its root filesystem would be under /var/lib/vz/root/1001. This may come in handy if you ever need to access the files directly for some reason -- for example, if the guest's admin has made a configuration that prevents the guest from booting normally -- or for backup purposes.
Now, let's set up networking. Again, this isn't terribly difficult:
vzctl set --ipadd ipaddr --nameserver nameserverIP --hostname hostname --save
The --ipadd parameter assigns the IP address to the first venet interface in the guest OS, the --hostname assigns the VPS its hostname, and the --nameserver paramter provides the first nameserver. The venet interface provided to OpenVZ guest systems by default does not have a MAC address, which means that (among other things) you cannot grab an address via DHCP for an interface.
However, the OpenVZ folks have added a new type of interface called a veth, which can provide a MAC address. The veth device also allows users to set up a DHCP server within the guest OS, and users can set their own network settings -- which is not possible using the venet devices. Whether this is desirable is another question. If you'd like to provide veth interfaces rather than venet interfaces, see the OpenVZ wiki for setup instructions.
Managing OpenVZ
Once the VPS is set up, go ahead and start the guest by running vzctl start vpsid , where vpsid is the ID that you assigned to the guest when you created it.
You should see a few messages logged to the console about starting the VPS, ending with "VPS start in progress..." You can see what VPSes are running with the vzlist command. After running vzlist, you should see something like this:
VPSID NPROC STATUS IP_ADDR HOSTNAME
1002 4 running 10.0.1.34 vroomfondle
Use the -a option to display all VPSes, whether they are running or not. You might also want to see what resources are being consumed by a VPS. To see how much memory is being used by a VPS, run
vzcalc -v vpsid
You should see something like this:
Resource Current(%) Promised(%) Max(%)
Low Mem 0.13 1.20 1.20
Total RAM 0.55 n/a n/a
Mem + Swap 0.36 1.83 n/a
Alloc. Mem 0.67 1.83 13.82
Num. Proc 0.06 n/a 0.40
--------------------------------------------------------------
Memory 0.67 1.83 13.82
This will show you how much memory is being used by the VPS, how much is allocated to the VPS, and what it can grow to.
You can also see other VPS parameters using the -o option. See the vzcalc man page for more information.
By default, VPSes will not be started up when you boot the system. In most situations, though, you probably do want VPSes to load after a system has restarted. You can change this setting using vzctl:
vzctl set vpsid --onboot yes --save
The vzctl utility is also used to set system parameters, including the amount of memory, CPU resources, access to iptables modules, and more. Let's look at a few examples.
One of the things that is frustrating about OpenVZ is that it's not straightforward to say "give a VPS 256MB of RAM"; instead, you have to adjust a couple of parameters and read through some fairly technical docs to try to make sense of the way that OpenVZ deals with memory.
To make things a bit simpler, let's look at setting a VPS with a minimum of 256MB of RAM, and up to 1GB. To do that, set the vmguarpages (that's the memory that's guaranteed to the VPS) and privvmpages (that's the maximum amount of memory that will be granted) parameters:
vzctl set vpsid --vmguarpages 65536 --save
vzctl set vpsid --privvmpages 262144 --save
I found another way to do this that is much more intuitive than calculating the amount of RAM by "pages" on the SWsoft forum. Just multiply the amount of RAM that you want by 256 as an easy way to arrive at the right amount of RAM:
vzctl set vpsid --vmguarpages $((256 * 256)) --save
vzctl set vpsid --privvmpages $((256 * 1024)) --save
Read the vzctl man page, as well as the OpenVZ wiki and other documentation, for more information.
As you set parameters for each VPS, the configuration settings are stored in /etc/vz/conf/vpsid.conf. If you make any changes to this file manually, you can use the vzcfgvalidate utility to make sure that the configuration file is correct.
Often, in hosting situations, you need to get into a system where the admin has changed the root password. With physical systems, you need to reboot the system and enter single-user mode to get root access to handle administrative tasks. With OpenVZ, all you need to do is log into the hardware node and use vzctl to log in:
vzctl enter vpid
That will log you into the VPS as root. After you've finished whatever admin tasks you need to perform, just type exit and you'll be returned to the session on the host system. Or, if you want to reset a password for a user, you can just use the --userpasswd option:
vzctl set vpsid --userpasswd user:passwd
If the user does not exist, it will be created.
If you'd like to run a command in a VPS without actually entering the VPS, you can use the exec parameter for vzctl to run a command as root. For example, if you want to run a quick upgrade inside a Debian VPS:
vzctl exec vpsid apt-get upgrade
This will run apt-get upgrade within the VPS itself.
To shut down a VPS, run vzctl stop vpsid, which will execute a clean shutdown within the VPS.
Running vzctl restart vpsid will restart the VPS. VPSes can also be shut down or rebooted normally from within the VPS.
So long, goodbye
So, your guest system has had a good run, but it's time to pack it in. For whatever reason, if you have a VPS that you'd like to get rid of, use the destroy command with vzctl:
vzctl destroy veid
A note of caution here: the vzctl utility does not ask for confirmation before destroying the VPS. As soon as you press Enter, that's all she wrote -- the VPS will be removed, its private data directories removed, and if you don't have a backup, you are up a creek without a paddle if you need to retrieve the data.
First openVZ installation with yum
So in short after having my bare bones install here is my quick and dirty easy to follow steps
from Scott's article:
1. cd /etc/yum.repos.d
2. wget http://download.openvz.org/openvz.repo
3. yum install ovzkernel
4. nano -w /etc/sysctl.conf with these changes:
______________________
# On Hardware Node we generally need
# packet forwarding enabled and proxy arp disabled
net.ipv4.ip_forward = 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
# TCP Explict Congestion Notification
# net.ipv4.tcp_ecn = 0
# 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. Set the default kernel in grub to the new one
6. Reboot using the new kernel
7. yum install vzctl vzquota
8. service vz start
9. yum install vzpkg vzyum vzrpm43-python vzrpm44-python
10. yum install vztmpl-centos-4
11. nano -w /vz/template/centos/4/i386/config/default.list appending this:
yum
mc
links
system-config-date
nano
12. vzpkgcache -f centos-4
13. vzctl create 101 --ostemplate centos-4 --config vps.basic
14. vzctl set 101 --ipadd 192.168.0.101 --save
15. vzctl set 101 --hostname vps101 --save
16. vzctl set 101 --nameserver 192.168.0.1 --nameserver 192.168.0.2 --save
17. vzctl set 101 --userpasswd root:areallycoolpassword
18. vzctl set 101 --onboot yes --save
19. vzctl start 101
20. vzctl enter 101
Okay so that is it in a nutshell. Then this is where I start getting into trouble with my wild
ideas. I mentioned wanting to make this my backup server and I normally use Dirvish, but this
time I want to try out BackupPC. Now I also have a nice 300GB drive I have used for my
time I want to try out BackupPC. Now I also have a nice 300GB drive I have used for my
backups and I planned on just mounting it inside this new VPS.
Problem is I couldn't figure out
how to give it enough diskspace quota. The most it would give was from my 40GB drive and
that was a 34GB quota. So I called Scott and pretty much just decided to do LVM (logical
volume management) and merge the drives together to make it look like one big drive. This
however entailed starting from scratch again as I'm pretty lazy when it comes to trying to
figure out installing something like this after the fact.
So I find my single CentOS CD and attempt to boot it but my crappy old Dell has an abused
CD-R drive. So I borrow the one out of another Dell and off we go. So when I get back to the
point I was last, I run this:
vzctl set 101 --diskspace 315621376:315621376 --save
This gives me 301GB disk space to work with in my VPS. Problem is I was told by Scott there is
an rpm for BackupPC but currently there are no rpm's for CentOS. So this brings me to another
task... create another VPS with a distribution that includes rpm package management for
BackupPC. I found out the hard way that these guys are yet another that uses caps in their
package name and caused me a bit of headache searching for it.
I picked FC-5 for the new VPS as it seems to be the latest to carry BackupPC. To do this I
needed to build the template similar to building the CentOS template above.
yum install vztmpl-fedora-core-5
The rest was pretty much as stated above. Of course I forgot to edit the default.list and had to
later go back and update the cache after already creating the VPS with FC5. So I needed yum
installed on this to fill in the blanks and Scott to the rescue again; I could install this from the
host with:
vzyum 102 install yum
This is it for now. I have yet to configure BackupPC. I will have to blog about it later.
from Scott's article:
1. cd /etc/yum.repos.d
2. wget http://download.openvz.org/openvz.repo
3. yum install ovzkernel
4. nano -w /etc/sysctl.conf with these changes:
______________________
# On Hardware Node we generally need
# packet forwarding enabled and proxy arp disabled
net.ipv4.ip_forward = 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
# TCP Explict Congestion Notification
# net.ipv4.tcp_ecn = 0
# 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. Set the default kernel in grub to the new one
6. Reboot using the new kernel
7. yum install vzctl vzquota
8. service vz start
9. yum install vzpkg vzyum vzrpm43-python vzrpm44-python
10. yum install vztmpl-centos-4
11. nano -w /vz/template/centos/4/i386/config/default.list appending this:
yum
mc
links
system-config-date
nano
12. vzpkgcache -f centos-4
13. vzctl create 101 --ostemplate centos-4 --config vps.basic
14. vzctl set 101 --ipadd 192.168.0.101 --save
15. vzctl set 101 --hostname vps101 --save
16. vzctl set 101 --nameserver 192.168.0.1 --nameserver 192.168.0.2 --save
17. vzctl set 101 --userpasswd root:areallycoolpassword
18. vzctl set 101 --onboot yes --save
19. vzctl start 101
20. vzctl enter 101
Okay so that is it in a nutshell. Then this is where I start getting into trouble with my wild
ideas. I mentioned wanting to make this my backup server and I normally use Dirvish, but this
time I want to try out BackupPC. Now I also have a nice 300GB drive I have used for my
time I want to try out BackupPC. Now I also have a nice 300GB drive I have used for my
backups and I planned on just mounting it inside this new VPS.
Problem is I couldn't figure out
how to give it enough diskspace quota. The most it would give was from my 40GB drive and
that was a 34GB quota. So I called Scott and pretty much just decided to do LVM (logical
volume management) and merge the drives together to make it look like one big drive. This
however entailed starting from scratch again as I'm pretty lazy when it comes to trying to
figure out installing something like this after the fact.
So I find my single CentOS CD and attempt to boot it but my crappy old Dell has an abused
CD-R drive. So I borrow the one out of another Dell and off we go. So when I get back to the
point I was last, I run this:
vzctl set 101 --diskspace 315621376:315621376 --save
This gives me 301GB disk space to work with in my VPS. Problem is I was told by Scott there is
an rpm for BackupPC but currently there are no rpm's for CentOS. So this brings me to another
task... create another VPS with a distribution that includes rpm package management for
BackupPC. I found out the hard way that these guys are yet another that uses caps in their
package name and caused me a bit of headache searching for it.
I picked FC-5 for the new VPS as it seems to be the latest to carry BackupPC. To do this I
needed to build the template similar to building the CentOS template above.
yum install vztmpl-fedora-core-5
The rest was pretty much as stated above. Of course I forgot to edit the default.list and had to
later go back and update the cache after already creating the VPS with FC5. So I needed yum
installed on this to fill in the blanks and Scott to the rescue again; I could install this from the
host with:
vzyum 102 install yum
This is it for now. I have yet to configure BackupPC. I will have to blog about it later.
Friday, October 9, 2009
Configuring Static ip address in Linux (ubuntu/debian)
Like most desktops, mine was connecting to network using DHCP. While it is nice and automatic, it is often clumsy as the ip address (of the Desktop) usually changes after every reboot.
If you have only command-line access, here is a simple way to assign a static ip address (in my case it is 192.168.1.3) to your desktop. Make sure you consult your site administrator before doing that, as ip address and gateway ip address may vary.
There are two files that must be configured /etc/network/interfaces and /etc/resolv.conf.
Open /etc/network/interfaces in your favorite editor (mine being nano).? What you will most likely see is this:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
The last line is what you need to edit (and add to.) To configure eth0 (your network device) for a static IP address that last line should resemble:
iface eth0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.1
Naturally you will need to change the last three lines to reflect your own networking setup.
Once that file has been edited you can restart your network connection with the command:
sudo /etc/init.d/networking restart
Now Configuring DNS
That file is /etc/resolv.conf. This file is in charge of holding your DNS server addresses. Open this file up in your editor. What you need are two lines:
nameserver 208.67.220.220
nameserver 208.67.222.222
If you have only command-line access, here is a simple way to assign a static ip address (in my case it is 192.168.1.3) to your desktop. Make sure you consult your site administrator before doing that, as ip address and gateway ip address may vary.
There are two files that must be configured /etc/network/interfaces and /etc/resolv.conf.
Open /etc/network/interfaces in your favorite editor (mine being nano).? What you will most likely see is this:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
The last line is what you need to edit (and add to.) To configure eth0 (your network device) for a static IP address that last line should resemble:
iface eth0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.1
Naturally you will need to change the last three lines to reflect your own networking setup.
Once that file has been edited you can restart your network connection with the command:
sudo /etc/init.d/networking restart
Now Configuring DNS
That file is /etc/resolv.conf. This file is in charge of holding your DNS server addresses. Open this file up in your editor. What you need are two lines:
nameserver 208.67.220.220
nameserver 208.67.222.222
Thursday, October 1, 2009
Configuring Apache to handle PSP (python server pages)
Note: You will need Python and mod_python installed in your server. If you have not done that, please follow the python install instructions
After mod_python installation you must make Apache aware of it. For this purpose open APACHE_HOME/conf/httpd.conf for editing(for default Linux location of httpd.conf, consult your system documentation) and append the following lines at the end:
The first line loads mod_python into Apache. The actual path of mod_python.so may vary but the installer should give you the proper path upon finishing. (On Linux most likely it would be libexec/mod_python.so.) The second line informs Apache which files should be handled by PythonHandler, specified on the third line (more about .psp_ usage in the section below). The last directive switches mod_python into debugging mode; when PythonDebug directive is set to On, it will dump traces for the first unhandled exception in the running application. Setting this flag is highly recommended for development purposes, but make sure you turn it off on production environments so as to not expose certain system internals to visitors.
If you would like mod_python pages to be used as default index pages, locate in httpd.conf the following line and change it from
to
Now restart Apache. On Windows you usually do that with the Apache Monitor in the system tray or by running net stop apache2 and then net start apache2; on Linux it's as simple as apachectl restart.
PSP are plain text files that include Python code surrounded with <% and %> tags. Python expressions are enclosed within <%= and %> tags. Directives enable inclusion of other PSP pages; they are wrapped by <%@ and %> tags. The least frequently used tags are <%-- and --%> which, as you might guess, are simply comments that are never rendered to the resulting code.
Let's start with the simple Hello Python example. Under APACHE_HOME/htdocs create a file hello.psp with the following content:
Now go to http://127.0.0.1/hello.psp with your web browser. You will see how many Python modules are installed on your system. Of course, this information is trivial to us. Mod_python doesn't offer a function equivalent to PHP's phpinfo(), which gives detailed information about the interpreter. In the next step, we'll write one for PSP ourselves.
Under APACHE_HOME/htdocs (usually /var/www), create a file pspinfo.psp with the following content:
Now open http://127.0.0.1/pspinfo.psp and you should see a page as below:
_____________________________________________________________________
Configuring Apache HTTP Server to Handle PSP
After mod_python installation you must make Apache aware of it. For this purpose open APACHE_HOME/conf/httpd.conf for editing(for default Linux location of httpd.conf, consult your system documentation) and append the following lines at the end:
LoadModule python_module modules/mod_python.so AddHandler mod_python .psp .psp_ PythonHandler mod_python.psp PythonDebug On
The first line loads mod_python into Apache. The actual path of mod_python.so may vary but the installer should give you the proper path upon finishing. (On Linux most likely it would be libexec/mod_python.so.) The second line informs Apache which files should be handled by PythonHandler, specified on the third line (more about .psp_ usage in the section below). The last directive switches mod_python into debugging mode; when PythonDebug directive is set to On, it will dump traces for the first unhandled exception in the running application. Setting this flag is highly recommended for development purposes, but make sure you turn it off on production environments so as to not expose certain system internals to visitors.
If you would like mod_python pages to be used as default index pages, locate in httpd.conf the following line and change it from
DirectoryIndex index.html index.html.var
to
DirectoryIndex index.html index.psp index.html.var
Now restart Apache. On Windows you usually do that with the Apache Monitor in the system tray or by running net stop apache2 and then net start apache2; on Linux it's as simple as apachectl restart.
Using mod_python
PSP are plain text files that include Python code surrounded with <% and %> tags. Python expressions are enclosed within <%= and %> tags. Directives enable inclusion of other PSP pages; they are wrapped by <%@ and %> tags. The least frequently used tags are <%-- and --%> which, as you might guess, are simply comments that are never rendered to the resulting code.
Let's start with the simple Hello Python example. Under APACHE_HOME/htdocs create a file hello.psp with the following content:
<html> <% import sys %> Hello! You have <%=len(sys.modules)%> Python modules at your command. </html>
Now go to http://127.0.0.1/hello.psp with your web browser. You will see how many Python modules are installed on your system. Of course, this information is trivial to us. Mod_python doesn't offer a function equivalent to PHP's phpinfo(), which gives detailed information about the interpreter. In the next step, we'll write one for PSP ourselves.
Under APACHE_HOME/htdocs (usually /var/www), create a file pspinfo.psp with the following content:
<% req.content_type = 'text/plain' import mod_python import pprint import sys %> PYTHON <%=sys.version %> MOD_PYTHON <%=mod_python.version %> PATH = <%=pprint.pformat(sys.path)%> AVAILABLE MODULES <%=pprint.pformat(sys.modules)%>
Now open http://127.0.0.1/pspinfo.psp and you should see a page as below:
_____________________________________________________________________
PYTHON 2.6.2 (release26-maint, Apr 19 2009, 02:11:59) [GCC 4.3.3] MOD_PYTHON 3.3.1 PATH = ['/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/local/lib/python2.6/dist-packages'] AVAILABLE MODULES {'StringIO': <module 'StringIO' from '/usr/lib/python2.6/StringIO.pyc'>, 'UserDict': <module 'UserDict' from '/usr/lib/python2.6/UserDict.pyc'>, '__builtin__': <module '__builtin__' (built-in)>, '__future__': <module '__future__' from '/usr/lib/python2.6/__future__.pyc'>, '__main__': <module '__main__' (built-in)>, '_abcoll': <module '_abcoll' from '/usr/lib/python2.6/_abcoll.pyc'>, '_apache': <module '_apache' (built-in)>, '_bisect': <module '_bisect' (built-in)>, '_bsddb': <module '_bsddb' from '/usr/lib/python2.6/lib-dynload/_bsddb.so'>, '_codecs': <module '_codecs' (built-in)>, '_collections': <module '_collections' (built-in)>, '_functools': <module '_functools' (built-in)>, '_hashlib': <module '_hashlib' from '/usr/lib/python2.6/lib-dynload/_hashlib.so'>, ................ ............. .......... ________________________________________________________________________________________ '_locale': <module '_locale' (built-in)>,
perl: warning: Setting locale failed
Error Message:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Resolution: Run the commands
#locale-gen en_US.UTF-8 (or whatever locale you want)
#dpkg-reconfigure locales
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Resolution: Run the commands
#locale-gen en_US.UTF-8 (or whatever locale you want)
#dpkg-reconfigure locales
Installing python and django
python (not the snake :P) has been around for quite sometime. But lately after Google's announcement of App Engine I developed a growing interest in it. One major benefit of python is the code size. Compared to Java, the code size of python is considerable less. More of comparisons later, I will use this post to install python and django in a fresh linux box.
I start with a CentOS box with apache and yum installed.
Now for installing python
#yum install python
Normally mod_python would install, but if it is not installed already, run
#yum install mod_python
In Debian/Ubuntu it would be
#apt-get install libapache2-mod-python
To test python installation, run the command
# python
You should get something like
___________________________________
Python 2.4.3 (#1, Jan 21 2009, 01:10:13)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
____________________________________
Python has been successfully installed. Press Ctrl+D to exit the python shell.
django is not found in repository, so I would install from svn (subversion)
First install subversion
#yum install subversion
Now,
Change directory to /var/www
#cd /var/www
create a directory for django
#mkdir django-src
Change to the django directory
#cd django-src
Download django from svn
#svn co http://code.djangoproject.com/svn/django/trunk/
django source would be downloaded into a sub-folder trunk. Change to the trunk folder
#cd trunk
install django
#python setup.py install
For debian and ubuntu it is a single command
#apt-get install python-django python-mysqldb
Install and start mysql server
#yum install mysql-server
#/etc/init.d/mysqld start
Now to install MySQL-python
(Normally mysql-python installed with yum is an old version, to install the latest follow this)
Installing the necessary tools
#yum install python-devel mysql-devel gcc
Download MySQL-python from http://sourceforge.net/project/showfiles.php?group_id=22307
Extract the compressed file
#tar zxvf <filename of MySQLdb tarball>
Change to the extracted folder
#cd <name of newly created directory by the tar command>
Build and Install from the MySQL-python source
#python setup.py build
#python setup.py install
MySQL-python is installed as .egg file in your site-packages directory.
To run your django application
#python manage.py runserver 127.0.0.1:8000
To additionally install Python Imaging Library
#yum install python-imaging
I start with a CentOS box with apache and yum installed.
Now for installing python
#yum install python
Normally mod_python would install, but if it is not installed already, run
#yum install mod_python
In Debian/Ubuntu it would be
#apt-get install libapache2-mod-python
To test python installation, run the command
# python
You should get something like
___________________________________
Python 2.4.3 (#1, Jan 21 2009, 01:10:13)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
____________________________________
Python has been successfully installed. Press Ctrl+D to exit the python shell.
django is not found in repository, so I would install from svn (subversion)
First install subversion
#yum install subversion
Now,
Change directory to /var/www
#cd /var/www
create a directory for django
#mkdir django-src
Change to the django directory
#cd django-src
Download django from svn
#svn co http://code.djangoproject.com/svn/django/trunk/
django source would be downloaded into a sub-folder trunk. Change to the trunk folder
#cd trunk
install django
#python setup.py install
For debian and ubuntu it is a single command
#apt-get install python-django python-mysqldb
Install and start mysql server
#yum install mysql-server
#/etc/init.d/mysqld start
Now to install MySQL-python
(Normally mysql-python installed with yum is an old version, to install the latest follow this)
Installing the necessary tools
#yum install python-devel mysql-devel gcc
Download MySQL-python from http://sourceforge.net/project/showfiles.php?group_id=22307
Extract the compressed file
#tar zxvf <filename of MySQLdb tarball>
Change to the extracted folder
#cd <name of newly created directory by the tar command>
Build and Install from the MySQL-python source
#python setup.py build
#python setup.py install
MySQL-python is installed as .egg file in your site-packages directory.
To run your django application
#python manage.py runserver 127.0.0.1:8000
To additionally install Python Imaging Library
#yum install python-imaging
Subscribe to:
Posts (Atom)