使用「systemctl start mongod」启动出现如下问题

1
2
3
4
5
6
7
8
9
I STORAGE  [initandlisten] WiredTiger message txn-recover: Main recovery loop: starting at 316/945152
I STORAGE [initandlisten] WiredTiger message txn-recover: Recovering log 316 through 317
I STORAGE [initandlisten] WiredTiger message txn-recover: Recovering log 317 through 317
I CONTROL [signalProcessingThread] got signal 15 (Terminated), will terminate after current cmd ends
I NETWORK [signalProcessingThread] shutdown: going to close listening sockets...
I NETWORK [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock
I NETWORK [signalProcessingThread] shutdown: going to flush diaglog...
I CONTROL [signalProcessingThread] now exiting
I CONTROL [signalProcessingThread] shutting down with code:0

多次观察之后发现每次都是启动到1分30秒到时候出现进程结束信号

查看systemd启动超时时间

1
2
systemctl show mongod -p TimeoutStartUSec
# 输出内容:TimeoutStartUSec=1min 30s

从上面命令可以看到默认的启动超时时间为1分30秒,在一般情况下是没有问题的。但是在数据库较大的时候MongoDB恢复时间远远大于默认值从而导致启动失败

修改mongod.service

1
2
3
4
5
6
7
8
[Unit]
此处内容省略
[Service]
# 增加如下设置,更改默认启动超时时间为1小时30分钟
TimeoutStartSec=1h 30min
此处内容省略
[Install]
此处内容省略