旧版
/etc/init.d/cgconfig restart
vim /etc/cgconfig.conf 控制哪个服务由哪个目录管理
如何创建自己的cgroup
编辑配置文件
vi /etc/cgconfg.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 |
group lesscpu{ cpu{ cpu.shares=100; } } group morecpu{ cpu{ cpu.shares=200; } } |
然后重启服务,会自动生成两个文件
然后将指定的进程分配给我们刚刚给的
1 |
cgexec -g cpu:lesscpu time dd if=/dev/zero of /dev/null bs=1M count=200000 |
1 |
cgexec -g cpu:morecpu time dd if=/dev/zero of /dev/null bs=1M count=200000 |
限制内存:
vi /etc/cgconfg.conf
1 2 3 4 5 6 7 8 9 10 |
group poormem{ memory{ memory.limit_in_bytes=268435456; #物理内存 memory.memsw.limit_in_bytes=268435456; #物理内存+虚拟内存的总量 } } |
然后重启服务,会自动生成两个文件
测试
1 2 |
cgexec -g memory:poormem bigmem 200 cgexec -g memory:poormem bigmem 300 |
磁盘IO的限制
vi /etc/cgconfg.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
group lowio{ blkio{ blkio.weight=100; } } group highio{ blkio{ blkio.weight=200; } } group ddio{ blkio{ blkio.throttle.read_bps_device="8:0 1000000"; } } |
注意,磁盘必须是cfg
1 2 |
cgexec -g blkio:lowio time cat /bigfile1 >/dev/null cgexec -g blkio:highio time cat /bigfile2 >/dev/null |
vi /etc/cgrules.conf
1 2 3 4 5 6 7 8 |
student:dd blkio ddio/ *:dd blkio ddio/ john:* blkio ddio/ *:program blkio ddio/ 这个主要来控制哪个用户执行什么命令的时候通过哪个group限制 |
冻结线程
vi /etc/cgconfig.conf
1 2 3 4 5 |
group stopit{ freezer{ } } |
重启服务
ps as 找到进程号
扔进去:
1 2 3 4 5 6 7 |
echo 2787 >/cgroup/freezer/stopit/tasks echo FROZEN >/cgroup/freezer/stopit/freezer.state 解冻 echo THAWED >/cgroup/freezer/stopit/freezer.state |
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021
广州网站建设 2018/07/17 10:38
已看