在linux服務器大併發調優時,其修改linux最大文件句柄數是最常修改的參數之一
目前:阿里雲服務器默認爲:open files (-n) 65535
[root@iZbp16qstyvxjc2nlzquvpZ ~]# 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) 63457
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65535
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) 63457
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
亞馬遜服務器默認爲open files: (-n) 1024
[root@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) 39188
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
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) 655350
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
備註:
- 默認情況下,linux最大文件句柄數爲1024個。
- 當你的服務器在大併發達到極限時,就會報出 "
Too many open files
"
執行下面命令即可修改最大句柄數爲655350:
[root@demo /root]#ulimit -n 655350
但是,這種方法只針對當前進程有效。重新打開一個shell或者開啓一個進程,你就會發現參數還是
ulimit -n xx修改之前的數字。
另一種方法就是修改linux系統參數。vi /etc/security/limits.conf
添加:
# End of file
# -----------分割線,上面是配置文件的模板,下面是自己添加的------------------------
* soft nofile 655350 #表示任何一個用戶可以打開的最大的文件描述符數量
* hard nofile 655350
* soft nproc 655350 #表示任何一個用戶可以打開的最大的進程數
* hard nproc 655350
@student hard nofile 65535 #student組中的任何人最多能打開文件描述符數量是65535,並且會在打開65000個時發出警告
@student soft nofile 65000
"/etc/security/limits.conf" 70L, 3225C
修改以後保存,註銷當前用戶,重新登錄,執行ulimit -a ,ok ,參數生效了:
[root@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) 39182
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 655350
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) 655350
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
[root@localhost ~]#
參考文獻:
linux最大文件句柄數:https://jinjiajin.net/101.html
注:以上內容僅提供參考和交流,請勿用於商業用途,如有侵權聯繫本人刪除!
持續更新中…
如有對思路不清晰或有更好的解決思路,歡迎與本人交流,微信:seesun2012(非緊急項目請加QQ羣解答
),QQ羣:273557553
你遇到的問題是小編創作靈感的來源!