Editing Getting started with OpenVZ live CD
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. | + | 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 | + | 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 | + | In the same way, a VE can be based on various [[OS template|OS (Operating System) templates]]. 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 | + | 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. | + | '''vzctl''' is the tool that manages VEs. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== 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 | + | 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 | + | 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> | ||
− | |||
− | |||
== 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. | + | It is also performed via vzctl. Current usage values and limits of memory-related resources can be viewed through |
− | + | /proc/bc/VEID/resources file: | |
<pre> | <pre> | ||
− | + | root@Knoppix:~# cat /proc/bc/60/resources | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | # cat /proc/bc/ | ||
kmemsize 628209 976969 2752512 2936012 0 | kmemsize 628209 976969 2752512 2936012 0 | ||
lockedpages 0 0 32 32 0 | lockedpages 0 0 32 32 0 | ||
Line 231: | Line 215: | ||
numfile 106 339 2048 2048 0 | numfile 106 339 2048 2048 0 | ||
numiptent 10 10 128 128 0 | numiptent 10 10 128 128 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. | 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. | ||
Line 243: | Line 227: | ||
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 | + | 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 some difficulties, contact us via http://forum.openvz.org/. Templates and other tools are available from http://download.openvz.org/. |