This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
технология_lxc [2017/10/04 11:00] val [Запуск/мониторинг/остановка контейнера] |
технология_lxc [2024/04/30 08:40] val [Управление учетными записями в дочерней системе] |
||
---|---|---|---|
Line 2: | Line 2: | ||
* [[http://ru.wikipedia.org/wiki/LXC|LXC wiki]] | * [[http://ru.wikipedia.org/wiki/LXC|LXC wiki]] | ||
- | * [[https://help.ubuntu.com/lts/serverguide/lxc.html|Ubuntu-Руководство по Ubuntu Server-Виртуализация]] | + | * [[https://wiki.debian.org/LXC|debian.org/LXC]] |
+ | * [[https://linuxcontainers.org/lxc/getting-started/|LXC Getting started]] | ||
Line 10: | Line 11: | ||
==== Подготовка сети ==== | ==== Подготовка сети ==== | ||
- | |||
- | * Для режима bridge в lxc понадобиться включить «**неразборчивый режим**» в адаптере | ||
- | * **!!!** В Debian 9 необходимо убрать из ядра [[Модуль AppArmor]] | ||
<code> | <code> | ||
Line 34: | Line 32: | ||
gateway 192.168.X.1 | gateway 192.168.X.1 | ||
| | ||
- | # bridge_ports eth0 | + | bridge_ports eth0 |
- | # bridge_ports enp0s3 | + | |
# bridge_stp off | # bridge_stp off | ||
Line 41: | Line 38: | ||
# post-up /sbin/brctl setfd br0 0 | # post-up /sbin/brctl setfd br0 0 | ||
</code><code> | </code><code> | ||
- | root@server:~# init 6 | + | root@server:~# init 0 |
</code> | </code> | ||
+ | |||
+ | * Для режима bridge в lxc понадобиться включить «**неразборчивый режим**» в адаптере | ||
==== Установка и настройка lxc ==== | ==== Установка и настройка lxc ==== | ||
Line 49: | Line 48: | ||
root@server:~# cat /etc/default/lxc | root@server:~# cat /etc/default/lxc | ||
+ | </code><code> | ||
+ | ... | ||
+ | #[ ! -f /etc/default/lxc-net ] || . /etc/default/lxc-net | ||
+ | </code> | ||
+ | ИЛИ | ||
+ | |||
+ | <code> | ||
root@server:~# cat /etc/default/lxc-net | root@server:~# cat /etc/default/lxc-net | ||
</code><code> | </code><code> | ||
Line 61: | Line 67: | ||
==== Создание ветки дочерней системы ==== | ==== Создание ветки дочерней системы ==== | ||
- | <code> | ||
- | ubuntu# lxc-create -t ubuntu -n www | ||
+ | === Debian === | ||
+ | <code> | ||
debian# lxc-create -t debian -n www | debian# lxc-create -t debian -n www | ||
+ | |||
+ | debian# ###lxc-create -t debian -n www -B lvm --vgname=vg1 --fssize=4G --fstype=ext4 | ||
+ | debian# ###mount /dev/vg1/www /var/lib/lxc/www/rootfs/ | ||
</code> | </code> | ||
+ | === Ubuntu === | ||
+ | <code> | ||
+ | ubuntu# lxc-create -t download -n www -- -d ubuntu -r focal -a amd64 | ||
+ | </code> | ||
==== Установка ПО в дочерней системе ==== | ==== Установка ПО в дочерней системе ==== | ||
<code> | <code> | ||
root@server:~# cp /etc/ssh/sshd_config /var/lib/lxc/www/rootfs/etc/ssh/sshd_config | root@server:~# cp /etc/ssh/sshd_config /var/lib/lxc/www/rootfs/etc/ssh/sshd_config | ||
- | |||
- | root@server:~# rm /var/lib/lxc/www/rootfs/etc/resolv.conf | ||
root@server:~# cp /etc/resolv.conf /var/lib/lxc/www/rootfs/etc/resolv.conf | root@server:~# cp /etc/resolv.conf /var/lib/lxc/www/rootfs/etc/resolv.conf | ||
Line 81: | Line 92: | ||
www:/# apt purge isc-dhcp-client | www:/# apt purge isc-dhcp-client | ||
- | www:/# apt purge resolvconf | + | www:/# apt install nano vim iputils-ping |
- | + | ||
- | www:/# apt install nano | + | |
</code> | </code> | ||
Line 97: | Line 106: | ||
==== Управление учетными записями в дочерней системе ==== | ==== Управление учетными записями в дочерней системе ==== | ||
<code> | <code> | ||
- | www:/# userdel -r ubuntu | ||
- | |||
www:/# passwd | www:/# passwd | ||
+ | ... 123 | ||
www:/# exit | www:/# exit | ||
+ | |||
+ | debian# ###umount /dev/vg1/www | ||
</code> | </code> | ||
Line 111: | Line 121: | ||
</code><code> | </code><code> | ||
... | ... | ||
- | #lxc.network.link = lxcbr0 | + | |
- | ... | + | lxc.net.0.type = veth |
- | # lxc.network.hwaddr = 00:16:3e:5c:c0:fb # need comment | + | lxc.net.0.link = br0 |
- | lxc.network.type = veth | + | lxc.net.0.flags = up |
- | lxc.network.flags = up | + | lxc.net.0.ipv4.address = 192.168.X.20/24 |
- | lxc.network.link = br0 | + | lxc.net.0.ipv4.gateway = 192.168.X.1 |
- | lxc.network.ipv4 = 192.168.X.20/24 | + | |
- | lxc.network.ipv4.gateway = 192.168.X.1 | + | #lxc.start.auto = 1 # now - systemctl enable lxc@www |
- | lxc.start.auto = 1 | + | |
+ | lxc.cgroup2.cpuset.cpus = 0-0 | ||
+ | lxc.cgroup2.cpu.max = 10000 100000 #/sys/fs/cgroup/lxc.payload.www/cpu.max | ||
+ | lxc.cgroup2.memory.max = 512M | ||
+ | lxc.cgroup2.memory.high = 512M #/sys/fs/cgroup/lxc.payload.www/memory.high | ||
</code><code> | </code><code> | ||
root@server:~# lxc-ls -f | root@server:~# lxc-ls -f | ||
Line 131: | Line 146: | ||
root@server:~# lxc-attach -n www -- ps ax | root@server:~# lxc-attach -n www -- ps ax | ||
+ | или | ||
+ | root@server:~# ps -eo pid,cmd,lxc | grep www | ||
+ | |||
root@server:~# lxc-attach -n www -- /bin/bash | root@server:~# lxc-attach -n www -- /bin/bash | ||
Line 136: | Line 154: | ||
root@server:~# lxc-stop -n www | root@server:~# lxc-stop -n www | ||
+ | |||
+ | root@server:~# systemctl start lxc@www | ||
+ | |||
+ | root@server:~# systemctl stop lxc@www | ||
</code> | </code> |