大网数据广告活动
服务器运维问答

Can't start mongodb

· 52CE 我爱测

I installed MongoDb on Ubuntu and was able to run it using sudo service mongod start . Then I had to restart it since I changes the config file. Now I can't start it again. When I run sudo service mongod start , it just says noth…

问题原文

原帖链接 · ulu · CC BY-SA 4.0

I installed MongoDb on Ubuntu and was able to run it using sudo service mongod start. Then I had to restart it since I changes the config file. Now I can't start it again. When I run sudo service mongod start, it just says nothing (but I can't connect using mongo). And the log says, 2018-06-06T18:45:49.279+0000 I STORAGE [initandlisten] exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /var/lib/mongodb, terminating

Here are the permissions: ubuntu@ip-172-31-24-92:~$ stat /var/lib/mongodb Access: (0755/drwxr-xr-x) Uid: ( 1000/ ubuntu) Gid: ( 116/ mongodb)

So, how do I run it again?

Bonus question: how do I make the command output the actual error, so that I don't have to look it up in the log every time?

P.S. I'm a long time Windows user, just learning Linux.

已采纳解答

原帖链接 · yosefrow · CC BY-SA 4.0

First of all, welcome to Linux!

Second, I'm guessing in this case mongodb runs as the user mongodb

If this is the case, then the user mongodb needs permission to write to the directory.

Given your current permissions: the owner is ubuntu which can rwx read, write, and execute, while the group is mongodb which can only r-x read, execute. Since the mongodb user is in the mongodb group but does not own the file, it cannot write.

Access: (0755/drwxr-xr-x)  Uid: ( 1000/  ubuntu)   Gid: (  116/ mongodb)

To solve this either make mongodb the owner sudo chown mongodb:mongodb -R /var/lib/mongodb or let the group write as well sudo chmod 775 -R /var/lib/mongodb

Assuming you installed the mongodb server using a standard method on standard linux system, you will likely need to restart the service using the systemctl (SystemD) or service (upstart) command.

SystemD: sudo systemctl restart mongodb or sudo systemctl restart mongod

Upstart: sudo service mongod restart

If you are running SystemD, then you can check the status of your service with

sudo systemctl status mongodb or sudo systemctl status mongod

And you can view the logs of your service with

sudo journalctl -u mongodb or sudo journalctl -u mongod

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-06-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。