当我尝试启动 mongo 服务(systemctl start mongodb)时,在 journalctl 中出现此错误:
Mar 21 15:36:18 redhat7 systemd[1]: Started High-performance, schema-free document-oriented database.
Mar 21 15:36:18 redhat7 systemd[1]: Starting High-performance, schema-free document-oriented database...
Mar 21 15:36:18 redhat7 mongod[14333]: about to fork child process, waiting until server is ready for con
Mar 21 15:36:18 redhat7 mongod[14333]: forked process: 14335
Mar 21 15:36:18 redhat7 systemd[1]: mongod.service: main process exited, code=exited, status=1/FAILURE
Mar 21 15:36:18 redhat7 systemd[1]: Unit mongod.service entered failed state.
Mar 21 15:36:18 redhat7 systemd[1]: mongod.service failed.
但是以 root 身份运行以下命令可以工作!
sudo -u mongod /usr/bin/mongod -f /etc/mongod1.conf
/lib/systemd/system/mongod.service
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongod
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod1.conf
[Install]
WantedBy=multi-user.target
答案1
systemd 默认服务是简单的。这意味着它在前台运行,如果它退出,则该服务被视为已停止。
你的 mongod 配置文件有类似这样的内容:
processManagement: fork: true
,这会导致mongod
分叉到后台。有两种方法可以解决这个问题,最好的方法是将 改为fork
false 。另一种是在文件的 部分中/etc/mongod1.conf
设置。Type=forking
[Service]
.service