LXDで仮想サーバーを立てる

LXD

LXD ホストの設定

LXDホストのネットワーク構成はブリッジにします。

vi /etc/netplan/99-my.yaml
network:
    version: 2
    ethernets:
        enp1s0:
            dhcp4: no
            dhcp6: no
        enp2s0:
            dhcp4: no
            dhcp6: no
        enp3s0:
            dhcp4: no
            dhcp6: no
    bridges:
        br0:
            interfaces: [enp1s0]
            dhcp4: no
            addresses: [192.168.8.3/24]
            parameters:
                stp: false
            dhcp6: yes

        br1:
            interfaces: [enp2s0]
            dhcp4: no
            addresses: [192.168.9.3/24]
            parameters:
                stp: false
            dhcp6: yes

        br2:
            interfaces: [enp3s0]
            dhcp4: no
            addresses: [192.168.23.3/24]
            nameservers:
                addresses: [192.168.23.7, 192.168.23.47]
            parameters:
                stp: false
            dhcp6: no
            routes:
                -to: default
                   via: 192.168.23.10
                - to: 192.168.24.0/24
                    via: 192.168.23.3

ファイルシステムにはzfs を使います。今回は未使用のLVM 論理パーテーション(/dev/vg0/lxd) 100GBを用意します。

pvdisplay
vgdisplay
lvcreate -L 100GB -n lxd vg0

初期設定

lxd init
1. Would you like to use LXD clustering? (yes/no) [default=no]:
2. Do you want to configure a new storage pool? (yes/no) [default=yes]:
3. Name of the new storage pool [default=default]: lxd
4. Name of the storage backend to use (btrfs, dir, lvm, zfs) [default=zfs]:
5. Create a new ZFS pool? (yes/no) [default=yes]:
6. Would you like to use an existing block device? (yes/no) [default=no]: yes
7. Path to the existing block device: /dev/vg0/lxd
8. Would you like to connect to a MAAS server? (yes/no) [default=no]:
9. Would you like to create a new local network bridge? (yes/no) [default=yes]: no
10. Would you like to configure LXD to use an existing bridge or host interface? (yes/no) [default=no]: yes
11. Name of the existing bridge or host interface: br2
12. Would you like LXD to be available over the network? (yes/no) [default=no]:
13. Would you like stale cached images to be updated automatically? (yes/no) [default=yes]
14. Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]: yes

Webサーバーを立てる

lxc init ubuntu:22.04 web-loog
lxc start web-loog
lxc exec web-loog bash

apt update
apt upgrade -y

vi /etc/netplan/99-netplan.yaml