Linux容器虚拟化LXC的使用

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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
LXCLinux Container)容器虚拟化技术是一种轻量级的虚拟化技术,适用于在单个主机上运行多个相互隔离的应用程序。与传统的虚拟机相比,LXC容器更加轻便和高效。 LXC容器虚拟化技术的研究主要集中在几个方面。首先,研究者致力于提高容器的隔离性。通过实现更严格的资源隔离和访问控制机制,可以保证不同容器之间的资源互不干扰,提高安全性和稳定性。 其次,研究者关注于提升容器的性能。通过针对不同应用场景的性能优化,可以提高容器运行效率和响应速度。例如,使用特定的调度算法来优化容器的CPU、内存和网络资源分配。 此外,研究者还致力于提供更便捷的容器管理工具和技术。例如,开发了一些图形化界面和命令行工具,可以方便地创建、部署和管理容器。同时,为了提高容器的可靠性,研究者还研究了容器的镜像和备份技术,以及容器的自动化部署和扩展技术。 最后,还有一些研究关注于容器的安全性。容器虚拟化技术由于存在共享内核的特点,容器之间存在一定的安全风险。因此,研究者致力于开发能够检测和防御容器安全威胁的技术。例如,通过使用用户命名空间(user namespace)和容器沙盒(container sandbox)等技术,可以增加容器的安全性。 总的来说,LXC容器虚拟化技术的研究方向包括提高容器的隔离性、性能优化、容器管理工具和技术、容器安全性等。通过这些研究,我们可以更好地应用LXC容器技术,提高应用程序的部署效率和资源利用率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值