Use of Linux container virtualization LXC

Source: Internet
Author: User

Use of Linux container virtualization LXC

Oops:

In case of access failure, please bring your own ladder and Mars Translator

Official Website:

Https://linuxcontainers.org/

Github:

Https://github.com/lxc/lxc

 

Introduction to Mars:

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 cmdt_root)
Kernel capabilities
Control groups (cgroups) # cgroups subsystem is required

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 tarbils here or grab it directly from git here or:

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

Bytes ------------------------------------------------------------------------------------------

Practice:

Preparations:

System Environment and yum Source

 

 

Install the required software package:

1) debootstrap

Debootstrap is used to create a Debian base system from scratch,
Requiring the availability of dpkg or apt.

2) libvirt

Skip the hassle of using this ^_^

3) libcgroup

Control groups infrastructure. The tools and library help manipulate, control administrate and monitor control groups and the associated controllers.

4) lxc-templates

MAIN package and template (wait for us to slightly change the yum source of the template file)

5) Of course, gcc rsync is also required.

 

 

Start related services:

 

 

Modify the template file:

 

 

The system provides so many templates. Next, modify the default source of the centos template (back up a template before modification)

 

 

Start official installation:

 

 

Lxc-create creates a container

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

 

 

Change Password:

# Chroot/var/lib/lxc/centos_1/rootfs passwd

 

Start the VM:

# Lxc-start-d-n centos_1


Options:
-N, -- name = NAME for name of the container
-D, -- daemon daemonize the container

 

View the virtual machine status:

# Lxc-info-n centos_1

 

 

Let's take a look:

 

 

This is done. If you want to perform LBC, HAC, and other experiments, you can clone multiple ones for implementation.

 

LXC provides us with many management tools:

Lxc-attach
Lxc-clone # clone related
Lxc-destroy # 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, you know.
Lxc-wait
Lxc-cgroup
Lxc-console
Lxc-freeze
Lxc-snapshot # image for a container
Lxc-unfreeze
Lxc-checkconfig
Lxc-create # create
Lxc-info # display container status information
Lxc-start # start
Lxc-unshare

 

Python API:

Python 3 K

    import lxc        container = lxc.Container("p1")    container.create("ubuntu")    container.start()    container.get_ips()    container.stop()

 

Python 2.X:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.