设为首页 收藏本站
查看: 502|回复: 0

[经验分享] Linux容器虚拟化LXC的使用

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-12-1 09:20:25 | 显示全部楼层 |阅读模式
Oops:
    万一不能访问,请自带梯子和火星文翻译器
官方网站:
    https://linuxcontainers.org/
Github:
    https://github.com/lxc/lxc


火星文简介:

What's LXC?

LXC is a userspace interface for the Linux kernel containment features.
Through a powerful API and simple tools, it lets Linux users easily create and manage system or application containers.
Features

Current LXC uses the following kernel features to contain processes:

    Kernel namespaces (ipc, uts, mount, pid, network and user)
    Apparmor and SELinux profiles
    Seccomp policies
    Chroots (using pivot_root)
    Kernel capabilities
    Control groups (cgroups)   # 需要用到cgroups子系统

As such, LXC is often considered as something in the middle between a chroot on steroids and a full fledged virtual machine. The goal of LXC is to create an environment as close as possible as a standard Linux installation but without the need for a separate kernel.
Components

LXC is currently made of a few separate components:

    The liblxc library
    Several language bindings for the API:
        python3 (in-tree, long term support in 1.0.x)
        lua (in tree, long term support in 1.0.x)
        Go
        ruby
        python2
        Haskell
    A set of standard tools to control the containers
    Container templates

Licensing

LXC is free software, most of the code is released under the terms of the GNU LGPLv2.1+ license, some Android compatibility bits are released under a standard 2-clause BSD license and some binaries and templates are shipped under the GNU GPLv2 license.
Where do I get it?
From upstream

You can fetch the latest upstream tarballs here or grab it directly from git here or with:

git clone git://github.com/lxc/lxc


------------------------------------------------------------------------------------------
实战部分:
    准备工作:
        系统环境和yum源

wKioL1R6jGuh4ipWAAFM4cYtj7o799.jpg

安装所需软件包:
            1) debootstrap
                debootstrap is used to create a Debian base system from scratch, without
requiring the availability of dpkg or apt.
            2) libvirt
                省去麻烦的配置,直接用这个 ^_^

            3) libcgroup
                Control groups infrastructure. The tools and library help manipulate, control administrate and monitor control groups and the associated controllers.
            4) lxc lxc-templates
                主要包以及模板(等下我们稍微改下模板文件的yum源)
            5) 当然还需要 gcc rsync

wKioL1R6jvHxRlOgAANxmP4mt18724.jpg

启动相关服务:

wKioL1R6kLXz_gWdAAPgSsKfyaE607.jpg    

修改模板文件:

wKiom1R6kR_DxzOJAAIylTLfrQs326.jpg

系统给提供了这么多模板,下面来修改下centos模板的默认源(修改之前自觉备份一个)

wKiom1R6khvgHOPpAADXoI35pVQ427.jpg

开始正式安装:

wKiom1R6k6fgzYVuAAGlLHPyeUU985.jpg

lxc-create creates a container

Options :
  -n, --name=NAME    NAME for name of the container
  -f, --config=file  Initial configuration file
  -t, --template=t   Template to use to setup container

wKiom1R6lHai81NFAAKCrg9llPk992.jpg

修改密码:
    # chroot /var/lib/lxc/centos_1/rootfs passwd

启动虚拟机:
# lxc-start -d -n centos_1

Options :
  -n, --name=NAME        NAME for name of the container
  -d, --daemon           daemonize the container

查看虚拟机状态:
# lxc-info -n centos_1

wKioL1R6ldCQv9exAADVkU_yRrg504.jpg

连过去看看:

wKiom1R6ldfQ-d70AAKg2tzzM3U169.jpg

这样一台就弄好了,如果要做LBC,HAC这类实验,可以克隆多个来实现。

LXC给我们提供了很多管理工具:
lxc-attach
lxc-clone       # 克隆相关
lxc-destroy     # 销毁
lxc-ls          # List containers existing on the system。
lxc-stop        # XD
lxc-usernsexec
lxc-autostart
lxc-config
lxc-execute
lxc-monitor
lxc-top        # top你懂的
lxc-wait
lxc-cgroup
lxc-console
lxc-freeze
lxc-snapshot  # 给一个容器镜像
lxc-unfreeze
lxc-checkconfig
lxc-create    # 创建
lxc-info      # 显示容器状态信息
lxc-start     # 启动
lxc-unshare

Python API:
    Python 3K

    import lxc        container = lxc.Container("p1")    container.create("ubuntu")    container.start()    container.get_ips()    container.stop()
    Python 2.X:
        https://github.com/cloud9ers/pylxc


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-34198-1-1.html 上篇帖子: grep、egrep以及正则表达式的使用 下篇帖子: Error:NFS启动无法绑定IPV6地址报错 Linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表