概要
Ubuntu 16.04.5 LTS ServerにLXD(2.0.11)を導入
OSインストール時、DHCPでIPを自動取得
後にブリッジ設定で固定IP付与
コンテナ環境はブリッジ接続でホストと同じセグメントに所属する事にする
自前の検証環境のため、OS設定とLXD設定は、余り深く考えずとりあえず動けば良しとする
OS初期設定
# rootユーザーのパスワード変更
hoge@test:~$ sudo passwd root
# rootユーザーに昇格
hoge@test:~$ su -
# OSアップデート
root@test:~# apt-get update
root@test:~# apt-get -y upgrade
root@test:~# apt-get -y dist-upgrade
# SSH接続用にパッケージインストール
root@test:~# apt-get install -y openssh-server
# IPv6 無効化 設定
root@test:~# cat << "_EOF_" >> /etc/sysctl.conf
> net.ipv6.conf.all.disable_ipv6 = 1
> net.ipv6.conf.default.disable_ipv6 = 1
> _EOF_
# IPv6 無効化 適用
root@test:~# sysctl -p
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
ネットワーク設定
# ブリッジ接続するためのパッケージインストール
root@test:~# apt-get install -y bridge-utils
# ブリッジ設定
root@test:~# vi /etc/network/interfaces
変更前
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
変更後
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet manual
# The primary Bridge interface
auto br0
iface br0 inet static
address 192.168.0.10
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.3.255
gateway 192.168.0.1
dns-nameservers 192.168.0.30
bridge_ports eth0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
# 変更後、一旦、OSを再起動する
root@test:~# reboot
LXDインストール
# パッケージインストール
root@test:~# apt-get install -y lxd lxd-client zfsutils-linux
# バージョン確認
root@test:~# lxd --version
2.0.11
root@test:~# lxc --version
2.0.11
# コンテナリストの表示
root@test:~# lxc list
クライアント証明書を生成します。1分ぐらいかかります...
初めて LXD を使う場合、sudo lxd init と実行する必要があります
初めてコンテナを起動するには、"lxc launch ubuntu:16.04" と実行してみてくだ
さい。
+------+-------+------+------+------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+-------+------+------+------+-----------+
LXD設定
# プロファイル設定
root@test:~# lxc profile edit default
変更後、Ctrl + [X] > [Y] > [Enter]で保存
変更前
config:
environment.http_proxy: http://[fe80::1%eth0]:13128
user.network_mode: link-local
description: Default LXD profile
devices:
eth0:
name: eth0
nictype: bridged
parent: lxdbr0
type: nic
name: default
変更後
config:
environment.http_proxy: ""
user.network_mode: ""
description: Default LXD profile
devices:
eth0:
name: eth0
nictype: bridged
parent: br0
type: nic
name: default
# LXD設定
root@test:~# lxd init
Do you want to configure a new storage pool (yes/no) [default=yes]? (Enter)
Name of the storage backend to use (dir or zfs) [default=zfs]: (Enter)
Create a new ZFS pool (yes/no) [default=yes]? (Enter)
Name of the new ZFS pool or dataset [default=lxd]: (Enter)
Would you like to use an existing block device (yes/no) [default=no]? (Enter)
Size in GB of the new loop device (1GB minimum) [default=100]: (Enter)
Would you like LXD to be available over the network (yes/no) [default=no]? (Enter)
Do you want to configure the LXD bridge (yes/no) [default=yes]? (Enter)
Containers need a bridge to connect....
<いいえ>
If you have an existing bridge you want to...
<はい>
A valid network interface name...
br0
LXD has been successfully configured.
# 一旦、OSを再起動する
root@test:~# reboot
コンテナーの作成
# CentOS7のイメージでコンテナーを作成する
root@test:~# lxc launch images:centos/7/amd64 server1
server1 を作成中
server1 を起動中
# コンテナーの存在確認
root@test:~# lxc list
+---------+---------+----------------------+------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+---------+---------+----------------------+------+------------+-----------+
| server1 | RUNNING | 192.168.0.xxx (eth0) | | PERSISTENT | 0 |
+---------+---------+----------------------+------+------------+-----------+
# コンテナー内へ接続
root@test:~# lxc exec server1 bash
[root@server1 ~]#
完了
コンテナー操作メモ
# コンテナーの起動
lxc start <コンテナ名>
# コンテナーの停止
lxc stop <コンテナ名>
# コンテナーのスナップショット作成
lxc snapshot <コンテナ名> <スナップショット名>
# コンテナーのスナップショットからリストア
lxc restore <コンテナ名> <スナップショット名>
# コンテナーのコピー
lxc copy <コピー元コンテナ名> <コピー先コンテナ名>
# コンテナーの削除
lxc delete <コンテナ名>