September 2010
M T W T F S S
« Aug    
 12345
6789101112
13141516171819
20212223242526
27282930  
99

Categories

Archives

Managing OpenVZ instances

Making an OS template
1
2
3
4
5
6
7
8
# to make a os template from an existing container (CT):
vzctl stop 101
vzctl set 101 --ipdel all --save
cd /vz/template/cache/
ls
cd /vz/private/101
ls
tar zcvf /vz/template/cache/centos-5-standard_5-2_i386_bubba.net.tar.gz .
Listing containers
1
2
3
4
5
6
7
8
# list containers
vzlist -a
      CTID      NPROC STATUS  IP_ADDR         HOSTNAME
       101         30 running 192.168.2.101   host1.mydomain.com         
       102         45 running 192.168.2.102   host2.mydomain.com
       103         31 running -               host3.mydomain.com
       104         38 running 192.168.2.104   host4.mydomain.com
       105         48 running 192.168.2.105   host5.mydomain.com

Starting containers
1
2
# to start the containers
vzctl start 101; vzctl start 102; vzctl start 103; vzctl start 104; vzctl start 105
Stopping containers
1
2
# to stop the containers
vzctl stop 101; vzctl stop 102; vzctl stop 103; vzctl stop 104; vzctl stop 105
Entering a container
1
2
# to enter the container 101
vzctl enter 101
Running commands in a container
1
2
3
# to run a command in the container 101
vzctl exec 101 passwd
vzctl exec 101 cat /proc/filesystems
Destroying a container
1
2
# to destroy a container
vzctl destory 101
Installing an app into a container
1
2
3
4
# to install an app
vzyum 101 install dhcp
vzctl exec 101 chkconfig --level 3 dhcpd on
vzctl exec 101 service dhcpd start
Cloning a container
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# cloning a VE
# Say there is a VE with ID 100, and you want to make a clone of it; a new
# VE will have ID 200. Here is how:
 
# Stop source VE
vzctl stop 100
 
# Copy VE private area:
cd /vz/private/
mkdir 200
cp -a 100/* 200/
# Copy VE config file
cd /etc/sysconfig/vz-scripts/
cp 100.conf 200.conf
 
# Change VE 200 IP address: remove old ones than add some new ones
vzctl set 200 --ipdel all --ipadd x.x.x.x --save
 
# Start original VE and the clone
vzctl start 100
vzctl start 200
Backup/Restore a container

The tool vzdump can be used to save/restore either running or stopped VEs. Vzdump can be installed like this:

1
2
3
4
5
6
7
8
9
10
rpm -ivh http://www.proxmox.com/cms_proxmox/cms/upload/vzdump/vzdump-1.1-1.noarch.rpm
 
# NOTE: I had to install 2 additional required packages cstream and MTA
#
# The first was available via the default centos repo
# yum install MTA
#
# The second I had to get from the rpmforge repo
# wget http://dag.wieers.com/rpm/packages/cstream/cstream-2.7.4-3.el5.rf.i386.rpm
# rpm -ivh cstream-2.7.4-3.el5.rf.i386.rpm

Here is a list of vzdump’s command-line options:

vzdump OPTIONS [--all | <VMID>]

      --exclude VPSID         exclude VPSID (assumes --all)
      --exclude-path REGEX    exclude certain files/directories. You
                              can use this option more than once to specify
                              multiple exclude paths
      --stdexcludes           exclude temorary files and logs
      --compress              compress dump file (gzip)
      --dumpdir DIR           store resulting files in DIR
      --tmpdir DIR            store temporary files in DIR. --suspend and --stop are using this directory to store a copy of the VM.
      --mailto EMAIL          send notification mail to EMAIL. You can use
                              this option more than once to specify multiple
                              receivers
      --stop                  stop/start VPS if running
      --suspend               suspend/resume VPS when running
      --snapshot              use LVM snapshot when running
      --size MB               LVM snapshot size (default 1024)
      --bwlimit KBPS          limit I/O bandwidth; KBytes per second
      --lockwait MINUTES      maximal time to wait for the global
                              lock. vzdump uses a global lock file to make
                              sure that only one instance is running
                              (running sereral instance puts too much load
                              on a server). Default is 180 (3 hours).
      --stopwait MINUTES      maximal time to wait until a VM is stopped.
      --restore FILENAME      restore FILENAME

Finally here are some examples:

Backup

Simply dump CT 777, no snapshot, just archive the container private area and configuration files to the default dump directory (usually /vz/dump/).

1
vzdump 777

Use rsync and suspend/resume to create a snapshot (minimal downtime).

1
vzdump --suspend 777

Backup all containers and send notification mails to root.

1
vzdump --suspend --all --mailto root

Use LVM2 to create snapshots (no downtime).

1
vzdump --dumpdir /space/backup --snapshot 777

Note that using LVM2 and vzdump to create snapshots requires 512Mb of free space in your VG as described here.

Restore/Clone

Restore the above backup to CT 600:

1
vzdump --restore /space/backup/vzdump-777.tar 600

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>