【Mongodb】往分片复制集添加复制成员
                                            
                                                
            1.新的成员机器上安装mongo,启动shard1
			
/usr/local/mongodb/bin/mongod -f shard1.conf
	
2.主节点上加入新的复制集成员
	
3.shard2 config 加成员同理(过程略)
4.检查是否加入成功
	
4.最后修改下配置文件
	
                
            
                                                            
网站题目:【Mongodb】往分片复制集添加复制成员
浏览地址:http://www.cqwzjz.cn/article/gispig.html
                                            
                                        - 
			[root@ip-10-1-2-183 etc]# more shard1.conf 
 
- 
			logpath=/usr/local/MongoDB/logs/mongo_shard1.log
 
- 
			logappend=true # need logrotae scripts
 
- 
			fork=true
 
- 
			journal=true
 
- 
			port=27019
 
- 
			#vvvvv = true
 
- 
			#diaglog = 3
 
- 
			dbpath=/usr/local/mongodb/shard1
 
- 
			pidfilepath=/usr/local/mongodb/logs/mongo_shard1.pid
 
- 
			bind_ip=10.1.2.183
 
- 
			replSet=shard1
 
- shardsvr=true
/usr/local/mongodb/bin/mongod -f shard1.conf
2.主节点上加入新的复制集成员
- 
			[root@ip-10-1-2-32 etc]# /usr/local/mongodb/bin/mongo 10.1.2.32:27019
 
- 
			shard1:PRIMARY> rs.add({_id: 3, host: "10.1.2.183:27019"})
 
- 
			{
 
- 
			        "ok" : 1,
 
- 
			        "operationTime" : Timestamp(1525752728, 3),
 
- 
			        "$gleStats" : {
 
- 
			                "lastOpTime" : {
 
- 
			                        "ts" : Timestamp(1525752728, 3),
 
- 
			                        "t" : NumberLong(1)
 
- 
			                },
 
- 
			                "electionId" : ObjectId("7fffffff0000000000000001")
 
- 
			        },
 
- 
			        "$clusterTime" : {
 
- 
			                "clusterTime" : Timestamp(1525752728, 3),
 
- 
			                "signature" : {
 
- 
			                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
 
- 
			                        "keyId" : NumberLong(0)
 
- 
			                }
 
- 
			        },
 
- 
			        "$configServerState" : {
 
- 
			                "opTime" : {
 
- 
			                        "ts" : Timestamp(1525752728, 2),
 
- 
			                        "t" : NumberLong(1)
 
- 
			                }
 
- 
			        }
 
- 
			}
 
- 
			shard1:PRIMARY> rs.isMaster()
 
- 
			{
 
- 
			        "hosts" : [
 
- 
			                "10.1.2.32:27019",
 
- 
			                "10.1.2.68:27019",
 
- 
			                "10.1.2.175:27019",
 
- 
			                "10.1.2.183:27019"
 
- 
			        ],
 
- 
			        "setName" : "shard1",
 
- 
			        "setVersion" : 4,
 
- 
			        "ismaster" : true,
 
- 
			        "secondary" : false,
 
- 
			        "primary" : "10.1.2.32:27019",
 
- 
			        "me" : "10.1.2.32:27019",
 
- 
			        "electionId" : ObjectId("7fffffff0000000000000001"),
 
- 
			        "lastWrite" : {
 
- 
			                "opTime" : {
 
- 
			                        "ts" : Timestamp(1525752728, 3),
 
- 
			                        "t" : NumberLong(1)
 
- 
			                },
 
- 
			                "lastWriteDate" : ISODate("2018-05-08T04:12:08Z"),
 
- 
			                "majorityOpTime" : {
 
- 
			                        "ts" : Timestamp(1525752728, 3),
 
- 
			                        "t" : NumberLong(1)
 
- 
			                },
 
- 
			                "majorityWriteDate" : ISODate("2018-05-08T04:12:08Z")
 
- 
			        },
 
- 
			        "maxBsonObjectSize" : 16777216,
 
- 
			        "maxMessageSizeBytes" : 48000000,
 
- 
			        "maxWriteBatchSize" : 100000,
 
- 
			        "localTime" : ISODate("2018-05-08T04:12:12.282Z"),
 
- 
			        "logicalSessionTimeoutMinutes" : 30,
 
- 
			        "minWireVersion" : 0,
 
- 
			        "maxWireVersion" : 6,
 
- 
			        "readOnly" : false,
 
- 
			        "ok" : 1,
 
- 
			        "operationTime" : Timestamp(1525752728, 3),
 
- 
			        "$gleStats" : {
 
- 
			                "lastOpTime" : {
 
- 
			                        "ts" : Timestamp(1525752728, 3),
 
- 
			                        "t" : NumberLong(1)
 
- 
			                },
 
- 
			                "electionId" : ObjectId("7fffffff0000000000000001")
 
- 
			        },
 
- 
			        "$clusterTime" : {
 
- 
			                "clusterTime" : Timestamp(1525752729, 3),
 
- 
			                "signature" : {
 
- 
			                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
 
- 
			                        "keyId" : NumberLong(0)
 
- 
			                }
 
- 
			        },
 
- 
			        "$configServerState" : {
 
- 
			                "opTime" : {
 
- 
			                        "ts" : Timestamp(1525752729, 3),
 
- 
			                        "t" : NumberLong(1)
 
- 
			                }
 
- 
			        }
 
- 
			}
 
- 
			shard1:PRIMARY> rs.conf()
 
- 
			{
 
- 
			        "_id" : "shard1",
 
- 
			        "version" : 4,
 
- 
			        "protocolVersion" : NumberLong(1),
 
- 
			        "members" : [
 
- 
			                {
 
- 
			                        "_id" : 0,
 
- 
			                        "host" : "10.1.2.32:27019",
 
- 
			                        "arbiterOnly" : false,
 
- 
			                        "buildIndexes" : true,
 
- 
			                        "hidden" : false,
 
- 
			                        "priority" : 1,
 
- 
			                        "tags" : {
 
- 
			
 
- 
			                        },
 
- 
			                        "slaveDelay" : NumberLong(0),
 
- 
			                        "votes" : 1
 
- 
			                },
 
- 
			                {
 
- 
			                        "_id" : 1,
 
- 
			                        "host" : "10.1.2.68:27019",
 
- 
			                        "arbiterOnly" : false,
 
- 
			                        "buildIndexes" : true,
 
- 
			                        "hidden" : false,
 
- 
			                        "priority" : 1,
 
- 
			                        "tags" : {
 
- 
			
 
- 
			                        },
 
- 
			                        "slaveDelay" : NumberLong(0),
 
- 
			                        "votes" : 1
 
- 
			                },
 
- 
			                {
 
- 
			                        "_id" : 2,
 
- 
			                        "host" : "10.1.2.175:27019",
 
- 
			                        "arbiterOnly" : false,
 
- 
			                        "buildIndexes" : true,
 
- 
			                        "hidden" : false,
 
- 
			                        "priority" : 1,
 
- 
			                        "tags" : {
 
- 
			
 
- 
			                        },
 
- 
			                        "slaveDelay" : NumberLong(0),
 
- 
			                        "votes" : 1
 
- 
			                },
 
- 
			                {
 
- 
			                        "_id" : 3,
 
- 
			                        "host" : "10.1.2.183:27019",
 
- 
			                        "arbiterOnly" : false,
 
- 
			                        "buildIndexes" : true,
 
- 
			                        "hidden" : false,
 
- 
			                        "priority" : 1,
 
- 
			                        "tags" : {
 
- 
			
 
- 
			                        },
 
- 
			                        "slaveDelay" : NumberLong(0),
 
- 
			                        "votes" : 1
 
- 
			                }
 
- 
			        ],
 
- 
			        "settings" : {
 
- 
			                "chainingAllowed" : true,
 
- 
			                "heartbeatIntervalMillis" : 2000,
 
- 
			                "heartbeatTimeoutSecs" : 10,
 
- 
			                "electionTimeoutMillis" : 10000,
 
- 
			                "catchUpTimeoutMillis" : -1,
 
- 
			                "catchUpTakeoverDelayMillis" : 30000,
 
- 
			                "getLastErrorModes" : {
 
- 
			
 
- 
			                },
 
- 
			                "getLastErrorDefaults" : {
 
- 
			                        "w" : 1,
 
- 
			                        "wtimeout" : 0
 
- 
			                },
 
- 
			                "replicaSetId" : ObjectId("5aeab9557a9235efbe4a9b59")
 
- }
- 
			shard1:PRIMARY> rs.status()
 {
 "set" : "shard1",
 "date" : ISODate("2018-05-08T05:38:35.245Z"),
 "myState" : 1,
 "term" : NumberLong(1),
 "heartbeatIntervalMillis" : NumberLong(2000),
 "optimes" : {
 "lastCommittedOpTime" : {
 "ts" : Timestamp(1525757907, 1),
 "t" : NumberLong(1)
 },
 "readConcernMajorityOpTime" : {
 "ts" : Timestamp(1525757907, 1),
 "t" : NumberLong(1)
 },
 "appliedOpTime" : {
 "ts" : Timestamp(1525757907, 1),
 "t" : NumberLong(1)
 },
 "durableOpTime" : {
 "ts" : Timestamp(1525757907, 1),
 "t" : NumberLong(1)
 }
 },
 "members" : [
 {
 "_id" : 0,
 "name" : "10.1.2.32:27019",
 "health" : 1,
 "state" : 1,
 "stateStr" : "PRIMARY",
 "uptime" : 425793,
 "optime" : {
 "ts" : Timestamp(1525757907, 1),
 "t" : NumberLong(1)
 },
 "optimeDate" : ISODate("2018-05-08T05:38:27Z"),
 "electionTime" : Timestamp(1525332319, 1),
 "electionDate" : ISODate("2018-05-03T07:25:19Z"),
 "configVersion" : 4,
 "self" : true
 },
 {
 "_id" : 1,
 "name" : "10.1.2.68:27019",
 "health" : 1,
 "state" : 2,
 "stateStr" : "SECONDARY",
 "uptime" : 425606,
 "optime" : {
 "ts" : Timestamp(1525757907, 1),
 "t" : NumberLong(1)
 },
 "optimeDurable" : {
 "ts" : Timestamp(1525757907, 1),
 "t" : NumberLong(1)
 },
 "optimeDate" : ISODate("2018-05-08T05:38:27Z"),
 "optimeDurableDate" : ISODate("2018-05-08T05:38:27Z"),
 "lastHeartbeat" : ISODate("2018-05-08T05:38:34.014Z"),
 "lastHeartbeatRecv" : ISODate("2018-05-08T05:38:34.014Z"),
 "pingMs" : NumberLong(0),
 "syncingTo" : "10.1.2.32:27019",
 "configVersion" : 4
 },
 {
 "_id" : 2,
 "name" : "10.1.2.175:27019",
 "health" : 1,
 "state" : 2,
 "stateStr" : "SECONDARY",
 "uptime" : 425606,
 "optime" : {
 "ts" : Timestamp(1525757907, 1),
 "t" : NumberLong(1)
 },
 "optimeDurable" : {
 "ts" : Timestamp(1525757907, 1),
 "t" : NumberLong(1)
 },
 "optimeDate" : ISODate("2018-05-08T05:38:27Z"),
 "optimeDurableDate" : ISODate("2018-05-08T05:38:27Z"),
 "lastHeartbeat" : ISODate("2018-05-08T05:38:34.014Z"),
 "lastHeartbeatRecv" : ISODate("2018-05-08T05:38:34.016Z"),
 "pingMs" : NumberLong(0),
 "syncingTo" : "10.1.2.183:27019",
 "configVersion" : 4
 },
 {
 "_id" : 3,
 "name" : "10.1.2.183:27019",
 "health" : 1,
 "state" : 2,
 "stateStr" : "SECONDARY",
 "uptime" : 5184,
 "optime" : {
 "ts" : Timestamp(1525757907, 1),
 "t" : NumberLong(1)
 },
 "optimeDurable" : {
 "ts" : Timestamp(1525757907, 1),
 "t" : NumberLong(1)
 },
 "optimeDate" : ISODate("2018-05-08T05:38:27Z"),
 "optimeDurableDate" : ISODate("2018-05-08T05:38:27Z"),
 "lastHeartbeat" : ISODate("2018-05-08T05:38:34.016Z"),
 "lastHeartbeatRecv" : ISODate("2018-05-08T05:38:33.567Z"),
 "pingMs" : NumberLong(0),
 "syncingTo" : "10.1.2.68:27019",
 "configVersion" : 4
 }
 ],
 "ok" : 1,
 "operationTime" : Timestamp(1525757907, 1),
 "$gleStats" : {
 "lastOpTime" : Timestamp(0, 0),
 "electionId" : ObjectId("7fffffff0000000000000001")
 },
 "$clusterTime" : {
 "clusterTime" : Timestamp(1525757911, 2),
 "signature" : {
 "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
 "keyId" : NumberLong(0)
 }
 },
 "$configServerState" : {
 "opTime" : {
 "ts" : Timestamp(1525757911, 2),
 "t" : NumberLong(1)
 }
 }
 }
 
		可以看到新的成员已经加入复制集中去了
	
3.shard2 config 加成员同理(过程略)
4.检查是否加入成功
- 登陆mongos端口可以看到
- 
			[root@ip-10-1-2-32 etc]# /usr/local/mongodb/bin/mongo 10.1.2.32:30000
 
- 
			MongoDB shell version v3.6.4
 
- 
			connecting to: mongodb://10.1.2.32:30000/test
 
- 
			MongoDB server version: 3.6.4
 
- 
			Server has startup warnings: 
 
- 
			2018-05-03T07:47:09.379+0000 I CONTROL [main] 
 
- 
			2018-05-03T07:47:09.379+0000 I CONTROL [main] ** WARNING: Access control is not enabled for the database.
 
- 
			2018-05-03T07:47:09.379+0000 I CONTROL [main] ** Read and write access to data and configuration is unrestricted.
 
- 
			2018-05-03T07:47:09.379+0000 I CONTROL [main] ** WARNING: You are running this process as the root user, which is not recommended.
 
- 
			2018-05-03T07:47:09.379+0000 I CONTROL [main] 
 
- 
			mongos> db.printShardingStatus();
 
- 
			--- Sharding Status --- 
 
- 
			  sharding version: {
 
- 
			        "_id" : 1,
 
- 
			        "minCompatibleVersion" : 5,
 
- 
			        "currentVersion" : 6,
 
- 
			        "clusterId" : ObjectId("5aeabc4db192a4fefca1c888")
 
- 
			  }
 
- 
			  shards:
 
- 
			        { "_id" : "shard1", "host" : "shard1/10.1.2.175:27019,10.1.2.183:27019,10.1.2.32:27019,10.1.2.68:27019", "state" : 1 }   ---新的复制集成员自动同步到分片信息了
 
- 
			        { "_id" : "shard2", "host" : "shard2/10.1.2.175:27018,10.1.2.32:27018,10.1.2.68:27018", "state" : 1 }
 
- 
			        { "_id" : "shard3", "host" : "shard3/10.1.2.175:27017,10.1.2.32:27017,10.1.2.68:27017", "state" : 1 }
 
- 
			  active mongoses:
 
- 
			        "3.6.4" : 3
 
- 
			  autosplit:
 
- 
			        Currently enabled: yes
 
- 
			  balancer:
 
- 
			        Currently enabled: yes
 
- 
			        Currently running: no
 
- 
			        Failed balancer rounds in last 5 attempts: 0
 
- 
			        Migration Results for the last 24 hours: 
 
- 
			                No recent migrations
 
- 
			  databases:
 
- 
			        { "_id" : "config", "primary" : "config", "partitioned" : true }
 
- 
			                config.system.sessions
 
- 
			                        shard key: { "_id" : 1 }
 
- 
			                        unique: false
 
- 
			                        balancing: true
 
- 
			                        chunks:
 
- 
			                                shard1  1
 
- 
			                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard1 Timestamp(1, 0) 
 
- 
			        { "_id" : "test", "primary" : "shard2", "partitioned" : true }
 
- 
			                test.users
 
- 
			                        shard key: { "_id" : 1 }
 
- 
			                        unique: false
 
- 
			                        balancing: true
 
- 
			                        chunks:
 
- 
			                                shard2  1
 
- 
			                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard2 Timestamp(1, 0) 
 
- 
			
 
- mongos> ;
4.最后修改下配置文件
- 避免重启问题,写入配置文件
- 
			[root@ip-10-1-2-32 etc]# more mongos.conf 
 
- 
			logpath=/usr/local/mongodb/logs/mongos.log
 
- 
			logappend=true # need logrotae scripts
 
- 
			fork=true
 
- 
			port=30000
 
- 
			pidfilepath=/usr/local/mongodb/logs/mongos.pid
 
- 
			configdb=conf/10.1.2.32:27000,10.1.2.68:27000,10.1.2.175:27000,10.1.2.183:27000
 
- bind_ip=10.1.2.32
网站题目:【Mongodb】往分片复制集添加复制成员
浏览地址:http://www.cqwzjz.cn/article/gispig.html

 建站
建站
 咨询
咨询 售后
售后
 建站咨询
建站咨询 
 