MongoDB advanced ---- & gt; copy and sharding

Source: Internet
Author: User

MongoDB provides the Replica pairs mode to start the database. After the database is started in this mode, the database automatically negotiates who is the master and who is the slave. Once a database server loses power, the other server automatically takes over and becomes the master from that moment on. In case of an error in the other server in the future, the master status will be changed back to the first server.

MongoDB includes an automatic sharding module "mongos" to build a large horizontally scalable Database Cluster, dynamically add servers, and automatically create a horizontally scalable database cluster system, store database sub-tables on each sharding Node

Here I use three servers for testing.

Are

10. X. X.21.163

10. X. X.21.164

10. X. X.228

.................(If a service fails, it may be due to the file lock problem in your Data or the name is incorrect)

Preparations:

Create a data directory for each machine

Server 1

  1. Performance_^ [root @:/usr/local/mongodb] # mkdir-p data/shard11
  2. Performance_^ [root @:/usr/local/mongodb] # mkdir-p data/shard21
Server 2
  1. Performance_^ [root @:/usr/local/mongodb] # mkdir-p data/shard12
  2. Performance_^ [root @:/usr/local/mongodb] # mkdir-p data/shard22
Server 3
  1. Performance_^ [root @:/usr/local/mongodb] # mkdir-p data/shard13
  2. Performance_^ [root @:/usr/local/mongodb] # mkdir-p data/shard23
Then perform Shard1 Replica Sets for each server:

Server1:

  1. ./Mongod -- shardsvr -- replSet shard1 -- port 27017 -- dbpath ../data/shard11 -- oplogSize 100 -- logpath ../data/shard11.log -- logappend -- fork.

Server2:

  1. ./Mongod -- shardsvr -- replSet shard1 -- port 27017 -- dbpath ../data/shard12 -- oplogSize 100 -- logpath ../data/shard12.log -- logappend -- fork.
Server3:
  1. ./Mongod -- shardsvr -- replSet shard1 -- port 27017 -- dbpath ../data/shard13 -- oplogSize 100 -- logpath ../data/shard13.log -- logappend -- fork.
Initialize Replica set:
  1. > Config = {_ id:'Shard1', Members :[
  2. ... {_ Id: 0, host:'10. X. X.228: 27017'},
  3. ... {_ Id: 1, host:'10. X. X.163: 27017'},
  4. ... {_ Id: 2, host:'10. X. X.164: 27017'}]
  5. ...}
  1. Rs. initiate (config );

Configure Replica Sets for Shard2.

Server1:

  1. ./Mongod -- shardsvr -- replSet shard2 -- port 27018 -- dbpath ../data/shard21 -- oplogSize 100 -- logpath ../data/shard21.log -- logappend -- fork.

Server2:

  1. ./Mongod -- shardsvr -- replSet shard2 -- port 27018 -- dbpath ../data/shard22 -- oplogSize 100 -- logpath ../data/shard22.log -- logappend -- fork.
Server3:
  1. ./Mongod -- shardsvr -- replSet shard2 -- port 27018 -- dbpath ../data/shard23 -- oplogSize 100 -- logpath ../data/shard23.log -- logappend -- fork.

After the first initialization, the following error occurs when you run the client:


If you want to use 27018, you must specify


./Mongo 10. X. X.228: 27018

  • 1
  • 2
  • Next Page

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.