Quick Installation CentOS 6

From OpenVZ Virtuozzo Containers Wiki
Revision as of 18:19, 5 March 2015 by Sblaydes (talk | contribs) (Added ploop to the OpenVZ utils yum install line.)
Jump to: navigation, search
Warning.svg Warning: This is an unofficial guide, use at your own risk. For an official guide, see Quick installation.

This quick installation quide assumes you have CentOS 6 64-bit installed with SELinux and Firewall disabled, and that the containers will be on the same subnet as the host node.

The node's IP is 192.168.1.99/24 and the gateway is 192.168.1.1. The containers will have 192.168.1.101, 192.168.1.102, etc...

  • Add the OpenVZ yum repo
# wget -O /etc/yum.repos.d/openvz.repo http://download.openvz.org/openvz.repo
# rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ
  • Ensure the yum repo points to RHEL6 packages
# vi /etc/yum.repos.d/openvz.repo
  • Install the OpenVZ kernel and ensure it's the 1st option in grub
# yum install vzkernel
# vi /boot/grub/menu.lst
  • Install the OpenVZ utilities
# yum install vzctl vzquota ploop
  • Tune /etc/sysctl.conf
# vi /etc/sysctl.conf
net.ipv4.ip_forward = 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 = 0
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.conf.default.forwarding=1

The last 2 steps are necessary only if you are planning on using veth containers

  • Create a vmbr0 bridge and add the host's interface to it
# vi /etc/sysconfig/network-scripts/ifcfg-vmbr0 
DEVICE="vmbr0"
BOOTPROTO="static"
IPV6INIT="no"
ONBOOT="yes"
TYPE="Bridge"
DELAY=0
IPADDR=192.168.1.99
NETMASK=255.255.255.0
GATEWAY=192.168.1.1

# vi /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE="eth0"
ONBOOT="yes"
IPV6INIT="no"
TYPE="Ethernet"
BRIDGE="vmbr0"
  • Create /etc/vz/vznet.conf with the following content. This will automatically add/remove the container's interface to the bridge when you start/stop the container.
# vi /etc/vz/vznet.conf 
#!/bin/bash
EXTERNAL_SCRIPT="/usr/sbin/vznetaddbr"
  • Done. Reboot

Create a VENET Container

  • Create a CT
# vzctl create 101 --ostemplate centos-6-x86_64 --config vswap-1g
  • Configure the CT
# vzctl set 101 --save --name server101
# vzctl set 101 --save --onboot yes
# vzctl set 101 --save --hostname server101.example.com
# vzctl set 101 --save --ipadd 192.168.1.101
# vzctl set 101 --save --searchdomain example.com
# vzctl set 101 --save --nameserver 8.8.8.8 --nameserver 8.8.4.4
# vzctl set 101 --save --cpus 4
# vzctl set 101 --save --ram 8G
# vzctl set 101 --save --swap 4G
# vzctl set 101 --save --diskspace 100G
# vzctl start 101
# vzctl exec 101 passwd
  • Done. Enjoy your new VENET container

Create a VETH Container

  • Create a CT
# vzctl create 102 --ostemplate centos-6-x86_64 --config vswap-1g
  • Configure the CT
# vzctl set 102 --save --name server102
# vzctl set 102 --save --onboot yes
# vzctl set 102 --save --hostname server102.example.com
# vzctl set 102 --save --netif_add eth0,,,FE:FF:FF:FF:FF:FF
# vzctl set 102 --save --searchdomain example.com
# vzctl set 102 --save --nameserver 8.8.8.8 --nameserver 8.8.4.4
# vzctl set 102 --save --cpus 4
# vzctl set 102 --save --ram 8G
# vzctl set 102 --save --swap 4G
# vzctl set 102 --save --diskspace 100G
# vzctl start 102
# vzctl exec 102 passwd

FE:FF:FF:FF:FF:FF will ensure a permanent MAC address on the bridge interface.

(Linux bridges behave strangely. They use the smallest MAC address of all the attached interfaces. If you add a new interface to the bridge with an even smaller MAC, the MAC of the bridge will change causing network interruption until the switch re-learns the new MAC)

  • Configure the network of a RHEL-based container
# cat << _EOF_ > /vz/root/102/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
HOSTNAME="server102"
IPV6INIT="no"
MTU="1500"
TYPE="Ethernet"
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.102
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
_EOF_

# vzctl exec 102 /etc/init.d/network restart
  • Configure the network of a Debian-based container
# cat << _EOF_ > /vz/root/102/etc/network/interfaces
auto lo eth0
iface lo inet loopback
iface eth0 inet static
	address 192.168.1.102
	netmask 255.255.255.0
	gateway 192.168.1.1
_EOF_

# vzctl exec 102 /etc/init.d/networking restart
  • Done. Enjoy your new VETH container