数据库 
首页 > 数据库 > 浏览文章

Mongodb 崩溃报错 Too many open files的问题解析

(编辑:jimmy 日期: 2024/5/9 浏览:3 次 )

在项目实际使用过程中,客户反馈能打开网页但无法登陆,第一时间感觉到应该是数据库服务器挂了,于是查看Mongodb数据库服务器日志,果不其然挂了。
报错信息如下:

2020-12-28T13:21:21.731+0800 E STORAGE  [conn2624] WiredTiger error (24) [1609132881:731422][23581:0x7fe157189700], WT_SESSION.create: __posix_directory_sync, 135: /data1/mongodb/data/db/: directory-sync: open: Too many open files Raw: [1609132881:731422][23581:0x7fe157189700], WT_SESSION.create: __posix_directory_sync, 135: /data1/mongodb/data/db/: directory-sync: open: Too many open files
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
2020-12-28T13:21:21.731+0800 E STORAGE  [conn2624] WiredTiger error (-31804) [1609132881:731651][23581:0x7fe157189700], WT_SESSION.create: __wt_panic, 494: the process must exit and restart: WT_PANIC: WiredTiger library panic Raw: [1609132881:731651][23581:0x7fe157189700], WT_SESSION.create: __wt_panic, 494: the process must exit and restart: WT_PANIC: WiredTiger library panic
2020-12-28T13:21:21.731+0800 F -        [conn2624] Fatal Assertion 50853 at src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp 420
2020-12-28T13:21:21.731+0800 F -        [conn2624]

***aborting after fassert() failure

可以看到核心问题就是 Too many open files。经查阅相关资料,造成如下问题的原因就是Centos7给每个用户默认的同时打开文件的数值为1024,可通过如下配置文件查看:

ulimit -a

Mongodb 崩溃报错 Too many open files的问题解析

其中所有的参数均可修改,那么如何修改open files呢?
在此提供两种方法:
首先查看系统全局参数:

Mongodb 崩溃报错 Too many open files的问题解析

所以我们可以修改的最大值也是174198

具体修改方法一:
新建一个nofile.conf文件:

vi /etc/security/limits.d/nofile.conf

在此配置文件中写入:

* soft nofile 65536
* hard nofile 65536

Mongodb 崩溃报错 Too many open files的问题解析

保存后,需要重启系统,永久有效。

具体修改方法二:(不需要重启,不需要停服务,动态修改
1,查看mongodb pid:

Mongodb 崩溃报错 Too many open files的问题解析

2,查看对应pid limits:

cat /proc/41814/limits

Mongodb 崩溃报错 Too many open files的问题解析

3,可直接编辑以上文件,也可以直接运行命令行:

prlimit --pid 41814 --nofile=65535:65535

4,再次查看,修改成功:

Mongodb 崩溃报错 Too many open files的问题解析

总结:建议双管齐下,都修改了。

上一篇:一次因mongo查询不存在字段引发的事故记录
下一篇:解决MAC上启动mongod报错exiting with code 1的问题
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网