MongoDB is a product between relational databases and non-relational databases. It has the most abundant functions and features like relational databases. It features high performance, easy to deploy, and easy to use, and stores data in a very convenient way.
MongoDB is a product between relational databases and non-relational databases. It has the most abundant functions and features like relational databases. It features high performance, easy to deploy, and easy to use, and stores data in a very convenient way.
MongoDB is a product between relational databases and non-relational databases. It has the most abundant functions and features like relational databases. It features high performance, ease of deployment, and ease of use, making it easy to store data. The company used the MONGODB database in the testing and production environments. During the daily use of the MONGODB database, we encountered some problems. The typical three problems are summarized and shared.
I. Maximum number of connections to the database
When you find a large amount of "connection refused because too open connections: 819" information in the background log, it is generally related to your failure to set a proper maximum connection value.
By default, in LINUX, the default number of connections in MONGODB is 819. You can increase the value as needed, but note that this value is not infinitely large and can be set to 20000 at most, see the official instructions of MONGODB.
We can add the -- maxConns 10000 parameter when starting the database to specify the maximum number of connections.
You can also modify the mongodb. conf configuration file and add maxConns = 10000 to save and quit, and then start MONGODB.
Of course, this problem is also related to the ulimit limit. You can manually modify ulimit-n to change the number of open files.
If you want to make the value of open file take effect permanently, add the following four lines in/etc/security/limits. conf, and modify the number according to the system conditions.
* Soft nofile 102400 (* for all users)
* Hard nofile 102400
Root soft nofile 102400 (for ROOT users)
Root hard nofile 102400
Then add
Session required/lib64/security/pam_limits.so
....
Reboot takes effect permanently.
Ii. Virtual Memory restrictions
After the MongoDB master-slave configuration is enabled, an ERROR "ERROR: mmap failed with out of memory" is returned ". This is because when mongodb is set to a master-slave relationship, "creating replication oplog of size: 944MB" will be created. This OPLOG should be stored in the memory.
Solution:
(1) set the oplog size, which is specified by the -- oplogSize parameter. The default value is 944 M.
(2) release the virtual memory limit (512 MB by default for the Virtual Machine), edit the/etc/profile file and add it to ulimit-v unlimited, and use source/etc/profile to make the setting take effect.
Run the master-slave startup command.
Mongodb is more memory-consuming. You can also limit the memory usage of mongodb as follows:
Vi mongodb. conf
Increase ulimit-m 2560000 (about 2.5 GB memory)
Notes:
1. the error "mmap failed with out of memory" occurs in the 32-bit operating system of MongoDB, because in the 32-bit platform, MongoDB does not allow the database file (accumulative total) to exceed 2 GB, the 64-bit platform does not have this restriction. If this error is also reported on the 64-bit platform, it is generally caused by insufficient virtual memory. You can edit the/etc/profile file and add it to ulimit-v unlimited. Use source/etc/profile to make the setting take effect or restart it to take effect.
2. The oplog size does not have much to do with the memory. The oplogSize is equivalent to the binlog of the mysql database. The data copied from the database is read from the oplog, that is, the local database.
-- OplopgSize: specifies the maximum size of log storage during slave synchronization. If no parameter is specified for the latest version of mongodb, the default value is 5% of the disk space. If the parameter is too small, if the difference between slave synchronization and the master database is far greater than the oplog size, data may be inconsistent.
See the official documentation for instructions:
+ Oplog + Length
3. We recommend that you use a high-performance sas hard disk for mongoDB. You can use a raid 10 hard disk for performance purposes.
Iii. Excessive mongodb space occupation
1. pre-allocation of space: to avoid the formation of too many hard disk fragments, mongodb will apply to generate a large disk space each time when space is insufficient, in addition, the application volume increases exponentially from 64 M, 128 M, and M until 2G is the maximum volume of a single file. As the amount of data increases, you can see these files in the data directory with increasing capacity.
2. space occupied by field names: to keep the structure information in each record for query, mongodb needs to store the key-value of each field in the form of BSON, if the value field is not large relative to the key field, for example, to store numeric data, the overhead of the data is the largest. One way to reduce the space occupation is to take the field name as short as possible, so that the occupied space will be smaller, but this requires a balance between ease of use and space occupation. We recommend that you set the field name as an index. Each field name is represented in one byte, so you don't have to worry about the length of the field name. However, this index method requires that the index value be replaced with the original value after each query result, and then sent to the client. This replacement is quite time-consuming.
3. delete a record without releasing space: This is easy to understand. To avoid large-scale migration of deleted data, the original record space is not deleted and only marked as "deleted, it can be reused in the future.
You can regularly run db. repairDatabase () to sort records and release space, but this process will be slow.
Supplement:
1. An error occurred while connecting the mongodb client to the server.
Generally, this error is caused by abnormal machine restart or hard shutdown. The solution is as follows:
① Delete the mongod. lock file and restart MongoDB.
Rm-rf/data/mongodb/mongod. lock (this is the path for storing mongodb data)
② Mongodb repair
Mongod-repair-dbpath =/data/mongodb/data
2. Start and Stop mongodb
/Opt/mongodb/bin/mongod-f/opt/mongodb. conf start
/Opt/mongodb/bin/mongo stop
Use admin
Db. shutdownServer ()
/Opt/mongodb/bin/mongo view database status
Db. serverStatus ()
This article is from the blog "dishui Tong Shi Sun Jie". Please keep this source