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