修改mongodb dbpath后启动失败

修改mongodb dbpath后启动失败

我执行了以下命令来修改dbpath:

mkdir /mnt/data/mongodb
sudo chown -R mongod:mongod /mnt/data/mongodb

修改mongod.conf:

vi /etc/mongod.conf

# Where and how to store data.
storage:
  dbPath: /mnt/data/mongodb
  journal:
    enabled: true

但是当我重新启动 mongodb 时,它失败了。

sudo service mongod restart

以下是错误日志:

● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 四 2020-10-15 21:56:26 UTC; 1min 43s ago
     Docs: https://docs.mongodb.org/manual
  Process: 11144 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=100)
  Process: 11142 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 11140 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 11139 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
 Main PID: 10605 (code=exited, status=0/SUCCESS)

10月 15 21:56:26 centos-sfo2-04 systemd[1]: Starting MongoDB Database Server...
10月 15 21:56:26 centos-sfo2-04 mongod[11144]: about to fork child process, waiting until server is ready for connections.
10月 15 21:56:26 centos-sfo2-04 mongod[11144]: forked process: 11147
10月 15 21:56:26 centos-sfo2-04 systemd[1]: mongod.service: control process exited, code=exited status=100
10月 15 21:56:26 centos-sfo2-04 systemd[1]: Failed to start MongoDB Database Server.
10月 15 21:56:26 centos-sfo2-04 systemd[1]: Unit mongod.service entered failed state.
10月 15 21:56:26 centos-sfo2-04 systemd[1]: mongod.service failed.

答案1

使用下面的命令

sudo mongod --dbpath /mnt/data/mongodb --repair

另外请检查目录路径的权限。

答案2

请检查数据路径权限和所有权,

sudo chown -R mongodb:mongodb /var/log/mongodb
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chmod -R 755 /var/lib/mongodb
sudo chmod -R 755 /var/log/mongodb

然后更改数据目录,

mongod --dbpath /data/mongo

相关内容