【问题标题】:How can I create a MongoDB cluster using multiple/three nodes/servers/machines using a single shell script?如何使用单个 shell 脚本使用多个/三个节点/服务器/机器创建 MongoDB 集群?
【发布时间】:2015-06-20 00:04:00
【问题描述】:
  1. 如何从单个远程/本地终端启动 3 配置服务器?
  2. 如何启动分片服务器?
  3. 如何将多台机器添加到分片集群?
  4. 如何在多节点集群中创建副本集?

【问题讨论】:

  • 到目前为止你尝试过什么?您是否在 StackOverflow 上搜索过尚未回答您问题的答案?另请看dba.stackexchange.com

标签: mongodb sharding replicaset


【解决方案1】:

这里你需要一个终端来启动分片服务器

每个分片有 1 个 .Script -

在每个分片上,你都会有一个脚本 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-06
    • 2021-04-14
    • 1970-01-01
    • 2023-01-29
    • 2014-04-26
    • 1970-01-01
    • 1970-01-01
    • 2017-12-03
    相关资源
    最近更新 更多