標籤:ulimit shel creat roo server edit 查看 data- 通過
一. MongoDB串連數
在Linux平台下,無論是64位或者32位的MongoDB預設最大串連數都是819,WIN平台不知道,估計也沒有人在 WIN平台下使用MongoDB做生產環境
[[email protected] mongodb-3.0.4]# ./bin/mongo
MongoDB shell version: 3.0.4
connecting to: test
> use admin
switched to db admin
> db.auth(‘user‘,‘password‘);
1
> db.serverStatus().connections;
{ "current" : 1, "available" : 818, "totalCreated" : NumberLong(2) }
上文available顯示818少了一個,表示閒置。current表示已經佔用了的串連數,兩數一加就等於819,如果我現在在串連一個,那麼available就是817,current就是2
[[email protected] mongodb-3.0.4]# ./bin/mongo
MongoDB shell version: 3.0.4
connecting to: test
> exit
bye
[[email protected] mongodb-3.0.4]# ./bin/mongo 192.168.5.215
MongoDB shell version: 3.0.4
connecting to: 192.168.5.215/test
> use admin
switched to db admin
> db.auth(‘al_user‘,‘123456‘);
1
> db.serverStatus().connections;
{ "current" : 2, "available" : 817, "totalCreated" : NumberLong(3) }
819個串連數對於一般的網站我認為已經夠用,並且都是現連現取現斷。但這個串連數也可以修改,只要在啟動的時候加入--maxConns即可
二. 修改MongoDB串連數
[[email protected] mongodb-3.0.4]# ./bin/mongod --maxConns=41942
MongoDB shell version: 3.0.4
connecting to: test
查看mongo日誌
[[email protected] mongodb-3.0.4]# vim ./log/mongo.log
2016-04-22T12:02:43.669+0800 I CONTROL [initandlisten] options: { net: { maxIncomingConnections: 41942 },
> db.serverStatus().connections;
{ "current" : 1, "available" : 818, "totalCreated" : NumberLong(2) }
發現還是819?其實是Linux預設進程能開啟最大檔案數有關,可以通過ulimit 解決
[[email protected] mongodb-3.0.4]# ulimit -n 41942
關於ulimit的更多知識大家可以去網上檢索檢索
再查看最大串連數
[[email protected] mongodb-3.0.4]# ./bin/mongod --maxConns=41942
> use admin
switched to db admin
> db.auth(‘user‘,‘password‘);
1
> db.serverStatus().connections;
{ "current" : 1, "available" : 41941, "totalCreated" : NumberLong(1) }
搞定!
關於MongoDB最大串連數的查看與修改