启动配置节点
./bin/mongod -f config/config-17017.conf ./bin/mongod -f config/config-17018.conf ./bin/mongod -f config/config-17019.conf
进入任意节点的mongo shell 并添加 配置节点集群 注意use admin
【MongoDB分片集群 Shard Cluster】./bin/mongo --port 17017 use adminvar cfg ={"_id":"configsvr","members":[ {"_id":1,"host":"127.0.0.1:17017"}, {"_id":2,"host":"127.0.0.1:17018"}, {"_id":3,"host":"127.0.0.1:17019"}]};rs.initiate(cfg)
4.2 配置shard集群
集群搭建37017到37019
dbpath=/usr/local/mongodb/shard/shard1/shard1-37017 bind_ip=0.0.0.0port=37017fork=true logpath=/usr/local/mongodb/shard/shard1/shard1-37017.log replSet=shard1shardsvr=truedbpath=/usr/local/mongodb/shard/shard1/shard1-37018 bind_ip=0.0.0.0port=37018fork=true logpath=/usr/local/mongodb/shard/shard1/shard1-37018.log replSet=shard1shardsvr=truedbpath=/usr/local/mongodb/shard/shard1/shard1-37019 bind_ip=0.0.0.0port=37019fork=true logpath=/usr/local/mongodb/shard/shard1/shard1-37019.log replSet=shard1shardsvr=true
启动每个 然后进入其中一个进行集群配置
./bin/mongod -f shard/shard1/shard1-37017.conf./bin/mongod -f shard/shard1/shard1-37018.conf./bin/mongod -f shard/shard1/shard1-37019.conf
var cfg ={"_id":"shard1", "protocolVersion" : 1,"members":[ {"_id":1,"host":"127.0.0.1:37017"}, {"_id":2,"host":"127.0.0.1:37018"}, {"_id":3,"host":"127.0.0.1:37019"}]}; rs.initiate(cfg) rs.status()
集群搭建47017到47019
dbpath=/usr/local/mongodb/shard/shard2/shard2-47017 bind_ip=0.0.0.0port=47017fork=true logpath=/usr/local/mongodb/shard/shard2/shard2-47017.log replSet=shard2shardsvr=truedbpath=/usr/local/mongodb/shard/shard2/shard2-47018 bind_ip=0.0.0.0port=47018fork=true logpath=/usr/local/mongodb/shard/shard2/shard2-47018.log replSet=shard2shardsvr=truedbpath=/usr/local/mongodb/shard/shard2/shard2-47019 bind_ip=0.0.0.0port=47019fork=true logpath=/usr/local/mongodb/shard/shard2/shard2-47019.log replSet=shard2shardsvr=true
启动每个 然后进入其中一个进行集群配置
./bin/mongod -f shard/shard2/shard2-47017.conf./bin/mongod -f shard/shard2/shard2-47018.conf./bin/mongod -f shard/shard2/shard2-47019.conf
var cfg ={"_id":"shard2", "protocolVersion" : 1,"members":[ {"_id":1,"host":"127.0.0.1:47017"}, {"_id":2,"host":"127.0.0.1:47018"}, {"_id":3,"host":"127.0.0.1:47019"}]}; rs.initiate(cfg) rs.status()
文章插图
4.3 配置和启动 路由节点
route-27017.conf
port=27017bind_ip=0.0.0.0fork=truelogpath=/usr/local/mongodb/route/route.log configdb=configsvr/127.0.0.1:17017,127.0.0.1:17018,127.0.0.1:17019
启动路由节点使用(注意不是)
./bin/mongos -f route/route-27017.conf
4.4 (路由)中添加分片节点
进入路由
mongo --port 27017sh.status() sh.addShard("shard1/127.0.0.1:37017,127.0.0.1:37018,127.0.0.1:37019");sh.addShard("shard2/127.0.0.1:47017,127.0.0.1:47018,127.0.0.1:47019");sh.status()
[root@rpp mongodb]# ./bin/mongo -port=27017MongoDB shell version v4.2.9connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodbImplicit session: session { "id" : UUID("6639aef1-6bc0-434d-a081-63e55f2578a4") }MongoDB server version: 4.2.9Server has startup warnings: 2020-10-10T18:22:15.444+0800 ICONTROL[main] 2020-10-10T18:22:15.444+0800 ICONTROL[main] ** WARNING: Access control is not enabled for the database.2020-10-10T18:22:15.444+0800 ICONTROL[main] **Read and write access to data and configuration is unrestricted.2020-10-10T18:22:15.444+0800 ICONTROL[main] ** WARNING: You are running this process as the root user, which is not recommended.2020-10-10T18:22:15.444+0800 ICONTROL[main] mongos> sh.status() --- Sharding Status --- sharding version: {"_id" : 1,"minCompatibleVersion" : 5,"currentVersion" : 6,"clusterId" : ObjectId("5f8183ddb1aac6cff1404a62")}shards:active mongoses:autosplit:Currently enabled: yesbalancer:Currently enabled:yesCurrently running:noFailed balancer rounds in last 5 attempts:0Migration Results for the last 24 hours: No recent migrationsdatabases:{"_id" : "config","primary" : "config","partitioned" : true }mongos> sh.addShard("shard1/127.0.0.1:37017,127.0.0.1:37018,127.0.0.1:37019"); {"shardAdded" : "shard1","ok" : 1,"operationTime" : Timestamp(1602325711, 7),"$clusterTime" : {"clusterTime" : Timestamp(1602325711, 7),"signature" : {"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),"keyId" : NumberLong(0)}}}mongos> sh.addShard("shard2/127.0.0.1:47017,127.0.0.1:47018,127.0.0.1:47019");{"shardAdded" : "shard2","ok" : 1,"operationTime" : Timestamp(1602325717, 7),"$clusterTime" : {"clusterTime" : Timestamp(1602325717, 7),"signature" : {"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),"keyId" : NumberLong(0)}}}mongos> sh.status()--- Sharding Status --- sharding version: {"_id" : 1,"minCompatibleVersion" : 5,"currentVersion" : 6,"clusterId" : ObjectId("5f8183ddb1aac6cff1404a62")}shards:{"_id" : "shard1","host" : "shard1/127.0.0.1:37017,127.0.0.1:37018,127.0.0.1:37019","state" : 1 }{"_id" : "shard2","host" : "shard2/127.0.0.1:47017,127.0.0.1:47018,127.0.0.1:47019","state" : 1 }active mongoses:"4.2.9" : 1autosplit:Currently enabled: yesbalancer:Currently enabled:yesCurrently running:noFailed balancer rounds in last 5 attempts:0Migration Results for the last 24 hours: No recent migrationsdatabases:{"_id" : "config","primary" : "config","partitioned" : true }mongos>
- Mongodb的副本、分片搭建方式
- Redis缓存服务器的 分片机制 和 哨兵机制 的配置与详解
- 二 进击消息中间件系列:Kafka 单机与集群部署实践
- pycharm连接远程mysql_【已解决】用PyCharm的MongoDB插件
- 打造八大优势产业集群,长沙挺起先进制造“硬脊梁” 长沙之中国之最
- Rancher搭建K8S集群并配置GPU共享完整流程
- 乡村文化产业集群:乡村振兴新引擎,让农村发展更有魅力! 文化产业历史之最有哪些
- KingbaseES V8R6集群运维案例之---sys_rewind应用分析
- 一、查询openGauss集群状态
- RabbitMQ --- 惰性队列、MQ集群