Open main menu

OpenVZ Virtuozzo Containers Wiki β

Changes

Getting started with OpenVZ live CD

1,734 bytes removed, 13:16, 11 December 2007
categorized
This article is written for OpenVZ LiveCD and assumes that the reader only starts using OpenVZ.([[Download live CD]])
== Introduction ==
So, as you probably know, OpenVZ allows the user to create [[VE]]s, or Virtual Environments, which seems seem very much
like real computers. Real computer can run various distributions: Debian, Gentoo, Red Hat and Novell products, etc.
In the same way, a VE can be based on various [[|OS template|OS (Operating System) templates]]. On the LiveCD only Debian few minimal template is OS templates are installed and it is used by defaultbecause of disk space limit. Each VE is indentified identified by its number -- a '''VEID'''.
== VE creation ==
terminal (you must be root):
<pre>
root@Knoppix:~# vzctl create 101--ostemplate debian-3.1-i386-minimal
Creating VE private area (debian-3.1-i386-minimal)
Performing postcreate actions
</pre>
'''vzctl''' is the tool that manages VEs.Look in <tt>/vz/template/cache/</tt> (CentOS LiveCD)or in <tt>/var/lib/vz/template/cache/</tt> (KNOPPIX LiveCD) directories for other OS templates available on LiveCD:<pre># ls -1 /var/lib/vz/template/cache/centos-4-i386-minimal.tar.gzdebian-3.1-i386-minimal.tar.gzfedora-core-5-i386-minimal.tar.gz</pre>
== List of VEs ==
You can get the list of all created VEs on '''HN''' (Hardware Node) using '''vzlist''' command:
<pre>
root@Knoppix:~# vzlist -a
VEID NPROC STATUS IP_ADDR HOSTNAME
101 - stopped - -
Let's start it:
<pre>
root@Knoppix:~# vzctl start 101
Starting VE ...
VE is mounted
Setting CPU units: 1000
VE start in progress...
root@Knoppix:~# vzlist -a
VEID NPROC STATUS IP_ADDR HOSTNAME
101 5 running -
== Executing commands in VE ==
From the previous "vzlist" command you see that 5 processes are running inside VE 101. (The "NPROC" field indicates the number of Processes, or PIDs, that are active in the VE -- not the number of Processors, or CPUs.) Being on usual [[hardware node]] you can use <code>ps</code> command to identify those, and the same command can be used here. The only difference is that this command should be called inside VE.
In order to perform any command inside VE `vzctl exec` is used:
<pre>
root@Knoppix:~# vzctl exec 101 ps
PID TTY TIME CMD
1 ? 00:00:00 init
Any self-respected OS provides a shell for the user. This is how you can get the VE's shell:
<pre>
root@Knoppix:~# vzctl enter 101
entered into VE 101
Knoppix:/#
</pre>
In this shell you can do almost all you can do on the real HN. For example create a new user:
<pre>
Knoppix:/# useradd new-userKnoppix:/# passwd new-user
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Knoppix:/# mkdir /home/new-userKnoppix:/# chown new-user /home/new-user/Knoppix:/# su new-userKnoppix:/$ cd ~Knoppix:~$ pwd
/home/new-user
exit
Knoppix:/#
</pre>
In order to exit from VEs shell, just type exit:
<pre>
Knoppix:/# exit
logout
exited from VE 101
root@Knoppix:~#
</pre>
<pre>
root@Knoppix:~# echo 1 > /proc/sys/net/ipv4/ip_forwardroot@Knoppix:~# ifconfig venet0 uproot@Knoppix:~# vzctl set 101 --ipadd 10.1.1.1 --save
Adding IP address(es): 10.1.1.1
Saved parameters for VE 1
root@Knoppix:~# vzlist -a
VEID NPROC STATUS IP_ADDR HOSTNAME
101 4 running 10.1.1.1 -
Now your [[Hardware Node]] can ping VE and VE can ping HN:
<pre>
root@Knoppix:~# ping 10.1.1.1
PING 10.1.1.1 (10.1.1.1) 56(84) bytes of data.
64 bytes from 10.1.1.1: icmp_seq=1 ttl=64 time=3.80 ms
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 3.804/3.804/3.804/0.000 ms
root@Knoppix:~#root@Knoppix:~# vzctl exec 101 ping 192.168.0.244
PING 192.168.0.244 (192.168.0.244) 56(84) bytes of data.
64 bytes from 192.168.0.244: icmp_seq=1 ttl=64 time=0.508 ms
root@Knoppix:~#
</pre>
of your node is 192.168.0.244 and nameserver IP address is 192.168.1.1.
<pre>
root@Knoppix:~# iptables -t nat -A POSTROUTING -s 10.1.1.1 -o eth0 -j SNAT --to 192.168.0.244root@Knoppix:~# vzctl set 101 --nameserver 192.168.1.1 --save
File resolv.conf was modified
Saved parameters for VE 101
root@Knoppix:~# vzctl exec 101 ping google.com
PING google.com (64.233.167.99) 56(84) bytes of data.
64 bytes from py-in-f99.google.com (64.233.167.99): icmp_seq=1 ttl=241 time=23.0 ms
== Installing software inside VE ==
I guess you've noted that there is not so many packages in VE. It is because minimal template was used.
But of course, you can install any software in VE by yourself. For example, in Debian usual <tt>apt-get </tt> tool can be used.
Now, for example, we can install gcc inside VE 101 for developing purposes:
<pre>
root@Knoppix:~# vzctl enter 101
entered into VE 101
Knoppix:/#Knoppix:/# apt-get install gcc
Reading Package Lists... Done
Building Dependency Tree... Done
Setting up gcc (3.3.5-3) ...
Knoppix:/# exit
logout
exited from VE 101
root@Knoppix:~#
</pre>
 
{{ Note|In the LiveCD environment, you may have to increase '''shmpages''' resource limit/barrier for the VE (read the next section) or you will run out of "disk space" when trying to install software }}
== Resource limiting ==
The very important feature of VE is that you can limit it by resources: CPU, memory, disk space.
It is also performed via vzctl. Current usage values and limits of For example to set '''shmpages''' (shared memory-related resources can be viewed throughpages) barrier:limit you[[/proc/user_beancounters]] fileshould give this command:
<pre>
root@Knoppixvzctl set 101 --shmpages 16384:16384 --save</pre>This will give VE 101 64MB of '''shmpages''' (one page equals 4Kb on i386: 4Kb * 16384 = 64Mb) Current usage values and limits of memory-related resources can be viewed through<code>/proc/bc/VEID/resources</code> file:~<pre># cat /proc/bc/101/resources # or /proc/user_beancountersVersion: on 2.56.9 kernels uid resource held maxheld barrier limit failcnt 101: kmemsize 628209 976969 2752512 2936012 0
lockedpages 0 0 32 32 0
privvmpages 5238 6885 49152 53575 0
shmpages 5012 5014 8192 8192 0
dummy 0 0 0 0 0
numproc 3 11 65 65 0
physpages 5084 6020 0 2147483647 0
dcachesize 0 0 1048576 1097728 0
numfile 106 339 2048 2048 0
dummy 0 0 0 0 0
dummy 0 0 0 0 0
dummy 0 0 0 0 0
numiptent 10 10 128 128 0
0: kmemsize 7843131 9967098 2147483647 2147483647 0 lockedpages 0 0 2147483647 2147483647 0 privvmpages 89600 127711 2147483647 2147483647 0 shmpages 63290 90159 2147483647 2147483647 0 dummy 0 0 2147483647 2147483647 0 numproc 73 78 2147483647 2147483647 0 physpages 85729 112341 2147483647 2147483647 0 vmguarpages 0 0 2147483647 2147483647 0 oomguarpages 85729 112341 2147483647 2147483647 1 numtcpsock 5 6 2147483647 2147483647 0 numflock 0 1 2147483647 2147483647 0 numpty 3 3 2147483647 2147483647 0 numsiginfo 0 3 2147483647 2147483647 0 tcpsndbuf 46620 48840 2147483647 2147483647 0 tcprcvbuf 81920 125476 2147483647 2147483647 0 othersockbuf 228660 339664 2147483647 2147483647 0 dgramrcvbuf 0 267484 2147483647 2147483647 0 numothersock 120 136 2147483647 2147483647 0 dcachesize 0 0 2147483647 2147483647 0 numfile 3111 3145 2147483647 2147483647 0 dummy 0 0 2147483647 2147483647 0 dummy 0 0 2147483647 2147483647 0 dummy 0 0 2147483647 2147483647 0 numiptent 15 15 2147483647 2147483647 0root@Knoppix:~#
</pre>
First column is resource name, second is current usage, third is peak usage, forth and fifth are barrier and limit, and last column is fail counter.
Note that if you have failcounters nonzero values in the last column, it means that the appropriate this VEexperienced a resource shortage. This is very common reason why some application fail torun work in a VE. In this case you should increase limits/barriers accordingly; see
[[resource shortage]] for more info.
Well, let's stop VE and destroy it:
<pre>
root@Knoppix:~# vzctl stop 101
Stopping VE ...
VE was stopped
VE is unmounted
root@Knoppix:~# rm -rf /var/lib/vz/private/101 # THIS STEP IS TEMPORARY: http://bugzilla.openvz.org/show_bug.cgi?id=455root@Knoppix:~# vzctl destroy 101
Destroying VE private area: /var/lib/vz/private/101
VE private area was destroyed
root@Knoppix:~#
</pre>
== Links ==
That's all you need to start playing with OpenVZ. Additional information can be found in man page on vzctl and at http://wiki.openvz.org/ . If you experience some difficulties, contact us via http://forum.openvz.org/ . Templates and other tools are available from http://download.openvz.org/.
If you expirience some difficulties, contact us via http[[Category://forum.openvz.org/. Templates and other tools are available from http://download.openvz.org/.Live CD]]