Editing Getting started with OpenVZ live CD

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
This article is written for OpenVZ LiveCD and assumes that the reader only starts using OpenVZ. ([[Download live CD]])
+
This article is written for OpenVZ LiveCD and assumes that the reader only starts using OpenVZ.
  
 
== Introduction ==
 
== Introduction ==
So, as you probably know, OpenVZ allows the user to create [[VE]]s, or Virtual Environments, which seem very much
+
So, as you probably know, OpenVZ allows the user to create [[VE]]s, or Virtual Environments, which seems very much
 
like real computers. Real computer can run various distributions: Debian, Gentoo, Red Hat and  Novell products, etc.
 
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 few minimal OS templates are installed because of disk space limit. Each VE is identified by its number -- a '''VEID'''.
+
In the same way, a VE can be based on various [[OS (Operating System) templates|OS template]]. On the LiveCD only Debian minimal template is installed and it is used by default. Each VE is indentified by its number -- a '''VEID'''.
  
 
== VE creation ==
 
== VE creation ==
Line 10: Line 10:
 
terminal (you must be root):
 
terminal (you must be root):
 
<pre>
 
<pre>
# vzctl create 101 --ostemplate debian-3.1-i386-minimal
+
root@Knoppix:~# vzctl create 101
 
Creating VE private area (debian-3.1-i386-minimal)
 
Creating VE private area (debian-3.1-i386-minimal)
 
Performing postcreate actions
 
Performing postcreate actions
Line 16: Line 16:
 
</pre>
 
</pre>
  
'''vzctl''' is the tool that manages VEs. Look in <tt>/vz/template/cache/</tt> (CentOS LiveCD)
+
'''vzctl''' is the tool that manages VEs.
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.gz
 
debian-3.1-i386-minimal.tar.gz
 
fedora-core-5-i386-minimal.tar.gz
 
</pre>
 
  
 
== List of VEs ==
 
== List of VEs ==
 
You can get the list of all created VEs on '''HN''' (Hardware Node) using '''vzlist''' command:
 
You can get the list of all created VEs on '''HN''' (Hardware Node) using '''vzlist''' command:
 
<pre>
 
<pre>
#  vzlist -a
+
root@Knoppix:~#  vzlist -a
 
       VEID      NPROC STATUS  IP_ADDR        HOSTNAME
 
       VEID      NPROC STATUS  IP_ADDR        HOSTNAME
 
       101          - stopped -              -
 
       101          - stopped -              -
Line 38: Line 31:
 
Let's start it:
 
Let's start it:
 
<pre>
 
<pre>
# vzctl start 101
+
root@Knoppix:~# vzctl start 101
 
Starting VE ...
 
Starting VE ...
 
VE is mounted
 
VE is mounted
 
Setting CPU units: 1000
 
Setting CPU units: 1000
 
VE start in progress...
 
VE start in progress...
# vzlist -a
+
root@Knoppix:~# vzlist -a
 
       VEID      NPROC STATUS  IP_ADDR        HOSTNAME
 
       VEID      NPROC STATUS  IP_ADDR        HOSTNAME
 
       101          5 running                -
 
       101          5 running                -
Line 49: Line 42:
  
 
== Executing commands in VE ==
 
== Executing commands in VE ==
From the "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.
+
From the previous command you see that 5 processes are running inside VE 101. 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:
 
In order to perform any command inside VE `vzctl exec` is used:
 
<pre>
 
<pre>
# vzctl exec 101 ps
+
root@Knoppix:~# vzctl exec 101 ps
 
   PID TTY          TIME CMD
 
   PID TTY          TIME CMD
 
     1 ?        00:00:00 init
 
     1 ?        00:00:00 init
Line 66: Line 59:
 
Any self-respected OS provides a shell for the user. This is how you can get the VE's shell:
 
Any self-respected OS provides a shell for the user. This is how you can get the VE's shell:
 
<pre>
 
<pre>
# vzctl enter 101
+
root@Knoppix:~# vzctl enter 101
 
entered into VE 101
 
entered into VE 101
#
+
Knoppix:/#
 
</pre>
 
</pre>
  
 
In this shell you can do almost all you can do on the real HN. For example create a new user:
 
In this shell you can do almost all you can do on the real HN. For example create a new user:
 
<pre>
 
<pre>
# useradd new-user
+
Knoppix:/# useradd new-user
# passwd new-user
+
Knoppix:/# passwd new-user
 
Enter new UNIX password:
 
Enter new UNIX password:
 
Retype new UNIX password:
 
Retype new UNIX password:
 
passwd: password updated successfully
 
passwd: password updated successfully
# mkdir /home/new-user
+
Knoppix:/# mkdir /home/new-user
# chown new-user /home/new-user/
+
Knoppix:/# chown new-user /home/new-user/
# su new-user
+
Knoppix:/# su new-user
$ cd ~
+
Knoppix:/$ cd ~
$ pwd
+
Knoppix:~$ pwd
 
/home/new-user
 
/home/new-user
 
exit
 
exit
#
+
Knoppix:/#
 
</pre>
 
</pre>
  
 
In order to exit from VEs shell, just type exit:
 
In order to exit from VEs shell, just type exit:
 
<pre>
 
<pre>
# exit
+
Knoppix:/# exit
 
logout
 
logout
 
exited from VE 101
 
exited from VE 101
#
+
root@Knoppix:~#
 
</pre>
 
</pre>
  
Line 100: Line 93:
  
 
<pre>
 
<pre>
# echo 1 > /proc/sys/net/ipv4/ip_forward
+
root@Knoppix:~# echo 1 > /proc/sys/net/ipv4/ip_forward
# ifconfig venet0 up
+
root@Knoppix:~# ifconfig venet0 up
# vzctl set 101 --ipadd 10.1.1.1 --save
+
root@Knoppix:~# vzctl set 101 --ipadd 10.1.1.1 --save
 
Adding IP address(es): 10.1.1.1
 
Adding IP address(es): 10.1.1.1
 
Saved parameters for VE 1
 
Saved parameters for VE 1
# vzlist -a
+
root@Knoppix:~# vzlist -a
 
       VEID      NPROC STATUS  IP_ADDR        HOSTNAME
 
       VEID      NPROC STATUS  IP_ADDR        HOSTNAME
 
       101          4 running 10.1.1.1        -
 
       101          4 running 10.1.1.1        -
Line 112: Line 105:
 
Now your [[Hardware Node]] can ping VE and VE can ping HN:
 
Now your [[Hardware Node]] can ping VE and VE can ping HN:
 
<pre>
 
<pre>
# ping 10.1.1.1
+
root@Knoppix:~# ping 10.1.1.1
 
PING 10.1.1.1 (10.1.1.1) 56(84) bytes of data.
 
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
 
64 bytes from 10.1.1.1: icmp_seq=1 ttl=64 time=3.80 ms
Line 119: Line 112:
 
1 packets transmitted, 1 received, 0% packet loss, time 0ms
 
1 packets transmitted, 1 received, 0% packet loss, time 0ms
 
rtt min/avg/max/mdev = 3.804/3.804/3.804/0.000 ms
 
rtt min/avg/max/mdev = 3.804/3.804/3.804/0.000 ms
#
+
root@Knoppix:~#
# vzctl exec 101 ping 192.168.0.244
+
root@Knoppix:~# vzctl exec 101 ping 192.168.0.244
 
PING 192.168.0.244 (192.168.0.244) 56(84) bytes of data.
 
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
 
64 bytes from 192.168.0.244: icmp_seq=1 ttl=64 time=0.508 ms
  
#
+
root@Knoppix:~#
 
</pre>
 
</pre>
  
Line 133: Line 126:
 
of your node is 192.168.0.244 and nameserver IP address is 192.168.1.1.
 
of your node is 192.168.0.244 and nameserver IP address is 192.168.1.1.
 
<pre>
 
<pre>
# iptables -t nat -A POSTROUTING -s 10.1.1.1 -o eth0 -j SNAT --to 192.168.0.244
+
root@Knoppix:~# iptables -t nat -A POSTROUTING -s 10.1.1.1 -o eth0 -j SNAT --to 192.168.0.244
# vzctl set 101 --nameserver 192.168.1.1 --save
+
root@Knoppix:~# vzctl set 101 --nameserver 192.168.1.1 --save
 
File resolv.conf was modified
 
File resolv.conf was modified
 
Saved parameters for VE 101
 
Saved parameters for VE 101
# vzctl exec 101 ping google.com
+
root@Knoppix:~# vzctl exec 101 ping google.com
 
PING google.com (64.233.167.99) 56(84) bytes of data.
 
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
 
64 bytes from py-in-f99.google.com (64.233.167.99): icmp_seq=1 ttl=241 time=23.0 ms
Line 144: Line 137:
 
== Installing software inside VE ==
 
== 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.
 
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.
+
But of course, you can install any software in VE by yourself. For example, in Debian usual apt-get tool can be used.
  
 
Now, for example, we can install gcc inside VE 101 for developing purposes:
 
Now, for example, we can install gcc inside VE 101 for developing purposes:
 
<pre>
 
<pre>
# vzctl enter 101
+
root@Knoppix:~# vzctl enter 101
 
entered into VE 101
 
entered into VE 101
#
+
Knoppix:/#
# apt-get install gcc
+
Knoppix:/# apt-get install gcc
 
Reading Package Lists... Done
 
Reading Package Lists... Done
 
Building Dependency Tree... Done
 
Building Dependency Tree... Done
Line 190: Line 183:
 
Setting up gcc (3.3.5-3) ...
 
Setting up gcc (3.3.5-3) ...
  
# exit
+
Knoppix:/# exit
 
logout
 
logout
 
exited from VE 101
 
exited from VE 101
#
+
root@Knoppix:~#
 
</pre>
 
</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 ==
 
== Resource limiting ==
 
The very important feature of VE is that you can limit it by resources: CPU, memory, disk space.
 
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 you
+
It is also performed via vzctl. Current usage values and limits of memory-related resources can be viewed through
should give this command:
+
[[/proc/user_beancounters]] file:
 
<pre>
 
<pre>
vzctl set 101 --shmpages 16384:16384 --save
+
root@Knoppix:~# cat /proc/user_beancounters
</pre>
+
Version: 2.5
This will give VE 101 64MB of '''shmpages''' (one page equals 4Kb on i386: 4Kb * 16384 = 64Mb)
+
      uid  resource          held    maxheld    barrier      limit    failcnt
 
+
      101:  kmemsize        628209    976969    2752512    2936012          0
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_beancounters on 2.6.9 kernels
 
            kmemsize        628209    976969    2752512    2936012          0
 
 
             lockedpages          0          0        32        32          0
 
             lockedpages          0          0        32        32          0
 
             privvmpages        5238      6885      49152      53575          0
 
             privvmpages        5238      6885      49152      53575          0
 
             shmpages          5012      5014      8192      8192          0
 
             shmpages          5012      5014      8192      8192          0
 +
            dummy                0          0          0          0          0
 
             numproc              3        11        65        65          0
 
             numproc              3        11        65        65          0
 
             physpages          5084      6020          0 2147483647          0
 
             physpages          5084      6020          0 2147483647          0
Line 230: Line 217:
 
             dcachesize            0          0    1048576    1097728          0
 
             dcachesize            0          0    1048576    1097728          0
 
             numfile            106        339      2048      2048          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
 
             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          0
 +
root@Knoppix:~#
 
</pre>
 
</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 nonzero values in the last column, it means that this VE
+
Note that if you have failcounters in the last column, it means that the appropriate VE
experienced a resource shortage. This is very common reason why some application fail to
+
experienced resource shortage. This is very common reason why some application fail to
work in a VE. In this case you should increase limits/barriers accordingly; see
+
run in a VE. In this case you should increase limits/barriers accordingly; see
 
[[resource shortage]] for more info.
 
[[resource shortage]] for more info.
  
Line 243: Line 256:
 
Well, let's stop VE and destroy it:
 
Well, let's stop VE and destroy it:
 
<pre>
 
<pre>
# vzctl stop 101
+
root@Knoppix:~# vzctl stop 101
 
Stopping VE ...
 
Stopping VE ...
 
VE was stopped
 
VE was stopped
 
VE is unmounted
 
VE is unmounted
# vzctl destroy 101
+
root@Knoppix:~# rm -rf /var/lib/vz/private/101          # THIS STEP IS TEMPORARY: http://bugzilla.openvz.org/show_bug.cgi?id=455
 +
root@Knoppix:~# vzctl destroy 101
 
Destroying VE private area: /var/lib/vz/private/101
 
Destroying VE private area: /var/lib/vz/private/101
 
VE private area was destroyed
 
VE private area was destroyed
#
+
root@Knoppix:~#
 
</pre>
 
</pre>
  
 
== Links ==
 
== 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/ .
+
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/ .
 
  
[[Category: Live CD]]
+
If you expirience some difficulties, contact us via http://forum.openvz.org/. Templates and other tools are available from http://download.openvz.org/.

Please note that all contributions to OpenVZ Virtuozzo Containers Wiki may be edited, altered, or removed by other contributors. If you don't want your writing to be edited mercilessly, then don't submit it here.
If you are going to add external links to an article, read the External links policy first!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)

Template used on this page: