Experience containers in libvirt

Source: Internet
Author: User

Experience containers in libvirt

Libvirt is a general virtualization framework that supports xen, kvm, and lxc Virtualization Technologies.

Set LXC to default (qemu by default)

Export LIBVIRT_DEFAULT_URI = lxc :///

Virsh-c lxc: // can be omitted

Network Settings

NAT

NAT is provided by libvirt by default, which is called default. You can view it using the following command:

Virsh net-list

Assume that the host machine has two NICs, eth0 is the Intranet, and eth1 is the Internet. We can connect two interfaces for the container Bridge:

# Cat lan. xml

<Network>

<Name> lan </name>

<Forward mode = "bridge"/>

<Interface dev = "eth0"/>

</Network>


# Cat wan. xml

<Network>

<Name> wan </name>

<Forward mode = "bridge"/>

<Interface dev = "eth1"/>

</Network>

Import Configuration

Virsh net-define lan. xm

Virsh net-define wan. xml


Enable Nic

Virsh net-start lan

Virsh net-autostart lan

Virsh net-start wan

Virsh net-autostart wan

Application container

The application container shares various resources of the host machine, including the kernel, various software packages, and various libraries. It has only one independent runtime space, such as a sandbox environment.

Create an application container named web

Cat web. xml

<Domain type = "lxc">

<Name> web </name>

<Memory> 102400 </memory>

<OS>

<Type> exec </type>

<Init>/bin/sh </init>

</OS>

<Device>

<Console type = "pty"/>

</Device>

</Domain>

Import virsh

Virsh define web. xml

Start

Virsh autostart web

Enter container

Virsh console web

Edit container configuration

Virsh edit web

Delete container

Virsh undefine web

Operating system container

In addition to the Linux kernel, operating system containers contain a complete running environment, such as a chroot environment.

Creating operating system containers is a little complicated

1. Create a root directory

Mkdir-p/lxc/CentOS7

2. Download and unzip the image http://images.linuxcontainers.org/images/centos/7/amd64/default/20140807_02:37/rootfs.tar.xz

Cd/lxc/centos7

Wget xxx

Xz-d rootfs.tar. xz

Tar xvf rootfs.tar


3. Create an xml template

Cat centos7.xml

<Domain type = "lxc">

<Name> centos7 </name>

<Memory unit = "KiB"> 1048576 </memory>

<CurrentMemory unit = "KiB"> 1048576 </currentMemory>

<Resource>

<Partition>/machine </partition>

</Resource>

<OS>

<Clock offset = 'utc'/>

<On_poweroff> destory </on_poweroff>

<On_reboot> restart </on_reboot>

<On_crash> restart <on_crash>

</Devices>

<Emulator>/usr/lib/libvirt/libvirt_lxc </emulator>

<Filesystem type = 'mount' accessmode = 'passthrough '>

<Source dir = '/lxc/centos7'/>

<Target dir = '/>

</Filesystem>

<Interface type = 'network'>

<Mac address = '00: 16: 3e: 52: 87: f1 '/>

<Source network = 'lan '/>

</Interface>

<Console type = 'PTY'>

<Target type = 'lxc 'port = '0'/>

</Console>

</Devices>

</Domain>

Import container

Virsh define centos7.xml

Start container

Virsh start centos7

Virsh autostart centos7

Enter container

Virsh console centos7

Stop startup

Virsh autostart -- disable centos7

Exit lxc console

Ctrl +]

Use libvirt to create and manage KVM virtual machines

Use Libvirt to connect to the KVM virtualization platform

This article permanently updates the link address:

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.