mkdocs-benoit.jp.net/docs/Howtos/HowtoLXD.md

85 lines
2.7 KiB
Markdown
Raw Normal View History

2017-08-21 19:49:14 +00:00
Some commands:
2021-02-20 06:06:15 +00:00
```console
$ lxc image alias list images:
$ lxc info <name>
$ lxc config edit <name>
2021-08-30 10:16:26 +00:00
$ lxc config show <name>
2021-02-20 06:06:15 +00:00
$ lxc exec <name> bash
2021-09-03 05:03:53 +00:00
# Some limits
2021-02-20 06:06:15 +00:00
$ lxc config set <name> limits.memory 512MB
$ lxc config set <name> limits.cpu 2
2021-09-03 05:03:53 +00:00
$ lxc config set <name> limits.cpu.allowance 50%
$ lxc config set <name> limits.memory.swap false
$ lxc config device set <name> root limits.read 30MB
2021-09-04 08:54:52 +00:00
$ lxc config device set <name> root limits.write 10MB
2021-09-03 05:03:53 +00:00
$ lxc config device set <name> root limits.read 20Iops
$ lxc config device set <name> root limits.write 10Iops
$ lxc config device override <name> root size=20GB
$ lxc profile device set default eth0 limits.ingress 100Mbit
$ lxc profile device set default eth0 limits.egress 100Mbit
2021-09-04 09:06:16 +00:00
# Port isolation make the container unable to see other containers that are also in port_isolation mode
$ lxc config device set <name> eth0 security.port_isolation=true
$ lxc profile device set default eth0 security.port_isolation=true
2021-09-04 08:54:52 +00:00
$ lxc
2021-08-30 10:16:26 +00:00
$ lxc launch images:debian/11 <name>
2021-02-20 06:06:15 +00:00
$ lxc config set <name> environment.LC_ALL=en_US.UTF-8
$ lxc list
$ lxc storage volume list <storagename>
$ #mode privileged
2021-08-30 10:16:26 +00:00
$ lxc launch ubuntu:20.04 test -c security.privileged=true -c security.nesting=true
2021-02-20 06:06:15 +00:00
$ lxc config device add test ssh proxy listen=tcp:0.0.0.0:2222 connect=tcp:127.0.0.1:22
$ #Create a backups volume in the local (default) pool (ZFS) and use it for backups
$ lxc storage volume create local backups
$ lxc config set storage.backups_volume local/backups
$ #Create a images volume in the local (default) pool (ZFS) and use it for images (containers images downloaded)
$ lxc storage volume create local images
$ lxc config set storage.images_volume local/images
$ lxc config device add $containerName $deviceName disk source=/home/foo path=/home/foo
2021-09-04 10:23:27 +00:00
$ lxc config device add $containerName $deviceName disk source=/dev/<disk> path=/home/foo
```
2021-08-30 10:16:26 +00:00
Path:
2021-08-30 10:18:15 +00:00
2021-08-30 10:16:26 +00:00
- /var/lib/lxd/
- /var/snap/lxd/common/lxd/
2017-09-13 19:46:28 +00:00
2021-08-30 10:16:26 +00:00
Entering LXD namespace managed by snap (to access ZFS mount points for example):
```console
# nsenter -t $(cat /var/snap/lxd/common/lxd.pid) -m
```
2017-09-13 19:46:28 +00:00
2021-08-30 10:16:26 +00:00
Some packages I like to install on fresh containers install:
2017-09-13 19:46:28 +00:00
```
2021-08-30 10:16:26 +00:00
vim
postfix
logrotate
2020-05-05 03:29:16 +00:00
etckeeper
iputils-ping
2017-09-13 19:46:28 +00:00
dnsutils
```
2021-08-30 10:16:26 +00:00
Some initial steps:
2021-08-30 10:18:15 +00:00
2021-08-30 10:16:26 +00:00
- Enable journald
- Set hostname (create /etc/hostname on Archlinux!)
- Configure postfix
2020-05-05 03:29:16 +00:00
2021-08-30 10:16:26 +00:00
Disable getty for old containers images:
2021-02-20 06:06:15 +00:00
```console
2021-08-30 10:16:26 +00:00
# sed -i 's/^tty/# tty/g' /etc/inittab
2017-09-26 20:37:09 +00:00
# systemctl disable getty@tty{1..4}
# reboot
```
2021-08-30 10:16:26 +00:00
Nginx memo:
2021-02-20 06:06:15 +00:00
```nginx
2018-01-10 21:23:59 +00:00
set_real_ip_from W.X.Y.Z;
2020-05-05 10:26:18 +00:00
#real_ip_recursive on;
2018-01-10 21:23:59 +00:00
real_ip_header X-Forwarded-For;
2020-05-05 10:26:18 +00:00
log_format custom '$http_x_forwarded_for - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log /var/log/nginx/access.log custom;
2021-08-30 10:16:26 +00:00
```