搭建sharded cluster

    xiaoxiao2021-12-12  22

    1创建replica set的配置server 如果使用配置文件,设置 sharding.clusterRole to configsvr,replication.replSetName 为控制server的名称。 2连接到一个配置server mongo –host –port 3初始化rs rs.initiate( { _id: “”, configsvr: true, members: [ { _id : 0, host : “cfg1.example.net:27017” }, { _id : 1, host : “cfg2.example.net:27017” }, { _id : 2, host : “cfg3.example.net:27017” } ] } ) 4创建分片replica set 在分片的控制文件中设置下面的参数 sharding: clusterRole: shardsvr replication: replSetName: 5启动 连接到rs中的一个成员 6初始化shared rs rs.initiate( { _id : , members: [ { _id : 0, host : “s1-mongo1.example.net:27017” }, { _id : 1, host : “s1-mongo2.example.net:27017” }, { _id : 2, host : “s1-mongo3.example.net:27017” } ] } ) 7mongos的配置文件中,需要设置参数: sharding: configDB: /cfg1.example.net:27017,cfg2.example.net:27017, 启动mongos –config 8连接mongos mongo –host –port 9添加分片到集群 sh.addShard( “/s1-mongo1.example.net:27017”) 10让数据库能分片 sh.enableSharding(“”) 11对集合设置分片 sh.shardCollection(“.”, { : } )

    可以设置hash,范围 分片,吐槽mongodb的权限设置,在搭建shared cluster的时候,要先去掉认证,在搭建完成后在启动认证,如果你的配置复制集与分片复制集,在搭建后,启动了认证,那么在mongos中添加的时候会提示没有权限。

    —————–测试环境下的配置中可以简化架构—————-

    转载请注明原文地址: https://ju.6miu.com/read-900082.html

    最新回复(0)