问题描述
我在根目录中创建了 /data/db
并运行了 ./mongod
:
I created /data/db
in root directory and ran ./mongod
:
[initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating
[initandlisten] shutdown: going to close listening sockets...
[initandlisten] shutdown: going to flush diaglog...
[initandlisten] now exiting
[initandlisten] shutting down with code:100
推荐答案
问题是你创建的目录,/data/db
归root用户所有并且只能写,但是你正在运行 mongod 作为你自己.有多种方法可以解决此问题,但最终,您必须为相关目录授予正确的权限.如果这是用于生产,我建议您检查文档并仔细考虑 - 您可能需要特别小心.
The problem is that the directory you created, /data/db
is owned by and only writable by the root user, but you are running mongod as yourself. There are several ways to resolve this, but ultimately, you must give the directory in question the right permissions. If this is for production, I would advise you to check the docs and think this over carefully -- you probably want to take special care.
但是,如果这只是为了测试而您只需要它来工作并继续使用它,您可以尝试这个,这将使每个人都可以写目录:
However, if this is just for testing and you just need this to work and get on with it, you could try this, which will make the directory writable by everyone:
> sudo chmod -R go+w /data/db
或者这个,这将使目录归您所有:
or this, which will make the directory owned by you:
> sudo chown -R $USER /data/db
这篇关于MongoDB:initAndListen 中的异常:20 尝试在只读目录上创建锁定文件:/data/db,正在终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!