centos7系統資源限制整理

 

概述

在linux系統使用過程中,默認的系統設置足夠使用,但是對於一些高並發高性能的程式會有瓶頸存在,這些限制主要通過ulimit查看和修改。

環境

centos:CentOS  release 7.0 (Final)或以上版本

ulimit查看

通過命令查看當前賬戶的限定設置。

ulimit -a

core file size          (blocks, -c) unlimited

data seg size           (kbytes, -d) unlimited

scheduling priority             (-e) 0

file size               (blocks, -f) unlimited

pending signals                 (-i) unlimited

max locked memory       (kbytes, -l) unlimited

max memory size         (kbytes, -m) unlimited

open files                      (-n) 65536

pipe size            (512 bytes, -p) 8

POSIX message queues     (bytes, -q) unlimited

real-time priority              (-r) 0

stack size              (kbytes, -s) 8192

cpu time               (seconds, -t) unlimited

max user processes              (-u) 65536

virtual memory          (kbytes, -v) unlimited

file locks                      (-x) unlimited

 

其中,比較常用的幾個是。

「core file size」(coredump記錄文件大小,默認為0不記錄)。

「open files」(進程打開文件最大數量,默認1024,網路連接較多時會存在瓶頸)。

「max user processes」(用戶最大進程數,多進程程式修改)。

設定

ulimit資源設定的修改分硬限制和軟限制,軟限制無法超過硬限制的上限,硬限制設定需要修改系統配置文件。

格式和說明都在配置文件中有清晰的描述。

vi /etc/security/limits.conf

#Each line describes a limit for a user in the form:

#

#<domain>        <type>  <item>  <value>

#

#Where:

#<domain> can be:

#        - a 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)

#        - data - max data size (KB)

#        - fsize - maximum filesize (KB)

#        - memlock - max locked-in-memory address space (KB)

#        - nofile - max number of open file descriptors

#        - 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 (KB)

#        - 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 values: [-20, 19]

#        - rtprio - max realtime priority

#

#<domain>      <type>  <item>         <value>

* soft core unlimited

* hard core unlimited

* soft data unlimited

* hard data unlimited

* soft fsize unlimited

* hard fsize unlimited

* soft sigpending unlimited

* hard sigpending unlimited

* soft nofile 65536

* hard nofile 65536

* soft msgqueue unlimited

* hard msgqueue unlimited

* soft nproc 65536

* hard nproc 65536

* soft locks unlimited

* hard locks unlimited

* soft memlock unlimited

* hard memlock unlimited

 

修改賬戶啟動執行腳本。

vi ./bash_profile

ulimit -c unlimited

ulimit -d unlimited

ulimit -f unlimited

ulimit -i unlimited

ulimit -n 65536

ulimit -q unlimited

ulimit -u 65536

ulimit -x unlimited

ulimit -l unlimited

總結

實際使用過程中,需要根據伺服器運行的程式放開資源的限制。

 

空空如常

求真得真