当前位置:首页 > IT技术 > 数据库 > 正文

MongoDB 4升级提示 /var/run/mongod.pid: Invalid argument`
2022-02-14 10:50:12

MongoDB 4升级提示 /var/run/mongod.pid: Invalid argument`


因安全需要,需要升级MongoDB,本来是件很简单的事,把包下载下来 ​​-Uvh​​​就完事了。万万没想到花了十几分钟。升级以后一直报 ​​Failed to read PID from file /var/run/mongod.pid: Invalid argument​

Starting High-performance, schema-free document-oriented database...
Failed to read PID from file /var/run/mongod.pid: Invalid argument
Stopped High-performance, schema-free document-oriented database.

关键是MongoDB配置文件里面已经配置了pid文件

[root@ecs-11-152 mongodb]# grep pid /etc/mongod.conf 
pidFilePath: /data/mongodb/mongod.pid # location of pidfile

这个 ​​/var/run/mongod.pid​​ 不知道是哪来的

网上查没有只发现一个类似的报错​


问题产生原因

因为 nginx 启动需要一点点时间,而 systemd 在 nginx 完成启动前就去读取 pid file
造成读取 pid 失败

解决方法

让 systemd 在执行 ExecStart 的指令后等待一点点时间即可
如果你的 nginx 启动需要时间更长,可以把 sleep 时间改长一点
建立目录
mkdir -p /etc/systemd/system/nginx.service.d

在新建目录中建立文件override.conf,输入内容

[Service]
ExecStartPost=/bin/sleep 0.1

然后
systemctl daemon-reload
systemctl restart nginx.service


于是去查看MongoDB的启动文件,​​/lib/systemd/system/mongod.service​

结果发现有这么一行

PIDFile=/var/run/mongod.pid

把这一行屏蔽以后重启,问题解决



本文摘自 :https://blog.51cto.com/u