我已經修改過/etc/security/limit.conf
:
* hard nofile 1000000
* soft nofile 1000000
還有這個文件/etc/security/limits.d/90-nproc.conf
* soft nproc unlimited
root soft nproc unlimited
並重新啟動系統。這是輸出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) 30967
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1000000
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 30967
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
但我的程式放入rc.local
啟動後,最大檔案限制仍然是1024:
這是輸出cat /proc/1695/limits
:
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 10485760 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 30967 30967 processes
Max open files 1024 4096 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 30967 30967 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
這是什麼原因呢?當我在命令列啟動程式時,沒有這樣的限制。
答案1
我沒有透過系統層面解決。我透過我的 golang 程式解決了這個問題。
var rLimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
log.Fatal("1Error Getting Rlimit ", err)
}
log.Infof("Current Rlimit:%+v", rLimit)
rLimit.Max = 1000000
rLimit.Cur = 1000000
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
log.Fatal("Error Setting Rlimit ", err)
}
err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
log.Fatal("2Error Getting Rlimit ", err)
}
log.Info("Rlimit Final", rLimit)