Centos 7: Mongodb cannot boot itself
- 2020-06-15 10:26:18
- OfStack
preface
The first mongodb you download has bug, so you need to manually use fix yourself. This is only a problem for a specific version, but not for all versions.
SeLinux
Also, 1 must set selinux to disabled or permissive
Problem description
sudo systemctl status mongod.service
Seeing that the service isn't working, open the log file:
cat /var/log/mongodb/mongod.log
The following problem occurs because the pid file cannot be created
***** SERVER RESTARTED *****
ERROR: Cannot write pid file to /var/run/mongodb/mongod.pid: No such file or directory
The Centos7 system cleans up one of the items under /var/run every time, so the next time it is restarted, there is no good way to handle this file, as systemd boot is just a command:
/usr/bin/mongod --quiet -f /etc/mongod.conf run
Treatment scheme
Create a permanent file path and the pid file yourself
Modify the pid path in configuration file /etc/ mongod.conf and then modify the path of the systemd entry.
Specific operation
1. Create the file and modify the permissions
[azuo1228@ecs-ee2fe26e /]$ sudo mkdir /mongod
[azuo1228@ecs-ee2fe26e /]$ sudo touch /mongod/mongod.pid
[azuo1228@ecs-ee2fe26e /]$ sudo chown -R mongod:mongod /mongod
2. Modify the configuration
[azuo1228@ecs-ee2fe26e /]$ sudo vim /etc/mongod.conf
Put the inside:
pidFilePath: /var/run/mongodb/mongod.pid
Modify to create file:
pidFilePath: /mongod/mongod.pid
3. Modify the systemd entry
[azuo1228@ecs-ee2fe26e ~]$ sudo vim /etc/systemd/system/multi-user.target.wants/mongod.service
Put the inside:
PIDFile=/var/run/mongodb/mongod.pid
Modify the path to the specified file:
cat /var/log/mongodb/mongod.log
0
4. reload systemd
cat /var/log/mongodb/mongod.log
1
5. Boot up the mongod or reboot
cat /var/log/mongodb/mongod.log
2
6. Check status
[azuo1228@ecs-ee2fe26e ~]$ sudo systemctl status mongod.service
NOTE 1:
mongo. conf will not be updated after the mongodb installation is updated, however, it will be updated
cat /var/log/mongodb/mongod.log
4
Install a new one
cat /var/log/mongodb/mongod.log
5
So, also can't get up.
If you have the conf file set as above, you will need to modify the systemd file again.
NOTE 2:
The updated mongodb 3.4.1 has fixed this issue
cat /var/log/mongodb/mongod.log
6
conclusion