Mongodb Crash Error: Too many open files [How to Solve]

Problem analysis of mongodb crash error too many open files

during the actual use of the project, the customer reported that he could open the web page but could not log in. He felt that the database server should hang up for the first time, so he checked the mongodb database server log, and sure enough, it hung up. The error information is as follows:

2020-12-28T13:21:21.731+0800 E STORAGE  [conn2624] WiredTiger error (24) [1609132881:731616][23581:0x7fe157189700], WT_SESSION.create: __posix_directory_sync, 151: /data1/mongodb/data/db/collection-1063-1706476241051221735.wt: directory-sync: Too many open files Raw: [1609132881:731616][23581:0x7fe157189700], WT_SESSION.create: __posix_directory_sync, 151: /data1/mongodb/data/db/collection-1063-1706476241051221735.wt: directory-sync: Too many open files

Cause of problem:

The number of open files on the system has reached the maximum
The reason for the above problem is that Centos7 gives each user a default number of files to open at the same time of 1024, which can be checked with the ulitme -u command

Problem solving:

1. Modify the limits.conf default parameters and add the following under the file.
* soft nofile 65536
* hard nofile 65536
PS: After saving as above, you need to reboot the system to take effect permanently

2, dynamic modification (no need to restart the system and mongo)
2.1, check the mongodb service pid file
        ps aux | grep mongo
2.2、After getting the pid file, check the corresponding pid limits, the following command
        cat /proc/95051/limits
2.3、Run the following command to achieve dynamic changes
        prlimit --pid 95051 --nofile=65535:65535
2.4. Check again, the modification is successful

proposal

It is recommended that new servers first change the system default parameters

Read More: