Openvz

OpenVZ VPS 上的 LXC 容器

  • January 19, 2016

我正在嘗試在 OpenVZ 中託管的 VPN 上執行 LXC,我嘗試過使用多種圖像風格 ubuntu 來執行此操作。centos,debian ……沒有運氣。LXC 安裝正確,但是由於網路原因容器無法啟動,這似乎與介面的橋接有關!

有沒有人遇到過類似的問題?有誰知道這是否是 OpenVZ 的限制?

從全新的 ubuntu 14.04 安裝開始:

sudo apt-get update 
sudo apt-get install lxc
sudo lxc-create -n p1 -t ubuntu 
sudo lxc-start -n p1 --logfile log.txt
cat log.txt
   lxc-start 1434379565.265 ERROR    lxc_conf - conf.c:instantiate_veth:2949 - failed to create veth pair (vethP4LPC8 and vethO6MP73): Operation not supported
   lxc-start 1434379565.265 ERROR    lxc_conf - conf.c:lxc_create_network:3261 - failed to create netdev
   lxc-start 1434379565.265 ERROR    lxc_start - start.c:lxc_spawn:826 - failed to create the network
   lxc-start 1434379565.265 ERROR    lxc_start - start.c:__lxc_start:1080 - failed to spawn 'p1'
   lxc-start 1434379565.265 ERROR    lxc_start_ui - lxc_start.c:main:342 - The container failed to start.
   lxc-start 1434379565.265 ERROR    lxc_start_ui - lxc_start.c:main:346 - Additional information can be obtained by setting the --logfile and --logpriority options.

並嘗試:

sudo brctl addbr lxcbr0
 add bridge failed: Invalid argument

OpenVZ 是一種作業系統虛擬化技術,與 LXC 和 Docker 一樣,但基於各種核心更新檔,許多從未與主流核心集成。

OpenVZ 基於舊核心(2.6.x),現在不需要很多東西來管理容器(主要是 cgroups)。不幸的是,你不能在 OpenVZ 虛擬環境中執行 LXC 容器。

不要減少其他答案(因為他們正確地聲明 OpenVZ 容器是容器),而是看到這個有趣的連結: OVZ CT 中的 Docker(“自從 OpenVZ 核心 042stab105.4 以來,可以在容器中執行 Docker。這篇文章描述瞭如何。” )

它可能會或可能不會為您的問題提供一些解決方案,但理論上可以在 CT 中使用 cgroups(在比042stab105.4更新的核心上並使用相當新的vzctl)。基本上你需要:

  • 檢查您的核心配置:在給定的核心下嘗試lxc-checkconfig,或CONFIG=/boot/config-2.6.32-openvz-042stab108.2-amd64 lxc-checkconfig用於安裝的任何核心。

如果看起來沒問題,您可以繼續前進,並且:

vzctl set $veid --save --features bridge:on --netif_add eth0 --netfilter full --devnodes net/tun:rw

並在 CT 中掛載自定義 cgroup:

mount -t tmpfs tmpfs /sys/fs/cgroup
mkdir /sys/fs/cgroup/freezer,devices
mount -t cgroup cgroup /sys/fs/cgroup/freezer,devices -o freezer,devices
mkdir /sys/fs/cgroup/cpu,cpuacct,cpuset
mount -t cgroup cgroup /sys/fs/cgroup/cpu,cpuacct,cpuset/ -o cpu,cpuacct,cpuset

這確實是一個有趣的結構,但 ovz 控制項和 cgroup 並非天生不兼容(許多 cgroup 功能是空的存根函式,例如,什麼都不做,但不會發出錯誤消息)。

免責聲明:我還沒有嘗試過(我的核心缺少 cgroup 命名空間)。

另一個有用的連結是這個 Docker 問題跟踪器評論,關於如何用所需的特性編譯你的 OVZ 核心。

引用自:https://serverfault.com/questions/699138