在MongoDB上或是在安裝其他系統時,通常需要透過ulimit限制一些資源,尤其是針對openfile。
ulimit指令對照
ulimit -t LimitCPU (CPU Time)
ulimit -f LimitFSIZE (File Size)
ulimit -d LimitDATA (Data Seg Size)
ulimit -s LimitSTACK (Stack Size)
ulimit -c LimitCORE (Core File Size)
ulimit -m LimitRSS (Max Memory Size)
ulimit -n LimitNOFILE (Open File)
ulimit -v LimitAS (Virtual Memory Size)
ulimit -u LimitNPROC (Max User Processes/Threads)
ulimit -l LimitMEMLOCK (Max Locked-in-Memory Size)
ulimit -x LimitLOCKS (File Locks)
ulimit -i LimitSIGPENDING (Pending Singnals)
ulimit -q LimitMSGQUEUE (POSIX Message Queues)
ulimit -e LimitNICE (Scheduling Priority)
ulimit -r LimitRTPRIO (Real-Time Priority)
ulimit -p (Pipe Size)
ulimit -a 列出所有的限制條件
因為本篇主要是提供給MongoDB使用的,所以列出MongoDB的各項建議值
ulimit -f (File Size) :unlimited
ulimit -t (CPU Time) :unlimited
ulimit -v (Virtual Memory Size) :unlimited
ulimit -l (Max Locked-in-Memory Size) :unlimited
ulimit -n (Open File) :64000
ulimit -m (Max Memory Size) :unlimited
ulimit -u (Max User Processes/Threads):64000
找出MongoDB服務的資源限制
啟動mongod服務
systemctl start mongod
找出MongoDB的Main PID
systemctl status mongod
找出Main PID: xxxx (mongod)
查看修改前及修改後;修改後開機前及修改後開機後,設定是否有變更
cat /proc/xxxx/limits
設定MongoDB的資源限制
vi /usr/lib/systemd/system/mongod.service
[Service]
LimitFSIZE = infinity
LimitCPU = infinity
LimitAS = infinity
LimitMEMLOCK = infinity
LimitNOFILE = 64000
LimitNPROC = 64000
LimitRSS = infinitysystemctl daemon-reload
systemctl restart mongod.service
沒有留言:
張貼留言