更改 MongoDB 数据存储目录 [英] Changing MongoDB data store directory

查看:32
本文介绍了更改 MongoDB 数据存储目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我还没有指定 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.

mongod --dbpath/usr/local/mongodb-data

mongod --dbpath /usr/local/mongodb-data

将启动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/DebianCentOS/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 数据存储目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆