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
总结
实际使用过程中,需要根据服务器运行的程序放开资源的限制。
空空如常
求真得真