XHanch Studio Log in | Register | Cart

Forum

Notifications
Clear all

[How to] Limiting server's resource usage via limits.conf

1 Posts
1 Users
0 Likes
1,179 Views
XHanch
(@xhanch-alt)
Posts: 2105
Member Admin
Topic starter
 

Limiting server resource usage (especially user processes) is essential and very important for running a stable system/server especially when a web server is used by several users (for shared hosting or personal use). The server resource includes memory, CPU usage time, number of process and many more.

For a server that is used by several users, it is very recommended to limit resource usage per user in order to prevent resource outage that will affect the other users. By limiting resource usage per user, you can keep other websites up when a website is trying to use lots of server resource. If you are not doing this, your web server can be totally down only caused by processes that belong to a user or several users. Of course this is not fair for the other users.

As another benefit, this will prevent server attacks such as fork bomb attack, abnormal huge traffic (can be DDoS attack), and so on that will use up your resource to 100% and cause your web server down.

Here is how to limit server resource usage?

To limit server resource usage for a user, you need to edit /etc/security/limits.conf to add usage/limit rules for a user name or group or several/all users. You may type nano /etc/security/limits.conf when you use SSH.
Understanding limits.conf file

<domain> can be:
    - an user name
    - a group name, with @group syntax
    - the wildcard *, for default entry
    - the wildcard %, can be also used with %group syntax, for maxlogin limit

<type> can have the two values:
    - "soft" for enforcing the soft limits
    - "hard" for enforcing hard limits

<item> can be one of the following:
    - core – limits the core file size (KB)

<value> can be one of the following:
    - core – limits the core file size (KB)
    - data – max data size (KB)
    - fsize – maximum filesize (KB)
    - memlock – max locked-in-memory address space (KB)
    - nofile – max number of open files
    - rss – max resident set size (KB)
    - stack – max stack size (KB)
    - cpu – max CPU time (MIN)
    - nproc – max number of processes
    - as – address space limit
    - maxlogins – max number of logins for this user
    - maxsyslogins – max number of logins on the system
    - priority – the priority to run user process with
    - locks – max number of file locks the user can hold
    - sigpending – max number of pending signals
    - msgqueue – max memory used by POSIX message queues (bytes)
    - nice – max nice priority allowed to raise to
    - rtprio – max realtime priority
    - chroot – change root to directory (Debian-specific)

Examples

example hard nproc 200
#prevent example to run more than 200 processes
@ruby hard nproc 75
#prevent anyone in the ruby group from having more than 75 processes
 
Posted : 08/03/2011 2:35 pm
Share:

× Close Menu