日期:2014-05-16  浏览次数:20497 次

MongoDB学习整理之Replica Sets + Sharding

环境准备:

配置Replica Sets
        1、配置shard1所用到Replica Set1
                Server A:
                /app/mongo/mongodb/bin/mongod --shardsvr --replSet shard1 --port 27017 --dbpath /app/mongo/data/shard1_1 --logpath /app/mongo/data/shard1_1/shard1_1.log --logappend --fork
                Server B:
                /app/mongo/mongodb/bin/mongod --shardsvr --replSet shard1 --port 27017 --dbpath /app/mongo/data/shard1_2 --logpath /app/mongo/data/shard1_2/shard1_2.log --logappend --fork
                Server C:
                /app/mongo/mongodb/bin/mongod --shardsvr --replSet shard1 --port 27017 --dbpath /app/mongo/data/shard1_3 --logpath /app/mongo/data/shard1_3/shard1_3.log --logappend --fork
               
                用mongo连接其中一台机器的27017端口的mongod,初始化Replica Set 1,如下面代码所示:
                        [mongodb@Hadoop2 bin]$ /app/mongo/mongodb/bin/mongo --port 27017
                        MongoDB shell version: 2.0.5
                        connecting to: 127.0.0.1:27017/test
                        > config ={_id:'shard1',members:[{_id:0,host:'132.42.33.212:27017'},{_id:1,host:'132.42.33.213:27017'},{_id:2,host:'132.42.33.214:27017'}]}
                        {
                                "_id" : "shard1",
                                "members" : [
                                        {
                                                "_id" : 0,
                                                "host" : "132.42.33.212:27017"