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

1 回答 1

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

于 2015-04-21T07:02:28.950 回答