标签:root prim ble 文件夹 进程 switch comm 连接 person
完整的搭建mongodb集群(副本集+分片)的样例。。。
准备四台机器,各自是bluejoe1,bluejoe2,bluejoe3,以及bluejoe0
副本集及分片策略确定例如以下:
以此类推
mkdir /usr/local/mongodb/data/db1 /usr/local/mongodb/data/db2 /usr/local/mongodb/data/db3 nohup /usr/local/mongodb/bin/mongod --dbpath /usr/local/mongodb/data/db1 --port 10001 --replSet db1 --logpath=/usr/local/mongodb/log/db1.log & nohup /usr/local/mongodb/bin/mongod --dbpath /usr/local/mongodb/data/db2 --port 10002 --replSet db2 --logpath=/usr/local/mongodb/log/db2.log & nohup /usr/local/mongodb/bin/mongod --dbpath /usr/local/mongodb/data/db3 --port 10003 --replSet db3 --logpath=/usr/local/mongodb/log/db3.log &
mongo bluejoe1:10001 use admin db.runCommand( { "replSetInitiate": { "_id":"db1", "members": [ { "_id":1, "host":"bluejoe1:10001" }, { "_id":2, "host":"bluejoe2:10001" }, { "_id":3, "host":"bluejoe3:10001" } ] } }) mongo bluejoe1:10002 use admin db.runCommand( { "replSetInitiate": { "_id":"db2", "members": [ { "_id":1, "host":"bluejoe1:10002" }, { "_id":2, "host":"bluejoe2:10002" }, { "_id":3, "host":"bluejoe3:10002" } ] } }) mongo bluejoe1:10003 use admin db.runCommand( { "replSetInitiate": { "_id":"db3", "members": [ { "_id":1, "host":"bluejoe1:10003" }, { "_id":2, "host":"bluejoe2:10003" }, { "_id":3, "host":"bluejoe3:10003" } ] } })
db.getMongo().setSlaveOk()
mkdir /usr/local/mongodb/data/configdb nohup /usr/local/mongodb/bin/mongod --dbpath /usr/local/mongodb/data/configdb --port 20000 --logpath=/usr/local/mongodb/log/configdb.log &
/usr/local/mongodb/bin/mongod --dbpath /usr/local/mongodb/data/configdb --shutdown
nohup /usr/local/mongodb/bin/mongos --port 30000 --configdb bluejoe1:20000,bluejoe2:20000,bluejoe3:20000 &
mongo bluejoe0:30000 mongos> use admin switched to db admin db.runCommand({"addShard":"db1/bluejoe1:10001"}) db.runCommand({"addShard":"db2/bluejoe1:10002"}) db.runCommand({"addShard":"db3/bluejoe1:10003"})
mongos> db.runCommand({listshards:1}) { "shards" : [ { "_id" : "db1", "host" : "db1/bluejoe1:10001,bluejoe2:10001,bluejoe3:10001" }, { "_id" : "db2", "host" : "db2/bluejoe1:10002,bluejoe2:10002,bluejoe3:10002" }, { "_id" : "db3", "host" : "db3/bluejoe1:10003,bluejoe2:10003,bluejoe3:10003" } ], "ok" : 1 }能够看出,虽然注冊的时候仅仅是提供了副本集的主节点,但mongos已知晓了各辅助节点;
mongos> db.runCommand({"enablesharding":"test"}) { "ok" : 1 } mongos> db.runCommand({"shardcollection":"test.person","key":{_id:‘hashed‘}}) { "collectionsharded" : "test.person", "ok" : 1 }
mongos> for(var i=0;i<10;i++){db.person.insert({name:"bluejoe"+i});} WriteResult({ "nInserted" : 1 })
[root@hadoop0 ~]# mongo bluejoe3:10002 MongoDB shell version: 2.6.5 connecting to: bluejoe3:10002/test shard1:PRIMARY> db.person.find() { "_id" : ObjectId("546ff1013a0d0ec68b42a914"), "name" : "bluejoe0" } { "_id" : ObjectId("546ff1013a0d0ec68b42a915"), "name" : "bluejoe1" } { "_id" : ObjectId("546ff1013a0d0ec68b42a91a"), "name" : "bluejoe6" } { "_id" : ObjectId("546ff1013a0d0ec68b42a91b"), "name" : "bluejoe7" } { "_id" : ObjectId("546ff1013a0d0ec68b42a91c"), "name" : "bluejoe8" } shard1:PRIMARY> exit bye [root@hadoop0 ~]# mongo bluejoe2:10001 MongoDB shell version: 2.6.5 connecting to: bluejoe2:10001/test shard2:PRIMARY> db.person.find() { "_id" : ObjectId("546ff1013a0d0ec68b42a918"), "name" : "bluejoe4" } shard2:PRIMARY> exit bye [root@hadoop0 ~]# mongo bluejoe3:10001 MongoDB shell version: 2.6.5 connecting to: bluejoe3:10001/test shard3:PRIMARY> db.person.find() { "_id" : ObjectId("546ff1013a0d0ec68b42a916"), "name" : "bluejoe2" } { "_id" : ObjectId("546ff1013a0d0ec68b42a917"), "name" : "bluejoe3" } { "_id" : ObjectId("546ff1013a0d0ec68b42a919"), "name" : "bluejoe5" } { "_id" : ObjectId("546ff1013a0d0ec68b42a91d"), "name" : "bluejoe9" } shard3:PRIMARY>
标签:root prim ble 文件夹 进程 switch comm 连接 person
原文地址:http://www.cnblogs.com/yfceshi/p/6745097.html