在 CentOS 7 上更改 MongoDB 的默认 dbPath 时出错

Error changing default dbPath for MongoDB on CentOS 7

我们如何更改 mongod.conf 文件中的 dbPath、路径等选项。 我正在使用 centos 7。 每次我更改默认的 dbPath 并尝试重新启动 mongod 服务时,它都会失败。(它可以正常使用默认配置选项,如 ->

storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log
)

我尝试使用 chown mongod:mongod /path/to/datachmod 0755 /path/to/data

更改对新目录的权限

每次出现错误(在 mongod.log 文件中)-> 2017-03-27T06:03:27.182+0000 I STORAGE [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /path/to/data, terminating

我必须配置 /etc/sysconfig/selinux 文件。 改变 SELINUX=enforcingSELINUX=disabled 允许 MongoDB 在 CentOS 上启动。 您必须重新启动系统才能使更改生效。