虚拟化

作者: 大诗兄_zl | 来源:发表于2018-03-22 09:30 被阅读73次

三者的关系

严格的说,Container技术并非虚拟化,更准确的说它是一种资源隔离机制。VMM或者叫Hypervisor是标准的虚拟化技术,这种技术通过虚拟层(也就是VMM或叫Hypervisor)把上层虚拟机的指令转换成底层Host操作系统所认识的指令。所以,虚拟化技术可以在主机上虚拟出各种类型的操作系统,而Container技术只能“虚拟”出与其主机操作系统相同或很类似的“虚拟机”。

LXC和Warden以及最近火热的Docker都是基于CGroup在其上封装了一层。所以,我们还是一起学习CGroup吧:)

一、CGroup

(1)CGroup简介及用法

http://linuxaria.com/article/introduction-to-cgroups-the-linux-conrol-group?lang=en

控制资源的三种方法:

First method it’s to use the meta-filesystem of cgroups.

|

<pre class="bash" name="code" style="margin: 0px 0px 24px; padding: 0px; font-weight: 400; box-sizing: border-box; background-color: rgb(240, 240, 240); overflow-x: auto; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; line-height: 22px; color: rgb(0, 0, 0);">$ echo 2048 >> /sys/fs/cgroup/cpu/Multimedia/cpu.shares</pre>

|

Second method it’s to use a set of commands

|

<pre class="bash" name="code" style="margin: 0px 0px 24px; padding: 0px; font-weight: 400; box-sizing: border-box; background-color: rgb(240, 240, 240); overflow-x: auto; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; line-height: 22px; color: rgb(0, 0, 0);">cgset -r cpu.shares=1024 Browsers</pre>

|

** Notice, the value of memory.memsw.limit_in_bytes must not less than that of memory.limit_in_bytes. See the following validation:**

root@app-node-v-o:/home/test/memleak# echo 1G >> /sys/fs/cgroup/memory/zhxue/memory.limit_in_bytes

root@app-node-v-o:/home/test/memleak# echo 200M >> /sys/fs/cgroup/memory/zhxue/memory.memsw.limit_in_bytes
bash: echo: write error: Invalid argument
root@app-node-v-o:/home/test/memleak# echo 100M >> /sys/fs/cgroup/memory/zhxue/memory.memsw.limit_in_bytes
bash: echo: write error: Invalid argument
root@app-node-v-o:/home/test/memleak# echo 10G >> /sys/fs/cgroup/memory/zhxue/memory.memsw.limit_in_bytes

The cgred Daemon

Cgred is a daemon that moves tasks into cgroups according to parameters set in the /etc/cgrules.conf file. Entries in the /etc/cgrules.conf file can take one of the two forms:

  • user hierarchies control_group

  • user:command hierarchies control_group

For example:

<pre style="margin: 1.5em 0px; padding: 1em; font-weight: 400; box-sizing: border-box; background-color: rgb(247, 247, 247); overflow: auto; font-family: "Courier New", Courier, Monaco, "Lucida Console", monospace; font-size: 14px; line-height: 1.5em; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; border: 1px solid rgb(221, 221, 221);">maria devices /usergroup/staff</pre>

This entry specifies that any processes that belong to the user named maria access the devices subsystem according to the parameters specified in the /usergroup/staff cgroup. To associate particular commands with particular cgroups, add the command parameter, as follows:

<pre style="margin: 1.5em 0px; padding: 1em; font-weight: 400; box-sizing: border-box; background-color: rgb(247, 247, 247); overflow: auto; font-family: "Courier New", Courier, Monaco, "Lucida Console", monospace; font-size: 14px; line-height: 1.5em; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; border: 1px solid rgb(221, 221, 221);">maria:ftp devices /usergroup/staff/ftp</pre>

The entry now specifies that when the user named maria uses the ftp command, the process is automatically moved to the /usergroup/staff/ftp cgroup in the hierarchy that contains the devices subsystem.

/etc/cgrules.conf 文​​​件​​​中​​​的​​​条​​​目​​​可​​​包​​​括​​​以​​​下​​​额​​​外​​​符​​​号​​​:

  • @ - 当​​​在​​​ user 使​​​用​​​前​​​缀​​​时​​​,代​​​表​​​是​​​一​​​个​​​组​​​群​​​而​​​不​​​是​​​单​​​独​​​用​​​户​​​。​​​例​​​如​​​:@admins 是​​​ admins 组​​​群​​​中​​​的​​​所​​​有​​​用​​​户​​​。​​​

  • * - 代​​​表​​​“​​​所​​​有​​​”​​​。​​​例​​​如​​​:subsystem 字​​​段​​​中​​​的​​​ * 代​​​表​​​所​​​有​​​子​​​系​​​统​​​。​​​

  • % - 代​​​表​​​与​​​以​​​上​​​行​​​中​​​项​​​目​​​相​​​同​​​的​​​项​​​目​​​。​​​例​​​如​​​:

问题:

1)在ubuntu高版本(13.04)上无法更改memsw值:

a. 直接该文件不行

root@ubuntudev:/sys/fs/cgroup/memory# echo 100M >> zhxue/memory.limit_in_bytes root@ubuntudev:/sys/fs/cgroup/memory# echo 100M >> zhxue/memory.memsw.limit_in_bytes
bash: echo: write error: Operation not supported
root@ubuntudev:/sys/fs/cgroup/memory# cat zhxue/memory.limit_in_bytes
104857600
root@ubuntudev:/sys/fs/cgroup/memory# cat zhxue/memory.memsw.limit_in_bytes
cat: zhxue/memory.memsw.limit_in_bytes: Operation not supported

b. 命令更改也无效:

root@ubuntudev:/sys/fs/cgroup/memory# cgset -r memory.memsw.limit_in_bytes=10MB zhxue
cgset: the group can't be modified

注意到memory.memsw.limit_in_bytes和memory.limit_in_bytes文件属性一模一样,为什么不能改?很奇怪。

(2) CGroup原理——很全面的文章

从底层数据结构到上层文件系统,非常有价值。

Linux Cgroups详解 by 王喆锋

http://files.cnblogs.com/lisperl/cgroups%E4%BB%8B%E7%BB%8D.pdf

(3) CGroup文件及参数详解

https://www.kernel.org/doc/Documentation/cgroups/

在内存这块,CGroup默认分配的内存为8PB,请看:

root@ubuntudev:/sys/fs/cgroup/memory# cgcreate -g memory:zhxue

root@ubuntudev:/sys/fs/cgroup/memory# ll zhxue/
cgroup.clone_children memory.memsw.usage_in_bytes
cgroup.event_control memory.move_charge_at_immigrate
cgroup.procs memory.oom_control
memory.failcnt memory.soft_limit_in_bytes
memory.force_empty memory.stat
memory.limit_in_bytes memory.swappiness
memory.max_usage_in_bytes memory.usage_in_bytes
memory.memsw.failcnt memory.use_hierarchy
memory.memsw.limit_in_bytes notify_on_release
memory.memsw.max_usage_in_bytes tasks

root@ubuntudev:/sys/fs/cgroup/memory# cat zhxue/memory.limit_in_bytes
9223372036854775807

root@ubuntudev:/sys/fs/cgroup/memory# cgset -r memory.limit_in_bytes=10M zhxue

root@ubuntudev:/sys/fs/cgroup/memory# cat zhxue/memory.limit_in_bytes
10485760

二、LXC

LXC(Linux containers)配置文件简介

http://www.cnblogs.com/lisperl/archive/2012/04/16/2451215.html

LXC:Linux 容器工具

http://www.ibm.com/developerworks/cn/linux/l-lxc-containers/

Linux 内存不足的解决办法 – 增加虚拟内存 Swap Space

http://www.cpanelcn.info/linux-%E5%86%85%E5%AD%98%E4%B8%8D%E8%B6%B3%E7%9A%84%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95-%E5%A2%9E%E5%8A%A0%E8%99%9A%E6%8B%9F%E5%86%85%E5%AD%98-swap-space.html
转载自:http://blog.csdn.net/zhxue123/article/details/8945236

相关文章

  • kvm虚拟化

    KVM 虚拟化技术 CPU虚拟化技术 内存虚拟化技术 IO虚拟化技术 网络IO虚拟化技术 磁盘IO虚拟化技术 虚拟...

  • 虚拟化技术

    虚拟化技术 分类 按虚拟对象 操作系统虚拟化 平台虚拟化 按方案 软件虚拟化 硬件虚拟化 虚拟机管理器 虚拟化技术...

  • 虚拟化原理

    虚拟化应用:弹性计算处理能力可弹性的服务器。 CPU虚拟化技术 内存虚拟化技术 IO虚拟化技术 开源虚拟化项目 X...

  • 虚拟化笔记

    1.虚拟化:计算机资源的抽象和模拟 2.平台虚拟化实现方式 3.cpu虚拟化 4.内存虚拟化 5.IO虚拟化

  • Docker概念理解

    容器技术 简单介绍 容器技术又称为容器虚拟化 首先是一种虚拟化技术 虚拟化技术包括硬件虚拟化 半虚拟化 操作系统虚...

  • 第三章 大数据平台的架构体系

    大数据基础设施 1.虚拟化服务器虚拟化,存储虚拟化,网络虚拟化,桌面虚拟化2.云计算私有云,社区云,公共云,混合云...

  • 企业部署虚拟化的七大好处

    编者按:目前虚拟化技术已经突破虚拟内存和虚拟服务器两大空间,延伸到网络虚拟化、微处理器虚拟化、文件虚拟化和存储虚拟...

  • 20171207 虚拟化

    虚拟化技术概览KVM简介KVM的管理操作 一、虚拟化技术概览 (一)虚拟化技术类型: 主机虚拟化:xen, kvm...

  • 虚拟化技术入门

    虚拟化技术今天,虚拟化技术的各方面都有了进步,虚拟化也从纯软件逐深入到处理器级虚拟化,再到平台级虚拟化乃至输入/输...

  • docker(一)

    1.什么是容器? 2.容器和虚拟化的区别 linux容器技术,容器虚拟化和kvm虚拟化的区别 kvm虚拟化: 需要...

网友评论

      本文标题:虚拟化

      本文链接:https://www.haomeiwen.com/subject/lcboqftx.html