一切都源於mongoDB的這條warningmongodb
1
|
** WARNING: soft rlimits too low. rlimits
set
to 4096 processes, 64000 files. Number of processes should be at least 32000 : 0.5
times
number of files.
|
修改ulimit原本也不難,不過仍是有很多坑。mongoDB官方文檔http://docs.mongodb.org/manual/reference/ulimit/#memory-size , 雖然給了方法,不過linux這個ulimit但是用戶相關的,因此這種作法不靠譜。bash
正確的作法是修改/etc/security/limits.conf文件,這個文件是有man文檔,能夠man limit.conf文件查看。先給個sample:dom
1
2
3
4
5
6
7
8
9
10
11
|
<domain><
type
><item><value>
* soft core 0
* hard nofile 512
@student hard nproc 20
@faculty soft nproc 20
@faculty hard nproc 50
ftp
hard nproc 0
@student - maxlogins 4
:123 hard cpu 5000
@500: soft cpu 10000
600:700 hard locks 10
|
根聽說明,咱們添加以下內容,這些數值來自於mongoDB文檔裏面的推薦數值。有個要求就是nproc要大於0.5nofile。ide
1
2
3
4
5
6
7
8
9
10
|
mongod soft fsize unlimited
mongod hard fsize unlimited
mongod soft cpu unlimited
mongod hard cpu unlimited
mongod soft as unlimited
mongod hard as unlimited
mongod soft nofile 64000
mongod hard nofile 64000
mongod soft nproc 64000
mongod hard nproc 64000
|
重啓後就搞定了。這裏要留意的是,請指明用戶,不要用*代替。誰啓動mongoDB就用戶就填誰,能夠用ps命令查詢。url
1
2
3
|
[yucanlin@localhost ~]$
ps
-ef |
grep
mongod
mongod 945 1 1 12:11 ? 00:00:14
/usr/bin/mongod
-f
/etc/mongod
.conf
yucanlin 3040 2649 0 12:32 pts
/0
00:00:00
grep
--color=auto mongod
|
另外,若是想查詢mongod的limits,能夠使用如下命令。其中945是pid。有上面的ps命令查詢獲得。spa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
[yucanlin@localhost ~]$
cat
/proc/945/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 8388608 unlimited bytes
Max core
file
size 0 unlimited bytes
Max resident
set
unlimited unlimited bytes
Max processes 64000 64000 processes
Max
open
files 64000 64000 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max
file
locks unlimited unlimited locks
Max pending signals 7859 7859 signals
Max msgqueue size 819200 819200 bytes
Max
nice
priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
|