For about 5 years now I have been wanting to limit the cpu of a user in CentOS(6) - without using cloudlinux.
So far, still have not been able to get an answer to this. cgroups seems to be a solution. However, I do not know how to set up the config file.
Here is a question which begins to answer it BUT DOES NOT ANSWER THIS QUESTION. I search again every few months but to no avail.
How to limit an entire user to less than 10% of cpu, not just process?
I seriously need help setting this up as it is really needed.
Here is what I got so far.
I installed the service libcgroup yum install libcgroup.
I checked with ls /cgroup and verified it is installed. I get this output:
blkio cpu cpuacct cpuset devices freezer memory net_cls
Now, I went to the cgconfig.conf file. This is located at /etc/cgconfig.conf
Underneath the mount { ... } section in the cgconfig.conf file, I added the following. I don't know if this is right (don't know if this does 10% of cpu).
I need some help finishing this up so I can finally restrict a user to desired percent of CPU (and, ideally, memory if possible!)
This is to create the group called limitcpu (although I actually want to call it limited group or something because I also want to restrict the memory as well, but for now let's just call it limitcpu group).
group limitcpu {
cpu {
cpu.shares = 200;
# cpu.cfs_period_us
# cpu.cfs_quota_us
}
memory {
}
}
Then I am supposed to use this template:
template users/%g/%u {
cpuacct{
}
cpu {
cpu.shares = "1000";
}
}
%g is supposed to be group name.
%u is supposed to be username.
Ok so say my user that I want to limit is called resourcehoggeruser. How do I complete the above configuration to limit the CPU and emmory allocated to this user?
Should it look something like this?
template users/limitcpu/resourcehoggeruser {
cpuacct{
}
cpu {
cpu.shares = "1000";
}
}
- What else do I need to get this working? Is the above even accurate code?
- Will this do what I want when the code is correct, which is to limit any processes ever spawned by the username to the desired percent of total CPU?
- Is this the correct location in the file to place this code?
What is a "share"? Say I have 16 CPUs and 24GB of RAM.
- What number do I put for
cpu.sharesif I want to have 10% of cpu? - How about 20% of cpu?
How about memory?
- What code do I also use to limit memory to all processes by the user?
- If it uses something like I might guess,
mem.shares, then what would be the "shares" for 10% of memory? How about 20% of memory?
I really appreciate your help! Thank you so much. I really need to get this working. I have searched long and hard and still can't find a clear answer so I really need your help.