MongoDB Shard Cluster Data Migration (scenario I)

Source: Internet
Author: User
Tags mongodb
Migrate data from an existing MongoDB replica set to a new shard cluster and design three migration scenarios.
Scenario One: Synchronize the data first, then set up the Shard cluster, and finally configure the Shard cluster. export the data that needs to be migrated, set up the first replica set, import the data into the replica set, add two additional replica sets, start config server, start MONGOs server, configure the Shard cluster. 1. Export the data that needs to be migrated;/usr/local/mongo/bin/mongodump--host 172.16.8.134:29017-d 201-o/data/data/mongo/tmp/--directoryperdb The data is synchronized to 131 of the/data/data/mongodb/tmp directory in 2. Establish the first replica set 2.1 establish the first replica set Shard1, server1 with no shards:/usr/local/mongo/bin/mongod--replset shard1--port 29017--dbpath=/data/ Data/mongodb/shard11--logpath=/data/log/shard11.log--logappend--fork server2:/usr/local/mongo/bin/mongod-- Replset shard1--port 29017--dbpath=/data/data/mongodb/shard12--logpath=/data/log/shard12.log--logappend--fork Server3:/usr/local/mongo/bin/mongod--replset shard1--port 29017--dbpath=/data/data/mongodb/shard13--logpath=/ Data/log/shard13.log--logappend--fork 2.2 Initializes the first replica set shard1./mongo--port 29017 config={_id: ' Shard1 ', Members: [{_id: 0, Host: ' 172.16.8.131:29017 '},{_id:1, Host: ' 172.16.8.132:29017 '},{_id:2, Host: ' 172.16.8.133:29017 '}]} Rs.initiat E (config) rs.status ()   3. Importing data into the replica set needs to be imported into the primary node./mongorestore--host 172.16.8.131:29017-d 201--directoryperdb/data/data/monGODB/TMP/201/  4. Add two additional replica sets 4.1 start the remaining two replica sets without shards server1:/usr/local/mongo/bin/mongod--replset shard2--port 29018--dbpath=/data/data/ Mongodb/shard21--logpath=/data/log/shard21.log--logappend--fork/usr/local/mongo/bin/mongod--replSet shard3-- Port 29019--dbpath=/data/data/mongodb/shard31--logpath=/data/log/shard31.log--logappend--fork server2:/usr/local /mongo/bin/mongod--replset shard2--port 29018--dbpath=/data/data/mongodb/shard22--logpath=/data/log/shard22.log- -logappend--fork/usr/local/mongo/bin/mongod--replset shard3--port 29019--dbpath=/data/data/mongodb/shard32-- Logpath=/data/log/shard32.log--logappend--fork server3:/usr/local/mongo/bin/mongod--replset shard2--port 29018-- Dbpath=/data/data/mongodb/shard23--logpath=/data/log/shard23.log--logappend--fork/usr/local/mongo/bin/mongod-- Replset shard3--port 29019--dbpath=/data/data/mongodb/shard33--logpath=/data/log/shard33.log--logappend--fork 4.2 Initializes the remaining two replica sets./mongo--port 29018 config={_id:' Shard2 ', Members: [{_id:0, Host: ' 172.16.8.131:29018 '},{_id:1, Host: ' 172.16.8.132:29018 '},{_id:2, Host: ' 172.16 .8.133:29018 '}]} rs.initiate (config) rs.status ()./mongo--port 29019 config={_id: ' Shard3 ', Members: [{_id:0, Host: ' 172.16.8.131:29019 '},{_id:1, Host: ' 172.16.8.132:29019 '},{_id:2, Host: ' 172.16.8.133:29019 '}]} rs.initiate (config) Rs.status ()   5. Start config Server/usr/local/mongo/bin/mongod--configsvr--dbpath=/data/data/mongodb/config--port 20000--logpath=/ Data/log/config.log--logappend--fork/usr/local/mongo/bin/mongod--configsvr--dbpath=/data/data/mongodb/config-- Port 20000--logpath=/data/log/config.log--logappend--fork    /usr/local/mongo/bin/mongod-- Configsvr--dbpath=/data/data/mongodb/config--port 20000--logpath=/data/log/config.log--logappend--fork   6. Start MONGOs server/usr/local/mongo/bin/mongos--configdb 172.16.8.131:20000,172.16.8.132:20000,172.16.8.133:20000- Port 40000-chunksize 5--logpath=/data/Log/mongos.log--logappend--fork/usr/local/mongo/bin/mongos--configdb 172.16.8.131:20000,172.16.8.132:20000,172.16.8.133:20000-port 40000-chunksize 5--logpath=/data/log/mongos.log-- Logappend--fork/usr/local/mongo/bin/mongos--configdb 172.16.8.131:20000,172.16.8.132:20000,172.16.8.133:20000- Port 40000-chunksize 5--logpath=/data/log/mongos.log--logappend--fork    7. Configure Shard Cluster 7.1 To configure Shards./mongo 172.16.8.131:40000/admin db 7.2 Join shards Db.runcommand ({addshard: "shard1/172.16.8.131:29017,17 2.16.8.132:29017,172.16.8.133:29017 ", Name:" Shard1 ", maxsize:20480}); Db.runcommand ({addshard: "shard2/172.16.8.131:29018,172.16.8.132:29018,172.16.8.133:29018", Name: "Shard2", maxsize:20480}); Db.runcommand ({addshard: "shard3/172.16.8.131:29019,172.16.8.132:29019,172.16.8.133:29019", Name: "Shard3", maxsize:20480});  7.3 Listing shards Db.runcommand ({listshards:1}) 7.4 Activate Shard Db.runcommand ({enablesharding: "201"} ); 7.5 Build Index Use 201 Db.customer_user_mst.ensureIndex ({"Name":1}) Db.user_attr_mst.ensureIndex ({"Name": 1}) 7.6 Configuration tablet key use admin db.runcommand ({"Shardcollection": "201.customer_user_ MST ", key:{" name ": 1})           Db.runcommand ({" Shardcollection ":" 201.user_attr_mst ", key:{" name ": 1})          
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.