情報技術の四方山話

AI、IoT、ヤマハルータ、VPN、無線LAN、Linux、クラウド、仮想サーバと情報セキュリティのよもやま話

Ubuntu 20.04 LTSにLXC/LXD仮想環境をインストールする

2020-10-10 16:06:46 | Linux/Ubuntu
今回は「Ubuntu 20.04 LTSにLXC/LXD仮想環境をインストールする」です。
弊社では、LXCコンテナ型仮想サーバをシステム構築に活用しています。

■Linuxの配布仕様とリリース情報
takumi@tubs01:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal

takumi@tubs01:~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.1 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
takumi@tubs01:~$


■LXCを試してみる
takumi@tubs01:~$ lxc

コマンド 'lxc' が見つかりません。次の方法でインストールできます:

sudo snap install lxd # version 4.6, or
sudo apt install lxd-installer # version 1
sudo apt install lxd # version 1:0.9

他のバージョンについては 'snap info lxd' を確認してください。
takumi@tubs01:~$


■snapを使ってLXDをインストールする
takumi@tubs01:~$ sudo snap install lxd
2020-10-10T06:44:32+09:00 INFO Waiting for automatic snapd restart...
lxd 4.6 from Canonical✓ installed
takumi@tubs01:~$


■LXDのインストールが成功したことを確認する
takumi@tubs01:~$ sudo lxc list
If this is your first time running LXD on this machine, you should also run: lxd init
To start your first instance, try: lxc launch ubuntu:18.04


+------+-------+------+------+------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+-------+------+------+------+-----------+
takumi@tubs01:~$


■LXDの初期化をする
(*)意識的に全てデフォルトでインストールしています。
takumi@tubs01:~$ lxd init
Would you like to use LXD clustering? (yes/no) [default=no]:
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 (lvm, ceph, btrfs, dir) [default=btrfs]:
Create a new BTRFS pool? (yes/no) [default=yes]:
Would you like to use an existing empty disk or partition? (yes/no) [default=no]:
Size in GB of the new loop device (1GB minimum) [default=5GB]:
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]:
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]:
takumi@tubs01:~$


■LXDコマンドヘルプ
(*)LXCコマンドはLXDコマンドに統合されています。

takumi@tubs01:~$ sudo lxc --help
Description:
Command line client for LXD

All of LXD's features can be driven through the various commands below.
For help with any of those, simply call them with --help.

Usage:
lxc [command]

Available Commands:
alias Manage command aliases
cluster Manage cluster members
config Manage instance and server configuration options
console Attach to instance consoles
copy Copy instances within or in between LXD servers
delete Delete instances and snapshots
exec Execute commands in instances
export Export instance backups
file Manage files in instances
help Help about any command
image Manage images
import Import instance backups
info Show instance or server information
launch Create and start instances from images
list List instances
move Move instances within or in between LXD servers
network Manage and attach instances to networks
operation List, show and delete background operations
profile Manage profiles
project Manage projects
publish Publish instances as images
remote Manage the list of remote servers
rename Rename instances and snapshots
restart Restart instances
restore Restore instances from snapshots
snapshot Create instance snapshots
start Start instances
stop Stop instances
storage Manage storage pools and volumes
version Show local and remote versions

Flags:
--all Show less common commands
--debug Show all debug messages
--force-local Force using the local unix socket
-h, --help Print help
--project string Override the source project
-q, --quiet Don't show progress information
-v, --verbose Show all information messages
--version Print version number

Use "lxc [command] --help" for more information about a command.
takumi@tubs01:~$

■LXCコマンドを実行してみる
takumi@tubs01:~$ lxc-ls

コマンド 'lxc-ls' が見つかりません。次の方法でインストールできます:

sudo apt install lxc-utils

■lxcのコマンドをインストールする
takumi@tubs01:~$ sudo apt install lxc-utils
[sudo] takumi のパスワード:
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
以下の追加パッケージがインストールされます:
dns-root-data dnsmasq-base libidn11 liblxc-common liblxc1 libpam-cgfs lxcfs uidmap
提案パッケージ:
btrfs-tools lxc-templates lxctl
以下のパッケージが新たにインストールされます:
dns-root-data dnsmasq-base libidn11 liblxc-common liblxc1 libpam-cgfs lxc-utils lxcfs uidmap
アップグレード: 0 個、新規インストール: 9 個、削除: 0 個、保留: 0 個。
1,607 kB のアーカイブを取得する必要があります。
この操作後に追加で 5,460 kB のディスク容量が消費されます。
続行しますか? [Y/n] y
.....省略.....
takumi@tubs01:~$

LXCコマンドでCentOS8をインストールする
takumi@tubs01:~$ sudo lxc-create -n DHCP01A -t download
Setting up the GPG keyring
Downloading the image index
---
DIST RELEASE ARCH VARIANT BUILD
---
alpine 3.10 amd64 default 20201009_13:00
alpine 3.10 arm64 default 20201009_13:00
alpine 3.10 armhf default 20201009_13:00
alpine 3.10 i386 default 20201009_13:00
alpine 3.10 ppc64el default 20201009_13:00
alpine 3.10 s390x default 20201009_13:00
alpine 3.11 amd64 default 20201009_13:00
alpine 3.11 arm64 default 20201009_13:00
alpine 3.11 armhf default 20201009_13:00
alpine 3.11 i386 default 20201009_13:00
alpine 3.11 ppc64el default 20201009_13:01
alpine 3.11 s390x default 20201009_13:00
alpine 3.12 amd64 default 20201009_13:00
alpine 3.12 arm64 default 20201009_13:00
alpine 3.12 armhf default 20201009_13:00
alpine 3.12 i386 default 20201009_13:00
alpine 3.12 ppc64el default 20201009_13:00
alpine 3.12 s390x default 20201009_13:00
alpine 3.9 amd64 default 20201009_13:00
alpine 3.9 arm64 default 20201009_13:00
alpine 3.9 armhf default 20201009_13:00
alpine 3.9 i386 default 20201009_13:00
alpine 3.9 ppc64el default 20201009_13:00
alpine 3.9 s390x default 20201009_13:00
alpine edge amd64 default 20201009_13:00
alpine edge arm64 default 20201009_13:00
alpine edge armhf default 20201009_13:00
alpine edge i386 default 20201009_13:00
alpine edge ppc64el default 20201009_13:00
alpine edge s390x default 20201009_13:00
alt Sisyphus amd64 default 20201010_01:17
alt Sisyphus arm64 default 20201010_01:36
alt Sisyphus i386 default 20201010_01:17
alt Sisyphus ppc64el default 20201010_01:17
alt p9 amd64 default 20201010_01:17
alt p9 arm64 default 20201010_01:17
alt p9 i386 default 20201010_01:17
apertis v2019.3 amd64 default 20201008_10:53
apertis v2019.3 arm64 default 20201008_10:53
apertis v2019.3 armhf default 20201008_10:53
apertis v2019.4 amd64 default 20201009_10:53
apertis v2019.4 arm64 default 20201009_10:53
apertis v2019.4 armhf default 20201009_10:53
apertis v2020.1 amd64 default 20201008_10:53
apertis v2020.1 arm64 default 20201008_10:53
apertis v2020.1 armhf default 20201008_10:53
apertis v2020.2 amd64 default 20201009_10:53
apertis v2020.2 arm64 default 20201009_10:53
apertis v2020.2 armhf default 20201009_10:53
archlinux current amd64 default 20201010_04:18
archlinux current arm64 default 20201010_04:18
archlinux current armhf default 20201010_04:18
centos 6 amd64 default 20201009_07:08
centos 6 i386 default 20201009_07:08
centos 7 amd64 default 20201009_07:08
centos 7 armhf default 20201009_07:08
centos 7 i386 default 20201009_07:08
centos 8-Stream amd64 default 20201009_07:08
centos 8-Stream arm64 default 20201009_07:08
centos 8-Stream ppc64el default 20201009_07:08
centos 8 amd64 default 20201009_07:08
centos 8 arm64 default 20201009_07:08
centos 8 ppc64el default 20201009_07:08
debian bullseye amd64 default 20201009_05:24
debian bullseye arm64 default 20201009_05:24
debian bullseye armel default 20201009_05:24
debian bullseye armhf default 20201009_05:40
debian bullseye i386 default 20201009_05:24
debian bullseye ppc64el default 20201009_05:34
debian bullseye s390x default 20201009_05:24
debian buster amd64 default 20201009_05:24
debian buster arm64 default 20201009_05:24
debian buster armel default 20201009_05:24
debian buster armhf default 20201009_05:24
debian buster i386 default 20201009_05:24
debian buster ppc64el default 20201009_05:24
debian buster s390x default 20201009_05:24
debian sid amd64 default 20201009_05:24
debian sid arm64 default 20201009_06:02
debian sid armel default 20201009_05:43
debian sid armhf default 20201009_05:43
debian sid i386 default 20201009_05:24
debian sid ppc64el default 20201009_05:24
debian sid s390x default 20201009_05:24
debian stretch amd64 default 20201009_05:24
debian stretch arm64 default 20201009_06:02
debian stretch armel default 20201009_05:42
debian stretch armhf default 20201009_05:40
debian stretch i386 default 20201009_05:24
debian stretch ppc64el default 20201009_05:24
debian stretch s390x default 20201009_05:24
devuan ascii amd64 default 20201009_11:50
devuan ascii arm64 default 20201009_11:50
devuan ascii armel default 20201009_11:50
devuan ascii armhf default 20201009_11:50
devuan ascii i386 default 20201009_11:50
devuan beowulf amd64 default 20201009_11:50
devuan beowulf arm64 default 20201009_11:50
devuan beowulf armel default 20201009_11:50
devuan beowulf armhf default 20201009_11:50
devuan beowulf i386 default 20201009_11:50
fedora 31 amd64 default 20201009_20:33
fedora 31 arm64 default 20201009_21:11
fedora 31 ppc64el default 20201009_20:33
fedora 31 s390x default 20201009_20:33
fedora 32 amd64 default 20201009_20:33
fedora 32 arm64 default 20201009_20:33
fedora 32 ppc64el default 20201009_20:33
fedora 32 s390x default 20201009_20:33
funtoo 1.4 amd64 default 20201009_17:15
funtoo 1.4 armhf default 20201009_17:16
funtoo 1.4 i386 default 20201009_17:15
gentoo current amd64 default 20201009_16:07
gentoo current armhf default 20201009_16:07
gentoo current i386 default 20201009_16:07
gentoo current ppc64el default 20201009_16:07
gentoo current s390x default 20201009_16:07
kali current amd64 default 20201009_17:15
kali current arm64 default 20201009_17:16
kali current armel default 20201009_17:16
kali current armhf default 20201009_17:16
kali current i386 default 20201009_17:15
mint sarah amd64 default 20201009_09:21
mint sarah i386 default 20201009_08:51
mint serena amd64 default 20201009_09:19
mint serena i386 default 20201009_09:21
mint sonya amd64 default 20201009_09:21
mint sonya i386 default 20201009_08:51
mint sylvia amd64 default 20201009_09:21
mint sylvia i386 default 20201009_09:21
mint tara amd64 default 20201009_09:21
mint tara i386 default 20201009_08:51
mint tessa amd64 default 20201009_08:51
mint tessa i386 default 20201009_08:51
mint tina amd64 default 20201009_08:51
mint tina i386 default 20201009_09:21
mint tricia amd64 default 20201009_09:21
mint tricia i386 default 20201009_08:51
mint ulyana amd64 default 20201009_09:21
opensuse 15.1 amd64 default 20201010_04:20
opensuse 15.1 arm64 default 20201010_04:20
opensuse 15.1 ppc64el default 20201010_04:20
opensuse 15.2 amd64 default 20201010_04:20
opensuse 15.2 arm64 default 20201010_04:20
opensuse 15.2 ppc64el default 20201010_04:20
opensuse tumbleweed amd64 default 20201010_04:20
opensuse tumbleweed arm64 default 20201010_04:43
opensuse tumbleweed i386 default 20201010_04:20
opensuse tumbleweed ppc64el default 20201010_04:27
openwrt 18.06 amd64 default 20201009_11:57
openwrt 19.07 amd64 default 20201009_11:57
openwrt snapshot amd64 default 20201009_11:57
oracle 6 amd64 default 20201009_07:46
oracle 6 i386 default 20201009_07:46
oracle 7 amd64 default 20201009_07:46
oracle 8 amd64 default 20201009_07:46
plamo 6.x amd64 default 20201010_01:33
plamo 6.x i386 default 20201010_01:33
plamo 7.x amd64 default 20201010_01:33
pld current amd64 default 20201009_20:46
pld current i386 default 20201009_20:46
sabayon current amd64 default 20201010_01:52
ubuntu bionic amd64 default 20201009_07:42
ubuntu bionic arm64 default 20201009_08:26
ubuntu bionic armhf default 20201009_07:42
ubuntu bionic i386 default 20201009_07:42
ubuntu bionic ppc64el default 20201009_07:42
ubuntu bionic s390x default 20201009_07:42
ubuntu focal amd64 default 20201009_07:42
ubuntu focal arm64 default 20201009_08:25
ubuntu focal armhf default 20201009_07:42
ubuntu focal ppc64el default 20201009_07:57
ubuntu focal s390x default 20201009_07:42
ubuntu groovy amd64 default 20201009_08:25
ubuntu groovy arm64 default 20201009_07:42
ubuntu groovy armhf default 20201009_08:25
ubuntu groovy ppc64el default 20201009_08:11
ubuntu groovy s390x default 20201009_07:42
ubuntu trusty amd64 default 20201009_07:42
ubuntu trusty arm64 default 20201009_07:42
ubuntu trusty armhf default 20201009_07:42
ubuntu trusty i386 default 20201009_07:42
ubuntu trusty ppc64el default 20201009_07:42
ubuntu xenial amd64 default 20201009_07:42
ubuntu xenial arm64 default 20201009_09:09
ubuntu xenial armhf default 20201009_07:42
ubuntu xenial i386 default 20201009_07:42
ubuntu xenial ppc64el default 20201009_07:42
ubuntu xenial s390x default 20201009_07:42
voidlinux current amd64 default 20201009_17:15
voidlinux current arm64 default 20201009_17:16
voidlinux current armhf default 20201009_17:16
voidlinux current i386 default 20201009_17:15
---
Distribution:
centos
Release:
8
Architecture:
amd64
Downloading the image index
Downloading the rootfs
Downloading the metadata
The image cache is now ready
Unpacking the rootfs
---
You just created a Centos 8 x86_64 (20201009_07:08) container.
takumi@tubs01:~$ sudo lxc-ls -f
NAME STATE AUTOSTART GROUPS IPV4 IPV6 UNPRIVILEGED
DHCP01A STOPPED 0 - - - false


■LXCコマンドでCentOS8を起動する
takumi@tubs01:~$ sudo lxc-attach -n DHCP01A
[root@DHCP01A /]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"


CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="8"

■CentOS8コンテナのカーネル情報
(*)親サーバと同じですね。
[root@DHCP01A /]# uname -a
Linux DHCP01A 5.4.0-48-generic #52-Ubuntu SMP Thu Sep 10 10:58:49 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@DHCP01A /]# ^C
[root@DHCP01A /]#


いつもアクセスありがとうございます。LXC/LXDについては引き続き投稿していきます。引き続きよろしくおねがいします。


コメント    この記事についてブログを書く
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする
« Ubuntu 20.04 LTSのIPv4アド... | トップ | 10GbEインターネット接続-au... »
最新の画像もっと見る

コメントを投稿

ブログ作成者から承認されるまでコメントは反映されません。

Linux/Ubuntu」カテゴリの最新記事