因为很多人一起用一个服务器,所以每当有人编译的时候,其他人就会有一种吃翔的感觉,所以当其他人有用的时候,必须要限制其CPU的使用,所以有了以下的实战
第一步,安装cgroup-bin
sudo apt-get install cgroup-bin
第二步,在/etc下新建一个文件, cgconfig.conf
内容如下:
group mysql_g1 {
cpu {
cpu.shares = 512;
}
}
第三步,修改/etc/cgrules.conf
格式为:
@auser cpu,cpuacct,memory a.com.cn
@buser cpu,cpuacct,memory b.com.cn
@cuser cpu,cpuacct,memory c.com.cn
我的电脑上如下:
wier cpu mysql_g1
第四步,修改/etc/init/cgroup-lite.conf
description “mount available cgroup filesystems”
author “Serge Hallyn serge.hallyn@canonical.com”
start on mounted MOUNTPOINT=/sys/fs/cgroup
pre-start script
test -x /bin/cgroups-mount || { stop; exit 0; }
test -d /sys/fs/cgroup || { stop; exit 0; }
/bin/cgroups-mount
cgconfigparser -l /etc/cgconfig.conf
cgrulesengd
end script
post-stop script
if [ -x /bin/cgroups-umount ]
then
/bin/cgroups-umount
fi
end script
其中,
cgconfigparser -l /etc/cgconfig.conf
cgrulesengd
这两行是我加的,其他是原来就有的
重启,一切OK