The use of Linux container virtualization Lxc

Source: Internet
Author: User
Tags git clone

Oops:

If you cannot access it, bring your own ladder and Mars translator

Official website:

https://linuxcontainers.org/

Github:

Https://github.com/lxc/lxc


Introduction to The Martian text:

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) # need to use cgroups subsystem

As such, LXC is often considered as something in the middle between a chroot on steroids and a full fledged virtual Machin E. 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 compatibilit Y bits is released under a standard 2-clause BSD license and some binaries and templates is shipped under the GNU GPLv2 License.
Where do I get it?
From upstream

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

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

------------------------------------------------------------------------------------------

Actual Combat part:

Preparatory work:

System environment and Yum Source


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/54/28/wKioL1R6jGuh4ipWAAFM4cYtj7o799.jpg "title=" Os_ Yum.png "alt=" Wkiol1r6jguh4ipwaafm4cytj7o799.jpg "/>


To install the required packages:

1) debootstrap

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

2) Libvirt

Eliminate the hassle of configuration, directly with this ^_^

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

Main package and template (wait for us to change the Yum source of the template file slightly)

5) GCC rsync is of course required


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/54/28/wKioL1R6jvHxRlOgAANxmP4mt18724.jpg "title=" yum_ Dep.png "alt=" Wkiol1r6jvhxrlogaanxmp4mt18724.jpg "/>


Start related services:


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/54/28/wKioL1R6kLXz_gWdAAPgSsKfyaE607.jpg "title=" Start_ Server.png "alt=" Wkiol1r6klxz_gwdaapgsskfyae607.jpg "/>


To modify a template file:


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/54/29/wKiom1R6kR_DxzOJAAIylTLfrQs326.jpg "title=" rpm_ Find_templates.png "alt=" Wkiom1r6kr_dxzojaaiyltlfrqs326.jpg "/>


System to provide so many templates, below to modify the next CentOS template of the default source (modified before consciously back up one)


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/54/29/wKiom1R6khvgHOPpAADXoI35pVQ427.jpg "title=" change _temp.png "alt=" Wkiom1r6khvghoppaadxoi35pvq427.jpg "/>


To start a formal installation:


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/54/2A/wKiom1R6k6fgzYVuAAGlLHPyeUU985.jpg "title=" Begin_ Install.png "alt=" 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


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/54/2A/wKiom1R6lHai81NFAAKCrg9llPk992.jpg "title=" Install_success.png "alt=" Wkiom1r6lhai81nfaakcrg9llpk992.jpg "/>


Change Password:

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


To start a virtual machine:

# lxc-start-d-N centos_1


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


To view the status of a virtual machine:

# lxc-info-n Centos_1


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/54/28/wKioL1R6ldCQv9exAADVkU_yRrg504.jpg "title=" vm_ Status.png "alt=" Wkiol1r6ldcqv9exaadvku_yrrg504.jpg "/>


Even look in the past:


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/54/2A/wKiom1R6ldfQ-d70AAKg2tzzM3U169.jpg "title=" Ssh_ Cmd.png "alt=" Wkiom1r6ldfq-d70aakg2tzzm3u169.jpg "/>


Such a set is ready, if you want to do lbc,hac such experiments, you can clone more to achieve.


LXC provides us with a number of management tools:

Lxc-attach
Lxc-clone # Cloning 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 # to a container image
Lxc-unfreeze
Lxc-checkconfig
Lxc-create # Create
Lxc-info # Display Container status information
Lxc-start # 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

The use of Linux container virtualization Lxc

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.