📜 ⬆️ ⬇️

Linux Virtualization with OpenVZ

Often there is a need to post different services across different physical servers. But what if the physical server is one? There is a way - virtualization. In this article I will talk about virtualization technology, which is based on the Linux kernel. We will consider the distribution of Debian, because Recently, the OpenVZ patch has been included in the etch repository. We assume that the OS we have already installed.

PS: Do not kick much, this is my first article on Habré.

So,

Building and installing the kernel


First, install the kernel source and patch:
aptitude update
aptitude install kernel-patch-openvz
aptitude install linux-source-2.6.18

')
We also need utilities for running and managing virtual machines:
aptitude install vzctl vzquota


Unpack the kernel:
cd / usr / src
tar xjvf linux-source-2.6.18.tar.bz2
cd linux-source-2.6.18


Copy the config:
cp /boot/config-2.6.18-4-686 .config


Fix in the config parameter CONFIG_SECURITY it should be set to n . Like this:

CONFIG_SECURITY = n

Install the kernel-package package, it will help us build a package with a patched kernel:
aptitude install kernel-package


We will assemble and install a new kernel:

make-kpkg --append_to_version = -1-openvz --added_patches = openvz --revision = 1 kernel_image
cd ...
dpkg -i linux-image-2.6.18-1-openvz_1_i386.deb
update-initramfs -c -k 2.6.18-1-openvz
update-grub


We edit /boot/grub/menu.lst so that we have a new kernel loaded. Reboot.

If you did everything right, then after the reboot, you will have a new network interface venet.

Creation of virtual machines.



First, let's change the kernel parameters:
sysctl -w net.ipv4.conf.eth0.proxy_arp = 1
sysctl -w net.ipv4.ip_forward = 1


Next, we need at least one OS template (you will find templates on the OpenVZ website).

cd / var / lib / vz / template / cache
wget download.openvz.org/template/precreated/debian-4.0-i386-minimal.tar.gz


Directly create a new machine with VEID 101:
vzctl create 101 --ostemplate debian-4.0-minimal - config vps.basic
vzctl set 101 --onboot yes --save
vzctl set 101 --hostname hostname1.example.com --save
vzctl set 101 --ipadd 192.168.5.1 - save
vzctl set 101 --numothersock 120 --save
vzctl set 101 --nameserver 192.168.0.1 --save
vzctl set 101 --privvmpages 500000: 750000 - save
vzctl start 101
vzctl exec 101 passwd


We go inside:

vzctl enter 101


We check if everything works and enjoy :)

Other utility:



Configuration files are in / etc / vz /
vzctl start command - starts a virtual machine.
vzctl stop command - stops the virtual machine.
vzctl restart command - restarts the virtual machine.

cat / proc / user_beancounters will show the resources used and show their lack.

vzlist will show running virtual machines
vzlist -a will show all configured virtual machines
vzpid $ PID By the pid of the process will show the VEID in which the process is running.

Source: https://habr.com/ru/post/30198/


All Articles