如何使用单个shell脚本使用多个/三个节点/服务器/机器创建MongoDB集群?

时间:2015-04-14 11:38:01

标签: mongodb sharding replicaset

  1. 如何从单个远程/本地终端启动3配置服务器?
  2. 如何启动分片服务器?
  3. 如何将多台计算机添加到分片群集?
  4. 如何在多节点群集中创建副本集?

1 个答案:

答案 0 :(得分:2)

在这里,您将需要一个终端来启动分片服务器

1.每个分片的脚本 -

在每个碎片上你都会有一个脚本cluster.sh,其中包括

/mongodb-linux-x86_64-2.6.6/bin/mongod --replSet <shard name> --logpath <logpath of replicaset> --dbpath --port <port no> --shardsvr

应该对该分片中的每个副本集进行此操作

然后 使用脚本中提到的端口连接到mongo客户端以启动分片服务器。

config = { _id: <shard name>, members:[
          { _id : 0, host : <ip of the shard : its port no.> }]

通过此命令添加所有副本集

rs.initiate(config)

<强> 2。每个配置服务器的脚本(cfgserver.sh)

在每台将成为配置服务器的计算机上

你将有一个配置服务器的脚本

/root/mongodb-linux-x86_64-2.6.6/bin/mongod --logpath <path to store config logs> --dbpath <path to store config data> --port <port no>  --configsvr

第3。在终端中编写每个分片和配置服务器的脚本

每个分片或群集

ssh 10.x.x.x 'sh /mongodb-linux-x86_64-2.6.6/bin/cluster.sh'
每个配置服务器

ssh 10.x.x.x 'sh /mongodb-linux-x86_64-2.6.6/bin/cfgserver.sh'

在此之后,所有群集将以所需数量的副本集启动 并且所有配置服务器也将运行。

我们剩下的就是在这个环境中添加分片

所以它将以下列方式完成

启动mongo客户端并为要添加的每个分片触发此命令

db.adminCommand( { addShard : "<name of the shard>/"+"ip of that shard:port number" } );

分片的名称将与我们在每个分片的脚本中定义的相同,即cluster.sh

相关问题