$ sudo apt-get install lxc安裝完畢之后,運行l(wèi)xc-checkconifg工具,檢查當(dāng)前l(fā)inux內(nèi)核支持LXC的情況。要是一切都已被啟用,內(nèi)核對LXC的支持已準(zhǔn)備就緒。$ lxc-checkconfig安裝LXC工具后,你會發(fā)現(xiàn),LXC的默認(rèn)網(wǎng)橋接口(lxcbr0)已自動創(chuàng)建(已在/etc/lxc/default.conf中加以配置)。$ ifconfig lxcbr0創(chuàng)建LXC容器后,窗口的接口就會自動連接到該網(wǎng)橋,那樣容器就能與外界進(jìn)行聯(lián)系了。創(chuàng)建LXC容器
在/usr/share/lxc/templates目錄下找到可用的LXC模板。
$ ls /usr/share/lxc/templates1.Create a configration file, named lxc_common.conf:
lxc.network.type = vethlxc.network.flags = uplxc.network.name = eth0lxc.network.link = lxcbr02.Change mirrors:
sudo vim /usr/share/lxc/templates/ubuntuChange this to the faster mirror server you know:
MIRROR=http://archive.ubuntu.com/ubuntuSECURITY_MIRROR=http://security.ubuntu.com/ubuntu
3.LXC模板其實就是一段腳本而已,用來為某個特定的Linux環(huán)境創(chuàng)建容器。你在創(chuàng)建LXC容器時,需要用到這其中一個模板。比如說,為了創(chuàng)建Ubuntu容器,使用下面這個命令行:
$ sudo lxc-create -n PRecise -f lxc_common.conf -t ubuntu -- -r precise4.Configure the network,sudo vim /etc/default/lxc-net
, change the configs if you like, I have uncomment this line:
LXC_DHCP_CONFILE=/etc/lxc/dnsmasq.conf5.Use a fixed ip address for “precise” container,sudo vim /etc/lxc/dnsmasq.conf
:
dhcp-host=precise,10.0.3.2管理LXC容器
既然我們已知道了如何創(chuàng)建及啟動LXC容器,現(xiàn)在不妨看看我們可以如何處理運行中的容器。
首先,我們想要訪問容器的控制臺。為此,鍵入這個命令:
$ sudo lxc-console -n precise
Restart lxc-net:
$ sudo service lxc-net restartStart the lxc container:
$ sudo lxc-start -n precise
Stop the lxc container:
$ sudo lxc-stop -n precise詳細(xì)內(nèi)容請看:LXC安裝與配置
新聞熱點
疑難解答
圖片精選