mongodb数据目录权限
早些时候,我将所有 mongodb 数据文件存储在 /var/lib/mongodb 目录中..并且 /etc/mongodb.conf 中的 dbpath 条目是 /var/lib/mongodb..
现在我想将数据目录更改为 /vol /db..so 我创建了目录 /vol/db 并使用 sudo chown -R id -u
/vol/db 更改了权限,并将 db 路径条目更改为 /vol/db /etc/mongodb.conf
现在当我使用 sudo service mongodb start 启动 mongodb 时..我在 /var/log/mongodb/mongodb.log
我需要帮助..我错在哪里?
Earlier i was storing all the mongodb data files in /var/lib/mongodb directory..and the dbpath entry in /etc/mongodb.conf was /var/lib/mongodb..
Now i want to change the data directory to /vol/db..so I created the directory /vol/db and changed the permissions using sudo chown -R id -u
/vol/db and changed the db path entry to /vol/db in /etc/mongodb.conf
now when i start the mongodb using sudo service mongodb start..i am getting this error in /var/log/mongodb/mongodb.log
i need help..where I am wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我遇到了同样的问题,但由于 类似问题。您需要确保
/vol/db/
归mongodb
所有。如果您收到错误
chown: invalid user: 'mongodb:mongodb'
,请检查/etc/passwd
以查看是否存在类似的用户(例如mongod
)。I was having the same problem, but was able to solve it thanks to a similar question. You need to make sure that
/vol/db/
is owned bymongodb
.If you get the error
chown: invalid user: 'mongodb:mongodb'
, check/etc/passwd
to see if there is a similar user that exists (ex.mongod
).最简单的是
The easiest would be
如果更改新数据库路径的权限和所有权后,您仍然遇到此问题,请运行
getenforce
来查看您是否使用以强制模式运行 SELinux 的系统。如果 getenforce 返回“enforcing”,则很可能 selinux 是权限错误的原因,因为 mongodb 现在在其原始上下文范围之外运行,因为数据库位置更改为 /var/lib/...
我不知道详细信息,但是在不为新上下文编写自己的 selinux 策略的情况下解决问题的一种强力方法是简单地关闭 selinux :-/
理想情况下,如果您打算运行,您会弄清楚如何更新 selinux 策略在生产中。
If after changing permissions and ownership of the new db path, you're still seeing this issue, run
getenforce
to see if you are using a system with SELinux running in enforce mode.If getenforce returns 'enforcing', it's likely selinux is the cause of the permissions error, since mongodb is now running outside it's original context scope since the db location changed out of /var/lib/...
I don't know the details, but a brute force way then to resolve the issue without writing your own selinux policy for the new context is to simply turn off selinux :-/
Ideally, you'd figure out how to update the selinux policy if you're planning to run in production.
我建议通过阅读mongo log来检查错误是什么,
你可以立即找到问题(包括权限问题)
I suggest to check what is the error by reading mongo log
you can immediately find the problem(including permission ones)
请尝试以下操作:
Try the following:
根据您使用的 Linux 发行版,更改目录权限的命令可能会有所不同。我使用的是centOS,我使用的Mongodb版本是8。当我这样做时它起作用了。
只需确保检查
/var/lib
目录以查看您要更改的 mongo 目录/文件夹;有时是mongodb
,有时是mongo
Depending on the linux distro you are using the command could be different to change the permission of the directory. I'm using centOS and Mongodb version I using is 8. It worked when I did this.
Just make sure you check the
/var/lib
directory to see what mongo director/folder you are change; Sometimes it'smongodb
and sometimes itsmongo