轻量级虚机:CGroup、LXC、Warden
来源:互联网 发布:美工编辑岗位职责 编辑:程序博客网 时间:2024/05/22 12:17
三者的关系
严格的说,Container技术并非虚拟化,更准确的说它是一种资源隔离机制。VMM或者叫Hypervisor是标准的虚拟化技术,这种技术通过虚拟层(也就是VMM或叫Hypervisor)把上层虚拟机的指令转换成底层Host操作系统所认识的指令。所以,虚拟化技术可以在主机上虚拟出各种类型的操作系统,而Container技术只能“虚拟”出与其主机操作系统相同或很类似的“虚拟机”。
一、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.
$ echo 2048 >> /sys/fs/cgroup/cpu/Multimedia/cpu.shares
Second method it’s to use a set of commands
cgset -r cpu.shares=1024 Browsers
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
mariadevices/usergroup/staff
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:maria:ftpdevices/usergroup/staff/ftp
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
字段中的*
代表所有子系统。%
- 代表与以上行中项目相同的项目。例如:
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
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
- 轻量级虚机:CGroup、LXC、Warden
- docker lxc cgroup namespace入门
- docker lxc cgroup namespace简述
- cgroup和LXC的安装
- docker lxc cgroup namespace入门
- linux namespace 和cgroup lxc
- LXC 轻量级虚拟化
- CRIU migration: where are cgroup and lxc ?
- 5.1 linux namespace 和cgroup lxc
- lxc
- LXC
- LXC
- lxc
- Cgroup
- Cgroup
- cgroup
- cgroup
- 虚拟化–操作系统级 LXC Linux Containers内核轻量级虚拟化技术
- Linux route 使用
- Jetty 核心架构分析
- Sizeof与Strlen的区别与联系
- SPRING整合JMS进行网络通信
- eclipse为java类添加版权注释
- 轻量级虚机:CGroup、LXC、Warden
- 每天一个linux命令(10):cat 命令
- 关于指针和const限定符问题的一个简单判断方法
- C++标准模板库 迭代器 iterator 详解(二)
- 把握销售中的八个细节使用适当字眼
- 算法导论 9.1-1 求第二小元素
- 常见浏览器兼容性问题与解决方案
- 千万级并发实现的秘密:内核不是解决方案,而是问题所在!
- 数据库使用skip-name-resolve的注意事项