使用cgroup限制普通用户资源

#安装cgroup
yum install -y libcgroup-tools.x86_64 libcgroup


#配置cgconfig
vim /etc/cgconfig.conf
#增加
group JstormGroup {
memory {
memory.limit_in_bytes = "85899345920";
memory.swappiness = 0;
memory.oom_control = 0;
}
cpu {
cpu.rt_period_us="1000000";
cpu.rt_runtime_us="0";
cpu.cfs_period_us="100000";
cpu.cfs_quota_us="-1";
cpu.shares="700";
}
}

#配置cgrules
vim /etc/cgrules.conf
#增加
jstorm cpu,memory JstormGroup/

systemctl start cgconfig.service
systemctl start cgred.service
systemctl status cgconfig.service
systemctl status cgred.service
systemctl enable cgconfig.service
systemctl enable cgred.service

systemctl restart cgconfig.service
systemctl restart cgred.service

#检查:是否已存在,如果不存在,执行:systemctl restart cgconfig.service systemctl restart cgred.service
ll /sys/fs/cgroup/memory/JstormGroup/memory.usage_in_bytes


注:重启顺序为cgconfig -> cgred ,更改配置文件后两个服务需要重启,且顺序不能错


#启动控制
systemctl status|start|stop|enable|disable cgconfig.service
systemctl status|start|stop|enable|disable cgred.service

运维监控:

#监控已使用内存,换算百分比,
/sys/fs/cgroup/memory/JstormGroup/memory.usage_in_bytes
#监控最大限制内存
/sys/fs/cgroup/memory/JstormGroup/memory.limit_in_bytes

猜你喜欢

转载自www.cnblogs.com/water-sky/p/10237172.html