OpenVZ is container-based virtualization for Linux. OpenVZ creates multiple secure, isolated containers (otherwise known as VEs or VPSs) on a single physical server enabling better server utilization and ensuring that applications do not conflict. Each container performs and executes exactly like a stand-alone server; a container can be rebooted independently and have root access, users, IP addresses, memory, processes, files, applications, system libraries and configuration files. OpenVZ is free open source software, available under GNU GPL.
Before install OpenVZ please remember this:
- OpenVZ was only supported in Ubuntu 8.04 LTS (Hardy Heron), and not in Ubuntu 10.04 (Lucid Lynx)
- At writing moment (november 2010) OpenVZ patch for kernel Linux 2.6.32 works, but is not yet released as stable, and for this reason is not recommended for production environments.
- Ext4 filesystem is not yet supported by vzquota, then if you want to have host kernel stability, better use Ext3 for containers space in /vz or /var/lib/vz
How to install and configure OpenVZ on Ubuntu server:
- Open your terminal and login as root (otherwise you should prepend all the command below with su).
- Just in case your default shell is /bin/dash, you should change it to /bin/bash.:
dpkg-reconfigure dash #install dash as /bin/sh? N
- Just in case you have AppArmor installed, remove it!
/etc/init.d/apparmor stop update-rc.d -f apparmor remove apt-get remove apparmor apparmor-utils
- Find your kernel series:
uname -r #Mine return 2.6.32-24-server
- Install these package below to build a new kernel:
aptitude install kernel-package libncurses5-dev fakeroot wget bzip2 module-assistant debhelper
then build the kernel
aptitude build-dep linux-image-2.6.32-24-server
- Download the 2.6.32 kernel sources plus the OpenVZ kernel patch and the official config for the OpenVZ kernel:
cd /usr/src wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.tar.bz2 m-a prepare wget http://download.openvz.org/kernel/branches/2.6.32/2.6.32-belyayev.1/patches/patch-belyayev.1-combined.gz wget http://download.openvz.org/kernel/branches/2.6.32/2.6.32-belyayev.1/configs/kernel-2.6.32-x86_64.config.ovz
- Then run this command:
kernel-packageconfig echo "CONCURRENCY_LEVEL := 5" >> /etc/kernel-pkg.conf #Note: CONCURRENCY_LEVEL is same as your CPU core + 1. I have 4 core CPU so i make it 5
- Patch the kernel sources and prepare the build:
tar -xpf linux-2.6.32.tar.bz2 mv linux-2.6.32 linux-2.6.32-openvz rm -f linux ln -s linux-2.6.32-openvz linux cd linux gunzip -dc ../patch-belyayev.1-combined.gz | patch -p1 cp -rf ../kernel-2.6.32-x86_64.config.ovz .config make oldconfig
- Build the OpenVZ kernel with the following command:
fakeroot make-kpkg --initrd --append-to-version=-ovz32 --revision=1.0 kernel_image kernel_headers
- Look for new compiled kernel:
cd .. ls -l *.deb # My result: #-rw-r--r-- 1 root src 6300866 2010-11-25 19:18 linux-headers-2.6.32.14-ovz32_1.0_amd64.deb #-rw-r--r-- 1 root src 26274680 2010-11-25 19:12 linux-image-2.6.32.14-ovz32_1.0_amd64.deb
- Install the new kernel:
dpkg -i linux-image-2.6.32.14-ovz32_1.0_amd64.deb linux-headers-2.6.32.14-ovz32_1.0_amd64.deb
- Then update the initrd and the GRUB bootloader configuration:
mkinitramfs -k 2.6.32.14-ovz32 -o /boot/initrd.img-2.6.32.14-ovz32 update-grub
- Build the OpenVZ tools (vzctl, vzquota, vzpkg):
prerequisite:aptitude install git-core git-buildpackage automake autoconf libtool liblockfile-simple-perl cstream liblog-agent-perl ssl-cert postfix rpm yum alien
vzctl:
cd git clone git://git.openvz.org/pub/vzctl vzctl cd vzctl ./autogen.sh ./configure --enable-bashcomp --enable-logrotate make make install make install-debian
vzquota:
cd git clone git://git.openvz.org/pub/vzquota vzquota cd vzquota make make install
vzpkg
cd git clone git://git.openvz.org/pub/vzpkg vzpkg cd vzpkg make install
- Run OpenVS on startup:
update-rc.d vz defaults ln -s /vz /var/lib/vz
15. Check sysctl.conf:
vim /etc/sysctl.conf
Should be like this:
net.ipv4.conf.all.rp_filter=1 net.ipv4.icmp_echo_ignore_broadcasts=1 net.ipv4.conf.default.forwarding=1 net.ipv4.conf.default.proxy_arp = 0 net.ipv4.ip_forward=1 kernel.sysrq = 1 net.ipv4.conf.default.send_redirects = 1 net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.eth0.proxy_arp=1
Reload sysctl.conf:
sysctl -p
- Open /etc/vz/vz.conf and set NEIGHBOUR_DEVS to all:
vim /etc/vz/vz.conf
Set:
NEIGHBOUR_DEVS=all
- Reboot the machine:
reboot
- Check your kernel it should changed now:
uname -r #2.6.32.14-ovz32
OpenVZ is now installed, now we need to make a virtual machine in it:
- Download the OpenVZ template and place it under /vz/template/cache directory. You can download it from this link: http://ftp.openvz.org/template/precreated/contrib/
- I download Ubuntu 10.04 for this example:
cd /vz/template/cache wget http://download.openvz.org/template/precreated/ubuntu-10.04-x86_64.tar.gz
- Set up a VPS from the Ubuntu 10.04 template:
vzctl create 99 --ostemplate ubuntu-10.04-x86_64 --config basic
note: 99 must be a unique id – each virtual machine must have its own unique ID
- Run the virtual machine on boot:
vzctl set 99 --onboot yes --save
- Set a hostname and IP address for the vm:
vzctl set 99 --hostname ivankristianto.com --save vzctl set 99 --ipadd 192.168.0.99 --save
- Set the number of sockets to 120 and assign nameservers:
vzctl set 99 --numothersock 120 --save vzctl set 99 --nameserver 208.67.222.222 --nameserver 208.67.220.220 --save
note: Virtual machine configuration is locate in /etc/vz/conf/{vm-id}.conf
- Start vm:
vzctl start 99
- Now you have a virtual machine. Test it and have fun with it.
Additional vzctl command:
To set a root password:vzctl exec {vm-id} passwd
Connect to vm ssh:
vzctl enter {vm-id}
Stop vm:
vzctl stop {vm-id}
Restart vm:
vzctl restart {vm-id}
Delete vm:
vzctl destroy {vm-id}
List of your vm and status:
vzlist -a
Fin more command in vzctl manual:
man vzctl
Useful links:
- OpenVZ: http://openvz.org/
- Ubuntu: http://www.ubuntu.com/
keren dan simpel, semua komando unix, lihat, priksa dan run!