6,534
edits
Changes
categorized
This article is basicaly 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 minimaltemplate is OS templates are installed and it is used by defaultbecause of disk space limit. Each VE is indentified identified by its identification number -- a '''veidVEID'''. == VE creation ==So, how to create a VE with veid 1 VEID of 101 based on Debian template? Very easy. Just type the following commands in your
terminal (you must be root):
<pre>
Creating VE private area (debian-3.1-i386-minimal)
Performing postcreate actions
</pre>
'''vzctl''' - is the tool that manages VEs. You can get the list of all created VEs on '''HN''' Look in <tt>/vz/template/cache/</tt> (CentOS LiveCD)or in <tt>/var/lib/vz/template/cache/</tt> (Hardware NodeKNOPPIX LiveCD) by '''vzlist''' commanddirectories for other OS templates available on LiveCD:
<pre>
VEID NPROC STATUS IP_ADDR HOSTNAME
</pre>
As you see, VE #1 101 is in stopped state now. == Starting VE ==Let's start it:
<pre>
Starting VE ...
VE is mounted
Setting CPU units: 1000
VE start in progress...
VEID NPROC STATUS IP_ADDR HOSTNAME
</pre>
In order to perform any command inside VE `vzctl exec` is used:
<pre>
PID TTY TIME CMD
1 ? 00:00:00 init
</pre>
== Entering VE ==
Any self-respected OS provides a shell for the user. This is how you can get the VE's shell:
<pre>
</pre>
In this shell you can do almost all you can do on the real HN. For example create a new user:
<pre>
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
/home/new-user
exit
</pre>
In order to exit from VEs shell, just type exit:
<pre>
logout
exited from VE 1101root@Knoppix:~#
</pre>
<pre>
Adding IP address(es): 10.1.1.1
Saved parameters for VE 1
VEID NPROC STATUS IP_ADDR HOSTNAME
</pre>
Now your '''HN''' ([[Hardware Node) ]] can ping VE and VE can ping HN:
<pre>
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
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
</pre>
However, it isn't is not possible to ping other computers in the network: for it we need toset up NAT (Network Address Translation) and set the nameserver.
Assume that you've set up network on HN (for example via DHCP) and the IP address
of your node is 192.168.0.244 and nameserver IP address is 192.168.1.1.
<pre>
File resolv.conf was modified
Saved parameters for VE 1101root@Knoppix:~# vzctl exec 1 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
</pre>
== 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 #1 101 for developing purposes:
<pre>
Reading Package Lists... Done
Building Dependency Tree... Done
Setting up gcc (3.3.5-3) ...
logout
exited from VE 1101root@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. For example to set '''shmpages''' (shared memory pages) barrier:limit youshould give this command:<pre>vzctl set 101 --shmpages 16384:16384 --save
</pre>
This will give VE 101 64MB of '''shmpages''' (one page equals 4Kb on i386: 4Kb * 16384 = 64Mb)
<pre>
lockedpages 0 0 32 32 0
privvmpages 5238 6885 49152 53575 0
shmpages 5012 5014 8192 8192 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
numiptent 10 10 128 128 0
</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 appropriate this VEexpirienced experienced a resource shortage. This is very common reason, why some applications application fail torun work in a VE. In this case you should increase limits/barriersaccordingly; see[[resource shortage]] for more info.
== Stopping/removing VE ==
Well, let's stop VE and destroy it:
<pre>
Stopping VE ...
VE was stopped
VE is unmounted
VE private area was destroyed
</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 expirience experience some difficulties , contact us via http://forum.openvz.org/ . Templates and other tools at are available from http://download.openvz.org/ . [[Category: Live CD]]