1. 首先检查文件 /etc/systemd/system/mongodb.service 是否存在,不存在则创建。
2. 查看内容:
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=root
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
重点是在 User=root(因为我登录的用户是root)。网贴上好多是 User=mongodb,导致启动失败。应该修改为相应用户。
3. 启动时遇到的错误信息:
systemctl status mongodb
● mongodb.service - High-performance, schema-free document-oriented database
Loaded: loaded (/etc/systemd/system/mongodb.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2018-09-11 14:33:14 CST; 18s ago
Process: 65076 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (code=exited, status=217/USER)
Main PID: 65076 (code=exited, status=217/USER)
Sep 11 14:33:14 localhost.localdomain systemd[1]: Started High-performance, schema-free document-oriented database.
Sep 11 14:33:14 localhost.localdomain systemd[1]: Starting High-performance, schema-free document-oriented database...
Sep 11 14:33:14 localhost.localdomain systemd[1]: mongodb.service: main process exited, code=exited, status=217/USER
Sep 11 14:33:14 localhost.localdomain systemd[1]: Unit mongodb.service entered failed state.
Sep 11 14:33:14 localhost.localdomain systemd[1]: mongodb.service failed.
4. 修改 文件后,执行
systemctl daemon-reload
systemctl start mongodb
systemctl status mongodb