转:mongoDB 修改 ulimit
转自:http://blog.yucanlin.cn/2015/03/23/mongodb-%E4%BF%AE%E6%94%B9-ulimit/
mongoDB 修改 ulimit
一切都源于mongoDB的这条warning
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可是用户相关的,所以这种做法不靠谱。
正确的做法是修改/etc/security/limits.conf文件,这个文件是有man文档,可以man limit.conf文件查看。先给个sample:
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。
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命令查询。
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命令查询得到。
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 |