免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 847 | 回复: 0
打印 上一主题 下一主题

[学习分享] 将LXC安装到Ubuntu上 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-06-04 10:51 |只看该作者 |倒序浏览
$ sudo apt-get install lxc

安装完毕之后,运行lxc-checkconifg工具,检查当前Linux内核支持LXC的情况。要是一切都已被启用,内核对LXC的支持已准备就绪。

$ lxc-checkconfig

安装LXC工具后,你会发现,LXC的默认网桥接口(lxcbr0)已自动创建(已在/etc/lxc/default.conf中加以配置)。

$ ifconfig lxcbr0

创建LXC容器后,窗口的接口就会自动连接到该网桥,那样容器就能与外界进行联系了。
创建LXC容器
在/usr/share/lxc/templates目录下找到可用的LXC模板。
$ ls /usr/share/lxc/templates

1.Create a configration file, named lxc_common.conf:
lxc.network.type = veth
lxc.network.flags = up
lxc.network.name = eth0
lxc.network.link = lxcbr0

2.Change mirrors:
sudo vim /usr/share/lxc/templates/ubuntu

Change this to the faster mirror server you know:
MIRROR=http://archive.ubuntu.com/ubuntu
SECURITY_MIRROR=http://security.ubuntu.com/ubuntu

3.LXC模板其实就是一段脚本而已,用来为某个特定的Linux环境创建容器。你在创建LXC容器时,需要用到这其中一个模板。

比如说,为了创建Ubuntu容器,使用下面这个命令行:
$ sudo lxc-create -n precise -f lxc_common.conf -t ubuntu -- -r precise

4.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.conf

5.Use a fixed ip address for “precise” container, sudo vim /etc/lxc/dnsmasq.conf:
dhcp-host=precise,10.0.3.2

管理LXC容器
既然我们已知道了如何创建及启动LXC容器,现在不妨看看我们可以如何处理运行中的容器。
首先,我们想要访问容器的控制台。为此,键入这个命令:
$ sudo lxc-console -n precise
Restart lxc-net:
$ sudo service lxc-net restart

Start the lxc container:
$ sudo lxc-start -n precise
Stop the lxc container:
$ sudo lxc-stop -n precise
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP