要在Debian上更改MongoDB的存儲路徑,請按照以下步驟操作:
sudo systemctl stop mongodb
/mnt/new_storage
:sudo mkdir -p /mnt/new_storage
mongodb
):sudo chown -R mongodb:mongodb /mnt/new_storage
mongodump
備份原始數據目錄(默認情況下為/data/db
):sudo mongodump --out /mnt/new_storage/backup
/etc/mongod.conf
),找到storage.dbPath
設置并更改為新的存儲路徑:sudo nano /etc/mongod.conf
將以下行:
storage:
dbPath: /data/db
更改為:
storage:
dbPath: /mnt/new_storage
保存并關閉配置文件。
使用mongorestore
將備份的數據恢復到新的存儲路徑:
sudo mongorestore --dir /mnt/new_storage/backup
sudo systemctl start mongodb
mongo --eval 'db.runCommand({ connectionStatus: 1 })'
在輸出中,檢查dbPath
字段是否指向新的存儲路徑。
完成以上步驟后,MongoDB應該已經成功更改了存儲路徑。