开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第4天,点击查看活动详情
发现问题:
前言:
上午正常日常敲代码的过程中,听同事说线上mongo数据库挂了。
下面开始打怪升级之旅....
排查问题:
1、 查看是否启动
[root@xxxxxx bin]# netstat -lanp | grep "27017"
-- 查看进程是否运行
[root@xxxxxx bin]# ps -ef|grep mongo
2、查看日志
{"t":{"$date":"2021-11-30T06:54:25.048+08:00"},"s":"F", "c":"CONTROL", "id":4757800,
"ctx":"ftdc","msg":"Writing fatal message","attr":{"message":"DBException::toString():
FileStreamFailed: Failed to write to interim file buffer for full-time diagnostic data capture:
/usr/local/mongoDB/mongodbserver/data/diagnostic.data/metrics.interim.temp\nActual exception type:
mongo::error_details::ExceptionForImpl<(mongo::ErrorCodes::Error)39, mongo::AssertionException>\n"}}
查看最新的日志发现有这样一段报错信息 FileStreamFailed: Failed to write to interim file buffer for full-time diagnostic data capture 提示 无法写入临时文件缓冲区 此时想到会不会是 服务器磁盘满了的缘故
3、查看空间使用情况
3.1 查看文件所在分区
[root@iz2zedu33j44bh5e85vtaiz wwwroot]# df ./
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/vda1 98950748 71886044 22015264 77% /
3.2 使用命令 查看磁盘空间使用情况
发现挂载点的磁盘满了 经过一系列删除处理之后....
恢复操作:
注:如果启动命令可以正常启动成功 不需要执行恢复操作
1、删除 data 下的 mongod.lock 文件
2、执行恢复命令
[root@xxxxxx bin]# ./mongod -f /usr/local/mongoDB/mongodbserver/etc/mongodb.conf --repair
3、执行启动命令
[root@xxxxxx bin]# ./mongod --config /usr/local/mongoDB/mongodbserver/etc/mongodb.conf
拓展:
[root@xxxx etc]# cat mongodb.conf
dbpath=/usr/local/mongoDB/mongodbserver/data
logpath=/usr/local/mongoDB/mongodbserver/logs/mongodb.log
bind_ip=0.0.0.0
port=27017
fork=true
auth=true
提示 :正确关闭mongodb的方法
use admin db.shutdownServer()
官方文档:
英文:
Stop mongod Processes
In a clean shutdown a mongod completes all pending operations, flushes all data to data files, and closes all data files. Other shutdowns are unclean and can compromise the validity of the data files.
To ensure a clean shutdown, always shutdown mongod instances using one of the following methods:
Use shutdownServer()
Shut down the mongod from the mongo shell using the db.shutdownServer() method as follows:
use admin
db.shutdownServer()
Calling the same method from a init script accomplishes the same result.
For systems with authorization enabled, users may only issue db.shutdownServer() when authenticated to the admin database or via the localhost interface on systems without authentication enabled.
Use --shutdown
From the Linux command line, shut down the mongod using the --shutdown option in the following command:
mongod --shutdown
Use CTRL-C
When running the mongod instance in interactive mode (i.e. without --fork), issue Control-C to perform a clean shutdown.
Use kill
From the Linux command line, shut down a specific mongod instance using the following command:
kill <mongod process ID>
中文翻译:
停止mongod进程
在完全关闭的情况下,mongod完成所有挂起的操作,将所有数据刷新到数据文件,并关闭所有数据文件。其他关机不干净,可能会影响数据文件的有效性。
要确保干净关闭,请始终使用以下方法之一关闭mongod实例:
使用shutdownServer()
使用db.shutdownServer()方法从mongo shell关闭mongod,如下所示:
use admin
db.shutdownServer()
从init脚本调用相同的方法可以实现相同的结果。
对于启用了授权的系统,用户只能在向管理数据库进行身份验证时,或在未启用身份验证的系统上通过localhost接口发出db.shutdownServer()。
Use --shutdown
在Linux命令行中,使用以下命令中的--shutdown选项关闭mongod:
mongod --shutdown
使用CTRL-C
在交互模式下运行mongod实例(即不使用--fork)时,发出Control-C以执行完全关闭。
使用kill
在Linux命令行中,使用以下命令关闭特定mongod实例:
kill<mongod进程ID>