Mongodb:在两台计算机之间共享数据库 [英] Mongodb: sharing a database between two computers

查看:502
本文介绍了Mongodb:在两台计算机之间共享数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在计算机1上使用MongoDB创建了一个数据库. 我正在尝试从计算机2加载此数据库. 你能帮我做到这一点吗?

I created a database using MongoDB on Computer 1. I am trying to load this DB from Computer 2. Could you please help me to do that ?

我试图在共享磁盘F:\中设置--dbpath(data \ db),但是计算机2无法识别数据.

I tried to set the --dbpath (data\db) in a shared disk F:\ but Computer 2 is not able to recognize the data.

推荐答案

您可以从任何其他节点访问mongo群集,因为您需要知道config-server在节点(计算机)上运行的端口1 . 可以使用以下命令启动配置服务器.理想情况下,系统上应该运行3台配置服务器,因此,我正在更新步骤以考虑到这一点.

You can access the mongo cluster from any other node, for that you need to know the port on which the config-server is running on node (Computer) 1. The config-server can be started using the following command. Ideally there should be 3 config servers running on a system so, I am updating the steps to take that into account.

<path-to-mongo>/bin/mongod --configsvr --port <port-1> --dbpath ./shardedcluster/cfg0 --fork

<path-to-mongo>/bin/mongod --configsvr --port <port-2> --dbpath ./shardedcluster/cfg1 --fork

<path-to-mongo>/bin/mongod --configsvr --port <port-3> --dbpath ./shardedcluster/cfg2 --fork

问题:未找到碎片.早些时候,我假设不需要分片来设置这种系统.但是,要解决此问题,您可以创建一个分片服务器,并按如下所示对其进行初始化.

Issue: No shards found. Earlier, I assumed that no shards were necessary to setup this kind of system. However, to overcome this issue you can create a shard server, and initialize it as follows.

<path-to-mongo>/bin/mongod --shardsvr --replSet a --dbpath ./shardedcluster/a0 --port <shard-port> --fork --smallfiles --oplogSize 50

要初始化碎片,请按照以下步骤操作.

To initialize the Shard, follow the steps below.

<path-to-mongo>/bin/mongo --port <shard-port>

然后,运行命令 rs.initiate()

假设您在计算机2上复制了MongoDB可执行文件.在计算机2上运行以下命令

Assuming on Computer 2 you have copied the MongoDB executable. Run the Following command on Computer 2

<path-to-mongodb>/bin/mongos --configdb <C1-IP>:<port-1>,<C1-IP>:<port-2>,<C1-IP>:<port-3> --port 27017

然后运行(在计算机2上),

Then run (on Computer-2),

<path-to-mongodb>/bin/mongo --port 27017

27017是默认端口,我仅出于冗长程度使用该选项.

27017 is default port, I am using that option just for verbosity.

注释1 如果分片初始化错误仍然存​​在 在mongos shell中运行以下命令,

Note 1 If the shard initialization error persists Run the following command in mongos shell,

sh.addShard("a/<C1-IP>:<Shard-port>")

注释2 ,请确保目录shardedcluster/cfg0,shardedcluster/cfg1,shardedcluster/cfg2,shardedcluster/a存在并且具有适当的写许可权.

Note 2 Please, ensure that directory shardedcluster/cfg0, shardedcluster/cfg1, shardedcluster/cfg2, shardedcluster/a exists and have proper write permissions.

要获取更多详细信息,请点击以下链接. http://www.mongodbspain.com/zh-CN/2015/01/26/how-to-set-up-a-mongodb-sharded-cluster/

To get more details, follow the below link. http://www.mongodbspain.com/en/2015/01/26/how-to-set-up-a-mongodb-sharded-cluster/

我只给了您所需的命令.

I have given you only the required commands out of it.

这篇关于Mongodb:在两台计算机之间共享数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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