LXC (linux containers)
LXC (Linux Containers) It is a technology virtualization at the level of operating system (SO) for Linux. LXC allows a physical server to run multiple instances of isolated operating systems, known as Virtual Private Servers (SPV or VPS in English) or Virtual Environments (EV). LXC does not provide a virtual machine, rather it provides a virtual environment that has its own process space and networks.
It is similar to other OS-level virtualization technologies such as OpenVZ and Linux-VServer, it also resembles those of other operating systems such as FreeBSD jail and Solaris Containers.
LXC is based on functionality cgroups of the Linux which is available since version 2.6.29, developed as part of LXC. It also builds on other namespace isolation capabilities, which were developed and integrated into the mainline Linux kernel.
Facility
Debian
apt-get install lxc bridge-utils libvirt-bin debootstrap cgroup-bin libcgroup1redhat
yum install lxc bridge-utils febootstrap debootstrap lxc-templateWe create the directory for the container
root@docker:~# mkdir /lxc
root@docker:~# cd /lxc
root@docker:~# mkdir contenedorWe enable cgroup.
root@docker:~# mkdir /cgroup
root@docker:~# echo «none /cgroup cgroup defaults 0 0« >>/etc/fstab
root@docker:~# mount /cgroup
root@docker:~# mkdir /cgroup/contenedorWe configure the network interface:
[root@docker /lxc]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
HWADDR=aa:bb:cc:dd:ee:ff:11:22
ONBOOT=yes
BRIDGE=br0
USERCTL=no
IPV6INIT=no
[root@docker /lxc]# vi /etc/sysconfig/network-scripts/ifcfg-br0
HOSTNANE=host1
DEVICE=br0
ONBOOT=yes
BOOTPROTO=static
DELAY=0
TYPE=Bridge
IPADDR=192.168.1.88
NETWORK=192.168.1.0
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
MTU=1500
DNS1=192.168.1.0
IPV6INIT=no
USERCTL=no[root@docker /lxc]# vi /etc/sysconfig/network-scripts/ifup-post
if [ $DEVNAME = «br0« ]
then
/usr/sbin/brctl setfd br0 0
firoot@docker:~# vi /etc/network/interfaces
auto lo
iface lo inet loopback
auto br0
iface br0 inet static
address 192.168.0.100
netmask 255.255.255.0
gateway 192.168.0.1
bridge_ports eth0
bridge_stp off
bridge_maxwait 5
post-up /usr/sbin/brctl setfd br0 0We create the container.
root@docker:/lxc/contenedor# lxc-create -n redorbita -t debian –lxcpath=/lxc/contenedorWe configure the network interface
We add the following configuration (Modifying the name and IP address):
root@docker:~# cat /lxc/contenedor/redorbita/config
# Template used to create this container: /usr/share/lxc/templates/lxc-debian
# Parameters passed to the template:
# For additional config options, please look at lxc.container.conf(5)
lxc.network.type = empty
lxc.rootfs = /lxc/contenedor/redorbita/rootfs
# Common configuration
lxc.include = /usr/share/lxc/config/debian.common.conf
# Container specific configuration
lxc.mount = /lxc/contenedor/redorbita/fstab
lxc.utsname = redorbita
lxc.arch = amd64
lxc.autodev = 1
lxc.kmsg = 0
# Network configuration
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
#lxc.network.hwaddr = 00:16:3e:64:0b:6e
# Assegnazione IP Address
lxc.network.ipv4 = 192.168.1.80/24
lxc.network.ipv4.gateway = 192.168.1.1
# Autostart
lxc.start.auto = 1
lxc.start.delay = 5
lxc.start.order = 100We start the server
root@docker:/lxc/contenedor# lxc-start -f /lxc/contenedor/redorbita/config -n redorbita -P /lxc/contenedor/ -dWe access through console
root@docker:~# lxc-console -n redorbita -P /lxc/contenedor/
Connected to tty 1
Type <Ctrl+a q> to exit the console, <Ctrl+a Ctrl+a> to enter Ctrl+a itself
Debian GNU/Linux 8 redorbita tty1
redorbita login: root
Password:root@docker:/lxc/contenedor# lxc-ls -f -P /lxc/contenedor/
NAME STATE IPV4 IPV6 AUTOSTART
——————————————————————
redorbita RUNNING 192.168.1.80, – YES
redorbitaweb RUNNING 192.168.1.81 – YESGreetings, rokitoh!
Comments