问题描述
直到现在,我还没有指定MongoDB数据目录,并且只有一个30 GB的主分区.
Until now I have not been specifying a MongoDB data directory and have had only one 30 GB primary partition.
我刚好用光了空间并添加了新硬盘.如何传输我的数据(显然在/var/lib/mongodb/
中)并配置MongoDB,以便所有内容都可以在新磁盘上运行而又不影响现有安装?
I just ran out of space and added a new hard disk. How can I transfer my data (that is apparently in /var/lib/mongodb/
) and configure MongoDB so that everything runs off of the new disk without affecting my existing installation?
推荐答案
简短的答案是MongoDB中的--dbpath
参数将允许您控制MongoDB从哪个目录读取和写入数据.
The short answer is that the --dbpath
parameter in MongoDB will allow you to control what directory MongoDB reads and writes it's data from.
将启动mongodb并将文件放入/usr/local/mongodb-data
.
Would start mongodb and put the files in /usr/local/mongodb-data
.
根据您的发行版和MongoDB安装,还可以配置mongod.conf
文件以自动执行此操作:
Depending on your distribution and MongoDB installation, you can also configure the mongod.conf
file to do this automatically:
# Store data in /usr/local/var/mongodb instead of the default /data/db
dbpath = /usr/local/var/mongodb
10gen Linux官方软件包( Ubuntu/Debian 或 CentOS/Fedora )附带了一个放置在其中的基本配置文件在/etc/mongodb.conf
中,MongoDB服务将在启动时读取该内容.您可以在此处进行更改.
The official 10gen Linux packages (Ubuntu/Debian or CentOS/Fedora) ship with a basic configuration file which is placed in /etc/mongodb.conf
, and the MongoDB service reads this when it starts up. You could make your change here.
这篇关于更改MongoDB数据存储目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!