Fedora20  lxc 试用

Linux container 是除了xen, kvm,vSphere外的另一种虚拟化选择方案。

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)

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 (python3, lua and Go)

A set of standard tools to control the containers

Container templates


1,yum -y install lxc*


155041992.png


2,lxc宿主主机配置


首先介绍几个文件夹(默认通过yum安装将自动生成以下文件/文件夹)


1). /etc/lxc/default.conf


创建容器时若未指定配置文件,则默认使用这个default.conf作为该容器的配置文件


2). /usr/share/lxc/templates/


该目录下保存了LXC支持的各种发行版的linux模板,通常有:

155043643.png


3). /var/lib/lxc/


这个目录是用来存放容器实例的,默认情况下该文件夹只有管理员才有权限访问读写其中文件


4). /var/cache/lxc/


第一次创建容器,需要下载一个mini版的容器系统,很快就好了,创建好后,将会在该目录下创建缓存,再次创建直接采用缓存无须再网上下载.


3,检验lxc是否已安装好

lxc-verison

如果显示 lxc version: x.x.x表示安装成功。这里x表示版本号,我安装的是lxc version:0.9.0

lxc-checkconfig

155046488.png


4,lxc基本命令用法

lxc-create -t oracle  -n o1

这里以lxc-oracle为模板,由于本机是fedora20,我发现还可以用lxc-fedora为模板,但是用lxc-ubuntu和lxc-debian时创建时不成功。

创建时需要比较长的时间先到镜像点下载对应镜像我这里是oracle

155048332.png


lxc-start  -n o1

开启容器o1,用oracle用户名,oracle密码登陆

155050254.png


lxc-ls --fancy o1

查看容器基本信息

155052645.png


lxc-console -n o1

连接容器o1,这是lxc容器里面的基本操作,更单独机器差不多,除了网络单独分出来,cpu和内存共享主机的。

155054621.png


lxc-stop -n o1

停止容器o1

还有其他命令,如想加深了解可以看man帮助

155056736.png