今回からはいよいよLXCの話題です。まずは開発の歴史と現在の開発体制を少し紹介したあと,
LXCの歴史
LXCはLinuxカーネルにコンテナ関連の機能が実装されはじめた2008年頃から,
その後,
2012年にリリースされたUbuntu 12.
この頃までのLXCは,
2013年9月にはDaniel Lezcano氏が多忙のため,
この後0.
1.
以上のようにUbuntuを中心にして開発が進んでいるため,
- ※1)
- 実際はDaniel Lezcano氏もまだメンテナに名前は連ねています。
LXCの特徴
通常はLXCの特徴というとコンテナが持つ特徴をあげることが多いです。しかしそれは第2回ですでに紹介していますので,
豊富なテンプレート
コンテナを使用する際は,
そこでLXCにはコンテナを作成するためのスクリプトとしてテンプレートが付属しています。テンプレートを使うと,lxc-create
コマンドから直接使えます。
各種ディストリビューションに対応したテンプレートは,
ディストリビューション用のテンプレートだけでなく,
テンプレートは全てシェルスクリプトで書かれていますので簡単にカスタマイズできます。実際,
1.
$ ls /usr/share/lxc/templates/ lxc-alpine lxc-centos lxc-fedora lxc-oracle lxc-ubuntu-cloud lxc-altlinux lxc-cirros lxc-gentoo lxc-plamo lxc-archlinux lxc-debian lxc-openmandriva lxc-sshd lxc-busybox lxc-download lxc-opensuse lxc-ubuntu
テンプレートの中も少し紹介しておきましょう。以下は17個のうちで一番シンプルなlxc-sshdテンプレートの一部です。ご覧のようにシェルスクリプトで書かれていますし,
:
:(略)
:
configure_sshd()
{
rootfs=$1
cat <<EOF > $rootfs/etc/passwd
root:x:0:0:root:/root:/bin/bash
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
EOF
cat <<EOF > $rootfs/etc/group
root:x:0:root
sshd:x:74:
EOF
ssh-keygen -t rsa -N "" -f $rootfs/etc/ssh/ssh_host_rsa_key
ssh-keygen -t dsa -N "" -f $rootfs/etc/ssh/ssh_host_dsa_key
# by default setup root password with no password
cat <<EOF > $rootfs/etc/ssh/sshd_config
Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 768
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords yes
ChallengeResponseAuthentication no
EOF
if [ -n "$auth_key" -a -f "$auth_key" ]; then
u_path="/root/.ssh"
root_u_path="$rootfs/$u_path"
mkdir -p $root_u_path
cp $auth_key "$root_u_path/authorized_keys"
chown -R 0:0 "$rootfs/$u_path"
chmod 700 "$rootfs/$u_path"
echo "Inserted SSH public key from $auth_key into $rootfs/$u_path"
fi
return 0
}
:
:(略)
:
install_sshd $rootfs
if [ $? -ne 0 ]; then
echo "failed to install sshd's rootfs"
exit 1
fi
configure_sshd $rootfs
if [ $? -ne 0 ]; then
echo "failed to configure sshd template"
exit 1
fi
copy_configuration $path $rootfs $name
if [ $? -ne 0 ]; then
echo "failed to write configuration file"
exit 1
fi