LoginSignup
0
0

More than 5 years have passed since last update.

DebianでLXC1.1をコンパイルしてインストール

Last updated at Posted at 2015-04-12

はじめに

DebianでLXCをコンパイルしてインストールする情報が殆ど無かったのでまとめてみました。
環境構築した時のメモみたいなものなので、適宜自分の環境に読み替えてください。

コンパイル・インストール

$ git clone git@github.com:lxc/lxc.git -b stable-1.1
$ cd lxc
$ sudo apt-get install autoconf automake pkg-config make gcc libcap-dev
$ sudo apt-get install debootstrap bridge-utils dnsmasq-base chkconfig
$ ./autogen.sh && ./configure  --prefix="" && make && sudo make install

無理やりだけど自動起動できるように

$ sudo ln -s /libexec/lxc/lxc-net /etc/init.d/lxc-net
$ sudo ln -s /libexec/lxc/lxc-containers /etc/init.d/lxc-containers
$ sudo chkconfig lxc-containers on
$ sudo chkconfig lxc-net on

dnsmasqが使えるように

/etc/default/lxc-netを編集して、以下を追記

USE_LXC_BRIDGE="true"
LXC_DOMAIN="abcang.net"

名前解決できるように

$ sudo apt-get install resolvconf

/etc/resolvconf/resolv.conf.d/headnameserver 10.0.3.1を追記
/etc/resolvconf/resolv.conf.d/taildomain abcang.netを追記

cgroupをマウント

/etc/fstabに以下を追記

cgroup  /sys/fs/cgroup  cgroup  defaults  0   0

一旦再起動

$ sudo reboot

コンテナの作成

$ sudo lxc-create -t debian -n test

ネットワーク設定

/var/lib/lxc/test/configを編集

lxc.network.type = empty

を削除し、以下を追記

lxc.network.type  = veth
lxc.network.link  = lxcbr0
lxc.network.flags = up

自動起動設定

/var/lib/lxc/test/configに以下を追記

lxc.start.auto = 1
lxc.start.order = 100

ユーザをバインド

以下のサイトを参考に
http://www.clear-code.com/blog/2014/8/6.html

ただし、ホームディレクトリのマウント方法が少し違い、
/var/lib/lxc/test/configに以下のように追記する

lxc.mount.entry = /home/abcang home/abcang none bind,create=dir

コンテナの起動

$ sudo lxc-start -n test

dnsmasqが動いてるか確認

$ ping test -c 1
PING test.abcang.net (10.0.3.102) 56(84) bytes of data.
64 bytes from test.abcang.net (10.0.3.102): icmp_req=1 ttl=64 time=0.033 ms

--- test.abcang.net ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.033/0.033/0.033/0.000 ms

メモ

  • apparmorの導入は諦めた
  • 固定IPにしたかったけど、コンテナを追加するたびにdnsmasqを再起動する必要があるが、あまり運用上再起動させたくないので諦めた
  • 何故か/run/lock/lxcがファイルとして存在していたため、削除した

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0