GNU/Linux >> Linux の 問題 >  >> Linux

CentOS / RHEL / Ubuntu に LXC Linux コンテナをインストールしてセットアップする方法

LXC は Linux コンテナの略です。

Linux コンテナは、単一の Linux カーネル上の単一の制御ホストで複数の仮想ユニットを同時に実行する軽量の「仮想化」方法です。

Linux カーネルには、リソース分離 (CPU、メモリ、ブロック I/O、ネットワークなど) のための cgroup が含まれており、仮想マシンを起動する必要はありません。

Cgroup は、アプリケーションを完全に分離する名前空間の分離も提供します。プロセス ツリー、ネットワーク、ユーザー ID、マウントされたファイル システムなどの動作環境のビュー。

LXC はオープン ソース ソフトウェアであり、GNU LGPLv2.1+ ライセンスの下でライセンスされています。

コンテナーは実際には、名前空間、cgroup、および chroot と呼ばれるカーネル機能を利用して、含まれる領域を切り離します。

したがって、LXC の最終結果は仮想マシンによく似ていますが、ハイパーバイザーはありません。

1. LXC インストールの前提条件

LXC をインストールする前に、以下に示すように yum update を使用してシステムが最新であることを確認してください。

# yum update

LXC は 2 つのライブラリに依存しています。 libpcap と libcgroup。これには、busybox とブリッジ ユーティリティも必要です。

LXC インストールに必要な次のパッケージをインストールします。

# yum install libcap-devel libcgroup busybox wget bridge-utils

ソース コードからソフトウェアをコンパイルしてインストールするために必要なコンパイラと関連する開発ツールがすべて揃っていることを確認しましょう。

# yum groupinstall "Development tools"

yum グループの詳細については、yum コマンドの記事を参照してください。

2. LXC Linux コンテナをダウンロード

Linux Containers Project から LXC の最新バージョンをダウンロードします。

以下に示すように、wget を使用して、LXC の最新の安定バージョンの tar ボールをマシンにダウンロードします。

# cd /

# wget http://linuxcontainers.org/downloads/lxc-1.1.5.tar.gz

上記の wget の使用中に証明書関連のエラー メッセージが表示された場合は、以下に示すように no-check-certificate オプションを使用してください。

# wget --no-check-certificate https://linuxcontainers.org/downloads/lxc-1.1.5.tar.gz

または、必要に応じて、以下に示すように、git clone を使用して最新の開発バージョンまたは安定バージョンをダウンロードすることもできます。

git clone git://github.com/lxc/lxc -b {branch}

上記のコマンドで、{branch} は、現在の開発ブランチの「マスター」、または 1.0 バージョンの安定した更新ブランチの「stable-1.0」のいずれかになります。

3.ブリッジ アダプターの構成

次に、ブリッジ アダプターを作成し、次の ifcfg-eth0 の例に示すように、ブリッジ アダプターで静的 IP を構成します。 ifcfg-eth0 で、物理アダプターがこのブリッジ アダプターを指していることを確認してください。

# cd /etc/sysconfig/network-scripts	

# vi ifcfg-br0
DEVICE="br0"
BOOTPROTO="static"
IPADDR="xxx.xxx.xxx.xxx"
NETMASK="255.255.255.xxx"
ONBOOT="yes"
TYPE="Bridge"
NM_CONTROLLED="no"

上記のファイルのすべての「xxx」を、IP アドレスとネットワークマスクに一致する値に置き換えます。たとえば、上記のファイルの IPADDR 値をマシンの IP アドレスに変更します。

4. LXC Linux コンテナをインストール

次に、先にダウンロードした LXC tar ボールを untar し、./configure を実行し、make と make install を実行して、以下に示すように LXC をシステムにインストールします。

デフォルトでは、これによりすべての lxc バイナリが /usr/local/bin ディレクトリにインストールされます。

# cd /

# tar xvfz lxc-1.1.5.tar.gz

# cd lxc-1.1.5/

# ./configure

# make && make install

以下は、上記の ./configure コマンドの出力の最後の数行の一部です。

# ./configure
...
...
config.status: creating src/python-lxc/setup.py
config.status: creating src/lua-lxc/Makefile
config.status: executing depfiles commands
config.status: executing default commands
----------------------------
Environment:
 - compiler: gcc
 - distribution: centos
 - init script type(s): sysvinit
 - rpath: no
 - GnuTLS: no
 - Bash integration: yes
Security features:
 - Apparmor: no
 - Linux capabilities: yes
 - seccomp: no
 - SELinux: no
 - cgmanager: no
Bindings:
 - lua: no
 - python3: no
Documentation:
 - examples: yes
 - API documentation: yes
 - user documentation: no
Debugging:
 - tests: no
 - mutex debugging: no
Paths:
 - Logs in configpath: no

以下は、上記の make コマンドの出力の最後の数行です。

# make
...
Building full member lists recursively...
Adding members to member groups.
...
Generating style sheet...
Generating index page...
Generating page index...
Generating example documentation...
Generating file sources...
Generating code for file /usr/save/lxc-1.1.5/src/lxc/attach_options.h...
Generating code for file /usr/save/lxc-1.1.5/src/lxc/lxccontainer.h...
Generating code for file /usr/save/lxc-1.1.5/src/lxc/lxclock.h...
Generating file documentation...
Generating docs for file /usr/save/lxc-1.1.5/src/lxc/attach_options.h...
...
Generating file member index...
make[2]: Leaving directory `/usr/save/lxc-1.1.5/doc/api'
make[2]: Entering directory `/usr/save/lxc-1.1.5/doc'
...
Making all in hooks
make[1]: Entering directory `/usr/save/lxc-1.1.5/hooks'
make[1]: Nothing to be done for `all'.
...

以下は、上記の make install コマンドの出力の最後の数行です。

# make install
...
Making install in hooks
make[1]: Entering directory `/usr/save/lxc-1.1.5/hooks'
 /bin/mkdir -p '/usr/local/share/lxc/hooks'
 /usr/bin/install -c clonehostname mountecryptfsroot ubuntu-cloud-prep squid-deb-proxy-client '/usr/local/share/lxc/hooks'
...
/bin/mkdir -p /usr/local/var/lib/lxc
/bin/mkdir -p /usr/local/var/cache/lxc
 /bin/mkdir -p '/usr/local/lib/pkgconfig'
 /usr/bin/install -c -m 644 lxc.pc '/usr/local/lib/pkgconfig'
...

5. LXC 共有ライブラリのソフト リンクを作成

lxc-info を実行して、LXC が正常にインストールされたことを確認します。すべてが適切にインストールされている場合、指定されたコンテナー名 (test など) が存在しないというメッセージが表示されます。この段階ではコンテナを作成していません。このコマンドが共有ライブラリ関連のエラーをスローしていないことを確認したいだけです。

# lxc-info --name test
test doesn't exist

システムの構成方法によっては、次の liblxc.so.1 ライブラリ関連のエラー メッセージが表示される場合もあります。

# lxc-info --name test
lxc-info: error while loading shared libraries: liblxc.so.1: cannot open shared object file: No such file or directory

この場合、修正するには、以下に示すように libxc.so.1 という名前のリンクを作成します。このリンクは、正しいバージョンの liblxc.so.x.x.x ファイルを指します。

# ln -s /usr/local/lib/liblxc.so.1.1.5 /lib64/liblxc.so.1

# ls -l /lib64/liblxc.so.1
lrwxrwxrwx. 1 root root 30 Jan 20 09:17 /lib64/liblxc.so.1 -> /usr/local/lib/liblxc.so.1.1.5

6. LXC のセットアップと構成を確認する

次に、lxc-checkconfig を実行して、lxc 環境が正しくセットアップされていることを確認することもできます。

次の 4 つの異なるセクションに出力があります:1) 名前空間、2) コントロール グループ、3) その他、および 4) チェックポイント/復元。部分的な出力を以下に示します。

# lxc-checkconfig
Kernel configuration not found at /proc/config.gz; searching...
Kernel configuration found at /boot/config-2.6.32-431.el6.x86_64
--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: enabled
Network namespace: enabled
Multiple /dev/pts instances: enabled
--- Control groups ---
Cgroup: enabled
Cgroup namespace: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
..
--- Misc ---
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
Bridges: enabled
Advanced netfilter: enabled
..
--- Checkpoint/Restore ---
CONFIG_EVENTFD: enabled
CONFIG_EPOLL: enabled
..
Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /usr/local/bin/lxc-checkconfig

システムですべてが適切に構成されている場合、上記の出力では、上記のグループのすべてのオプションが「有効」になっているはずです。

明日、LXC シリーズ記事の次のパートでは、さまざまな lxc コマンドを使用して lxc Linux コンテナーを作成、開始、および使用する方法について説明します。


Linux
  1. Podmanとは何ですか?LinuxにPodmanをインストールする方法

  2. Ubuntu20.04にSuricataIDSをインストールしてセットアップする方法

  3. CentOS / RHEL Linux に OpenLDAP をインストールして構成する方法

  1. CentOS/RHELおよびUbuntuにVMwarePlayerをインストールする方法

  2. GoをFedoraおよびRockyLinux/ Centos/RHELにインストールする方法

  3. RHEL / CentOS 5,6 に telnet をインストールして構成する方法

  1. RHEL 8 / CentOS8Linuxにredmineをインストールする方法

  2. RHEL 8 / CentOS8Linuxでxinetdを使用してサンプルサービスをインストールおよびセットアップする方法

  3. Linux CentOS/RHEL 7 および 8 に zip/unzip パッケージをインストールする方法