所以我在 CentOS 7 上运行,并且刚刚用非 root 用户安装了 mongod 4.2.6。Mongod 使用默认的 db 路径/var/lib/mongo 运行良好,但我想将 db 路径编辑为/data/mongo,所以我将/etc/mongod.conf 中的 dbpath 参数编辑为/data/mongo。我还运行sudo chown mongod:mongodb /data/mongo
来更改权限。但是当我重新启动服务时,mongod 崩溃了,错误exception in initAndListen: Location28596: Unable to determine status of lock file in the data directory /data/mongo: boost::filesystem::status: Permission denied: "/data/mongo/mongod.lock", terminating
.我也尝试授予 mongodchmod 777
但它仍然存在同样的问题。让 mongod 正常运行的唯一方法是让我手动运行命令sudo mongod --dbpath /data/mongo
,这不是首选方法。如何让 mongod 作为服务正常运行?
试试 chmod 755/data。 权限必须是 drwxr-xr-x