📜 ⬆️ ⬇️

Install and configure LXC on Debian 8

On previous versions of Debian, I successfully used OpenVZ virtualization technology. She completely suited me, despite the presence of some controversial points. On Debian 8 Jessie, the installation of this technology was not under any sauce. Later, my guesses about the impossibility of the existence of OpenVZ on Debian 8 and later were confirmed on toster.ru. An alternative was also proposed there - LXC, which I decided to try.

Briefly describe how to install and configure LXC on Debian Jessie.

We will install the LXC in the traditional way - from repositories.

So far, everything is simple:
')
apt-get install lxc lxctl lxc-templates 

Further, our task is to create virtuals on the same network as the host machine. The address of the host machine: 192.168.0.10, virtualka 192.168.0.11-192.168.0.20. Create a virtual network interface and configure the bridge. This will require the bridge-utils package:

 apt-get install bridge-utils 

We make manipulations with the network interface. It is better to do this directly on the terminal of the host machine.
We comment on the current network configuration in / etc / networks / interfaces:

 # allow-hotplug eth0 # iface eth0 inet dhcp 

Add the settings of the bridge there:

 auto br0 iface br0 inet static bridge_ports eth0 bridge_fd 0 bridge_hello 2 bridge_maxage 12 bridge_stp off address 192.168.0.10 netmask 255.255.255.0 gateway 192.168.0.1 broadcast 192.168.0.255 

Next, set up the bridge:

 brctl addbr br0 ifconfig eth0 down brctl setfd br0 0 brctl addif br0 eth0 ifconfig eth0 0.0.0.0 up ifconfig bdr0 192.168.1.2/24 up route add default gw 192.168.1.1 

This configuration step is extremely important. Since creating a virtual machine, it can only get communication with the outside world through a network bridge. After all the changes, you can reboot and make sure that all network interfaces have risen as it should.

 #ifconfig br0 Link encap:Ethernet HWaddr 3c:d9:2b:0c:26:91 inet addr:192.168.0.10 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::3ed9:2bff:fe0c:2691/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:4424607 errors:0 dropped:0 overruns:0 frame:0 TX packets:7829837 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:268042187 (255.6 MiB) TX bytes:11251410291 (10.4 GiB) eth0 Link encap:Ethernet HWaddr 3c:d9:2b:0c:26:91 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:4509932 errors:0 dropped:0 overruns:0 frame:0 TX packets:8137429 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:475678060 (453.6 MiB) TX bytes:11302104498 (10.5 GiB) Interrupt:18 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:122 errors:0 dropped:0 overruns:0 frame:0 TX packets:122 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:11992 (11.7 KiB) TX bytes:11992 (11.7 KiB) 

Now our main interface is br0, and it will roll all the packages onto our virtual machines. We create virtualka. I did not split hairs with disk quotas, giving all virtuals all the free space in the section.

 lxc-create -t debian -n test_01 

Virtualka is created in / var / lib / lxc / <container name>

There is also a config. We go into it and rule the network settings.

Important: all actions with the config need to be performed with the virtualk turned off.

 #     lxc.network.type = veth #    lxc.network.flags = up #      lxc.network.name = eth0 #  ""  - lxc.network.veth.pair = veth-01 #       lxc.network.link = br0 #  lxc.network.ipv4.gateway = 192.168.0.1 # MAC   lxc.network.hwaddr = 00:16:3e:6b:c7:5b # IP          lxc.network.ipv4 = 192.168.0.11/24 

Next, we try to start the virtual machine:
 lxc-start -n test_01 

This command starts the container and immediately makes a login to it. The user is prompted to enter the username and password to the virtual. The password is created during the first launch of the virtual machine and is displayed on the screen. It is important not to forget to write it down! But even if you forgot, you can reset the password from the host machine with the command:

 chroot /var/lib/lxc/< >/rootfs 

then:

 passwd 

enter new password. And back to the host machine:

 exit 

To start the container without entering it, use the command:

 lxc-start -n test_01 –d 

Stop:

 lxc-stop –n test_01 

If for some reason the container does not start, you can enable the log with the command:

 lxc-start --logfile=/var/log/lxc.log -d -n test_01 

If everything went well and the container was launched, then on the host machine you can see the network interface without IP with the name specified in the container config.

 veth-01 Link encap:Ethernet HWaddr fe:2b:3a:ea:60:3f inet6 addr: fe80::fc2b:3aff:feea:603f/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:21888 errors:0 dropped:0 overruns:0 frame:0 TX packets:83943 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1688238 (1.6 MiB) TX bytes:65591423 (62.5 MiB) 

Then you can check the connection by pinging the virtual machine and enter it through the console. From the host machine, you can enter the command:

 lxc-console -n test_01 

You can exit the console by pressing the combination "Ctrl + a" and then "q". View all virtualok:

 lxc-ls –f 

For ease of management and monitoring, you can install the LXC Web Panel:

 wget https://lxc-webpanel.imtqy.com/tools/install.sh -O - | bash 

Once installed, you can go to it by typing in your browser your_ip_address : 5000 / . Login admin , password admin . To periodically update the web panel, use the command:

 wget https://lxc-webpanel.imtqy.com/tools/update.sh -O - | bash 

Conclusion

At first glance, this virtualization system seems somewhat inconvenient to configure, but I liked it because of its brevity and ease of use. When you need to pick up and test a service, but you don’t want to bury the battle server with garbage, the LXC is the right solution. Having studied this technology, I see in it quite ample opportunities for setting up and project prospects in the future.

PS: I hope this article will not allow stepping on the same rake and will save time for those who decide to try LXC as a virtualization system at the operating system level.

Articles that inspired and helped write this topic:

Our experience in testing LXC (Linux Containers) using the example of Debian Wheezy
http://xgu.ru/wiki/LXC
lxc - native linux containers

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


All Articles