1. 程式人生 > >Cent OS下修改用戶打開文件數限制

Cent OS下修改用戶打開文件數限制

linux ulimit 文件數限制

如果有用戶test,現在需要修改此用戶打開文件數限制,步驟如下:
1 修改Linux下資源使用的配置文件,添加以下參數:
sudo vim /etc/security/limits.conf
test soft nproc 65534
test hard nproc 65534
test soft nofile 65534
test hard nofile 65534

參數說明:
nproc:用戶可用的最大進程數量
nofile:用戶可打開的最大文件總數
soft即是軟限制,hard是硬限制。用戶可以超過soft設置的值,但一定不能超過hard 的值。一般soft比hard小
test:代表用戶,可以用 “*” 表示,代表所有用戶

2 退出當前Sehll,重新登陸,輸入下面的命令即可看見參數已經發現改變:
[test@localhost ~]$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 1821
max locked memory (kbytes, -l) 64

max memory size (kbytes, -m) unlimited
open files (-n) 65534
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 65534
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

備註:如果是root用戶可以在命令行直接修改,然後把ulimit -SHn 65534追加到/etc/profile文件中,普通用戶在yum update升級之後,可能無法在命令行修改,可以直接修改配置文件。

Cent OS下修改用戶打開文件數限制