zoukankan      html  css  js  c++  java
  • 如何在Ubuntu上创建及管理LXC容器?

    将LXC安装到Ubuntu上

    $ 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

    详细内容请看:LXC安装与配置
  • 相关阅读:
    Eclipse “cannot be resolved to a type” error
    Hadoop作业提交分析(三)
    Hadoop作业提交分析(五)
    Hadoop作业提交分析(一)
    An Idiot Computer Story
    基于ASP.NET的comet简单实现
    火车票余票查询小助手(windows 7 gadget)
    Div+CSS+JQuery轻松实现选项卡"选项卡"
    jQuery+Div Simple menu
    Visual Studio 2010 cannot goto definition
  • 原文地址:https://www.cnblogs.com/dragon1013/p/4432012.html
Copyright © 2011-2022 走看看