Installing OpenVZ on CentOS
Server preparation
$ sudo suUpdate the list of packages:
# yum update -yInstall ntp to be able to synchronize time and wget for downloading files:
# yum install ntp wget -ySet the time zone (choose your timezone) and synchronize it with the time server:
# cp /usr/share/zoneinfo/Europe/Chisinau/etc/localtime; ntpdate ru.pool.ntp.orgCreate a task in cron to automatically synchronize the time every day at 00:00:
# mkdir -p /var/cron/tabs && echo '0 0 * * * /usr/sbin/ntpdate ru.pool.ntp.org' >> /var/cron/tabs/crontab && crontab /var/cron/ tabs/crontab && crontab -lSetting up the system for the correct operation of OpenVZ
Edit the system sysctl file to run CentOS with the parameters optimal for OpenVZ:
# nano /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv6.conf.default.forwarding = 1
net.ipv6.conf.all.forwarding = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.all.rp_filter = 1
kernel.sysrq = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0Disable SELINUX:
# echo "SELINUX = disabled"> /etc/sysconfig/selinuxTo make the network work in a virtual machine, we clean the FORWARD chain in iptables and save the settings:
# iptables -F FORWARD && service iptables saveSince there are no necessary packages in the standard repositories, we will connect an additional one. To do this, enter the following two commands:
# wget -P /etc/yum.repos.d/http://ftp.openvz.org/openvz.repo
# rpm --import http://ftp.openvz.org/RPM-GPG-Key-OpenVZInstall OpenVZ:
# yum install vzkernel -yAlso install utilities to manage our virtualization system:
# yum install vzctl vzquota ploop -yCreating a virtual machine (container)
Create a container with the number 128:
# vzctl create 128 --config basicWe configure the network to auto-on at startup:
# vzctl set 128 --onboot yes --saveSet the containers name:
# vzctl set 128 --hostname vps128.local - saveAssign the IP address 192.168.1.10 to the container being created:
# vzctl set 128 --ipdel all --ipadd 192.168.1.10 - saveWe set a name server (DNS) to enable the container to go online and interact with the corporate network:
# vzctl set 128 --nameserver 192.168.2.1 - saveSet the password for the vm’s root account:
# vzctl set 128 --userpasswd root:password --saveYou can limit CPU usage by 15 percent, if you want:
# vzctl set 128 --cpulimit 15 --saveSet the disk quota:
# vzctl set 128 --diskspace 9000000:10000000 --saveSet a delay for exceeding the limit (grace period):
# vzctl set 128 --quotatime 600 --saveDetermine the maximum amount of RAM for the container:
# vzctl set 128 --privvmpages 750M:768M - saveSet the guaranteed amount of memory that the virtual machine will receive:
# vzctl set 128 --vmguarpages 250M:256M - saveUsing this command, start the created container:
# vzctl start 128Frequently used commands to control OpenVZ
* 128 – container number. For each virtual machine it has its own.
Running the container:
# vzctl start 128Container stop:
# vzctl stop 128Restart the container:
# vzctl restart 128Installing the packages in the container:
# vzyum 128 install packagename*Removing package from a virtual machine:
# vzyum 128 remove sambaRun a command in a container (in this example, update the list of repo’s):
# vzctl exec 128 yum update -yList all the installed containers:
# vzlist -aCheck containers status:
# vzctl status 128