Ubuntu 18.04 LTSにおけるLXDの初期設定~コンテナ作成~実行までの手順です。
/etc/sysctl.confへの設定追加
sysctl.confを開き、次の通りカーネルパラメータを追加して保存します。
user.max_user_namespaces = 3883 fs.inotify.max_queued_events = 1048576 fs.inotify.max_user_instances = 1048576 fs.inotify.max_user_watches = 1048576 vm.max_map_count = 262144 net.ipv4.ip_forward = 1
/etc/security/limits.conf への設定追加
limits.confを開き、次の通り設定を追加して保存します。
* soft nofile 1048576 * hard nofile 1048576 root soft nofile 1048576 root hard nofile 1048576 * soft memlock unlimited * hard memlock unlimited
Ubuntu再起動
ここまでの状態で、一旦Ubuntuを再起動します。
# reboot
LXDの初期設定
LXDを初期設定します。なお、環境や運用方法等にあわせ、設定は適宜調整します。
# lxd init Do you want to configure a new storage pool? (yes/no) [default=yes]: Name of the new storage pool [default=default]: Name of the storage backend to use (btrfs, ceph, dir, lvm) [default=btrfs]: dir Would you like to connect to a MAAS server? (yes/no) [default=no]: Would you like to create a new local network bridge? (yes/no) [default=yes]: What should the new bridge be called? [default=lxdbr0]: What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: none Would you like LXD to be available over the network? (yes/no) [default=no]: Would you like stale cached images to be updated automatically? (yes/no) [default=yes] Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]:
コンテナの作成と起動
lxcコマンドでコンテナを作成してみます。以下はUbuntu 18.04コンテナをubuntu-testという名前で作成する場合の例です。
# lxc launch ubuntu:18.04 ubuntu-test
LXDで利用可能なコンテナイメージは、以下のURLより確認いただけます。
- Image server for LXC and LXD
- https://us.images.linuxcontainers.org/
CentOS7コンテナを作成したい場合は、以下の投稿を参照ください。
- LXD上のCentOS7にhttpdをインストールするには(特権コンテナを利用する)
- https://qiita.com/tabimoba/items/a054e6e301739814e60a
コンテナの確認
lxc listを実行すると、作成済みのコンテナを一覧で確認することができます。
# lxc list +-------------+---------+----------------------+------+------------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +-------------+---------+----------------------+------+------------+-----------+ | ubuntu-test | RUNNING | 10.153.159.19 (eth0) | | PERSISTENT | | +-------------+---------+----------------------+------+------------+-----------+
コンテナへ入る(コンテナ上のシェルを利用する)
lxc exec <コンテナ名> /bin/bashを実行すると、指定されたコンテナへ入る(コンテナ上のシェルを利用する)ことができます。
# lxc exec ubuntu-test /bin/bash # cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=18.04 DISTRIB_CODENAME=bionic DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS" # uname -a Linux ubuntu-test 3.10.0-862.14.4.el7.x86_64 #1 SMP Wed Sep 26 15:12:11 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
参考
- lxc/lxd Production setup
- LXDを本番導入するときに気をつけるべき事