`

修改MONGODB 最大连接数

 
阅读更多

问题: 今天PHP 测试端出错。不知是否为MONGODB的问题。测试最时而正常,刷新多次后就出错。

想到是否为连接次数的原因呢,所以想到把最大连接数修改后,再让他们测试一下,是否问题依旧。

 

修改方法:

---------------------------------------------------------------------------------------

1.修改系统参数:

vi /etc/rc.local

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.


ulimit -n 20000
touch /var/lock/subsys/local

 

 

2.配置文件:
[root@localhost bin]# cat mongod.cfg
dbpath=/opt/mongodb/db/
logpath=/opt/mongodb/logs/mongod.log
port=28001
logappend=true
fork = true
directoryperdb=true
#auth=true

maxConns=30000

 

重启服务器,

但现在最大连接数还是默认:
> db.serverStatus().connections;
{ "current" : 1, "available" : 819, "totalCreated" : NumberLong(8) }

 

查看:ulimit -a 没有看到open files 项。

 


看来是没起作用。后来在用户的.bash_profile 添加了,再看,问题解决:


[root@localhost bin]# su - mongo
[mongo@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) 30435
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 20000
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) 1024
virtual memory          (kbytes, -v) unlimited

file locks                      (-x) unlimited

 

修改的.bash_profile 文件如下:

--------------------------------------------

[mongo@localhost ~]$ cat ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin


MONGO_HOME=/opt/mongodb/mongodb-linux-x86_64-2.5.5; export MONGO_HOME
PATH=$PATH:$MONGO_HOME/bin;
export PATH

stty erase ^h #删除键可用处理

ulimit -n 20000
export PATH
[mongo@localhost ~]$ 


再查看最大连接数:

 

> db.serverStatus().connections;

{ "current" : 1, "available" : 15999, "totalCreated" : NumberLong(8) }

 

 

后来再另一测试服务器中修改mongod 启动参数:

maxConns=30000 发现在修改成10 时,还报错,后来为了测试修改成100,没有出错。

具体最小值为多少,还没有测试下去。

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics