● mongod.service - SYSV: Mongo is a scalable, document-oriented database.
Loaded: loaded (/etc/rc.d/init.d/mongod; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2019-03-21 10:52:22 CST; 16s ago
Docs: man:systemd-sysv-generator(8)
Process: 41767 ExecStart=/etc/rc.d/init.d/mongod start (code=exited, status=1/FAILURE)
Mar 21 10:52:22 iZ8vb8vuru3z975hcpmh4rZ systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database....
Mar 21 10:52:22 iZ8vb8vuru3z975hcpmh4rZ runuser[41778]: pam_unix(runuser:session): session opened for user mongod by (uid=0)
Mar 21 10:52:22 iZ8vb8vuru3z975hcpmh4rZ runuser[41778]: pam_unix(runuser:session): session closed for user mongod
Mar 21 10:52:22 iZ8vb8vuru3z975hcpmh4rZ mongod[41767]: Starting mongod: [FAILED]
Mar 21 10:52:22 iZ8vb8vuru3z975hcpmh4rZ systemd[1]: mongod.service: control process exited, code=exited status=1
Mar 21 10:52:22 iZ8vb8vuru3z975hcpmh4rZ systemd[1]: Failed to start SYSV: Mongo is a scalable, document-oriented database..
Mar 21 10:52:22 iZ8vb8vuru3z975hcpmh4rZ systemd[1]: Unit mongod.service entered failed state.
Mar 21 10:52:22 iZ8vb8vuru3z975hcpmh4rZ systemd[1]: mongod.service failed.
解决办法:
将mongoDB添加到systemd
vim /usr/lib/systemd/system/mongod.service
[Unit]
Description=mongodb database
[Service]
User=mongod
Group=mongod
Environment="OPTIONS=--quiet -f /etc/mongod.conf"
ExecStart=/usr/bin/mongod $OPTIONS run
PIDFile=/var/run/mongodb/mongod.pid
[Install]
WantedBy=multi-user.target
建立链接
ln -s /usr/lib/systemd/system/mongod.service /etc/systemd/system/multi-user.target.wants/
重新加载systemctl
systemctl daemon-reload
● mongod.service
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: failed (Result: start-limit) since Thu 2019-03-21 10:56:09 CST; 15s ago
Process: 41857 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=14)
Mar 21 10:56:09 iZ8vb8vuru3z975hcpmh4rZ systemd[1]: Failed to start mongod.service.
Mar 21 10:56:09 iZ8vb8vuru3z975hcpmh4rZ systemd[1]: Unit mongod.service entered failed state.
Mar 21 10:56:09 iZ8vb8vuru3z975hcpmh4rZ systemd[1]: mongod.service failed.
Mar 21 10:56:09 iZ8vb8vuru3z975hcpmh4rZ systemd[1]: mongod.service holdoff time over, scheduling restart.
Mar 21 10:56:09 iZ8vb8vuru3z975hcpmh4rZ systemd[1]: Stopped mongod.service.
Mar 21 10:56:09 iZ8vb8vuru3z975hcpmh4rZ systemd[1]: start request repeated too quickly for mongod.service
Mar 21 10:56:09 iZ8vb8vuru3z975hcpmh4rZ systemd[1]: Failed to start mongod.service.
Mar 21 10:56:09 iZ8vb8vuru3z975hcpmh4rZ systemd[1]: Unit mongod.service entered failed state.
Mar 21 10:56:09 iZ8vb8vuru3z975hcpmh4rZ systemd[1]: mongod.service failed.
看完之后不明觉厉,这时候看一下mongo的log
tail -f /var/log/mongodb/mongod.log
信息如下
2019-03-21T10:56:09.405+0800 I CONTROL [initandlisten] distarch: x86_64
2019-03-21T10:56:09.405+0800 I CONTROL [initandlisten] target_arch: x86_64
2019-03-21T10:56:09.405+0800 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/var/lib/mongo", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2019-03-21T10:56:09.428+0800 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2019-03-21T10:56:09.428+0800 I - [initandlisten] Fatal Assertion 28578
2019-03-21T10:56:09.428+0800 I - [initandlisten]
其中最关键的一句就是2019-03-21T10:56:09.428+0800 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted没有权限
查看一下/tmp/mongodb-27017.sock的读写权限
ls -l /tmp/mongodb-27017.sock
发现该文件夹的所有者为root
srwx------ 1 root root 0 Mar 21 09:39 /tmp/mongodb-27017.sock
把所有者修改为mongod
chown mongod:mongod /tmp/mongodb-27017.sock
重新启动mongo
service mongod start
启动成功
创建了一个小游戏交流群,加群或者有问题交流可以加我微信 备注“微信小游戏”