MongoDB sharding simple instance

Source: Internet
Author: User
Tags install mongodb mongodb sharding

MongoDB sharding simple instance
Parts

Another type of cluster exists in Mongodb, that is, the sharding technology, which can meet the needs of a large increase in MongoDB data volume.

When MongoDB stores massive amounts of data, one machine may not be enough to store data or provide acceptable read/write throughput. In this case, we can split data on multiple machines so that the database system can store and process more data.

Why use sharding?
  • Copy all write operations to the master node
  • Sensitive delayed data is queried on the master node.
  • A single replica set is limited to 12 nodes.
  • When the Request volume is large, there will be insufficient memory.
  • Insufficient local disk
  • Vertical Scaling is expensive
MongoDB sharding

Shows the sharded cluster structure distribution in MongoDB:

There are three main components as follows:

  • Shard:

    Used to store actual data blocks. In the actual production environment, a shard server role can be assumed by a relica set of several machines to prevent single point of failure (spof) on the host.

  • Config Server:

    The mongod instance stores the entire ClusterMetadata, including the chunk information.

  • Query Routers:

    Frontend routing allows clients to access the cluster and make the cluster look like a single database. Front-end applications can be used transparently.

Specific instance

Use three shard Configuration Services

1. Start three Database Server ports: 55555, 55556, 55557, host: localhost.

./Mongod -- port 55555 -- dbpath = data/share1 -- logpath = data/share1/logs/s1.log -- logappend -- fork

./Mongod -- port 555556 -- dbpath = data/share2 -- logpath = data/share2/logs/s2.log -- logappend -- fork

./Mongod -- port 55557 -- dbpath = data/logs 3 -- logpath = data/logs 3/logs/s3.log -- logappend -- fork

    

2. Start the configuration server

./Mongod -- port 55558 -- dbpath = data/config -- logpath = data/config/logs/cnf. log -- logappend -- fork

3. Start the routing service.

./Mongos -- port 55554 -- dbpath = data/share -- logpath = data/share/logs/route. log -- logappend -- fork -- configdb localhost: 55558 -- chunkSize 500

The chunkSize is the shard size. The configuration service mainly stores the route information.

4. Add shard

Use admin

Db. runCommand ({addshard: "localhost: 55555 "})

Db. runCommand ({addshard: "localhost: 55556 "})

Db. runCommand ({addshard: "localhost: 55557 "})

Db. runCommand ({enablesharding: "test"}) // The database test has the sharding capability.

Db. runCommand ({shardcollection: "test. log ", key: {id: 1, time: 1}) // specify the partitions used by the table corresponding to the database in the document. in test, the log table is sharded Based on the id and time.

5. view the shard status

Db. runCommand ({listshards: 1 })

For more MongoDB tutorials, see the following:

CentOS compilation and installation of php extensions for MongoDB and mongoDB

CentOS 6 install MongoDB and server configuration using yum

Install MongoDB2.4.3 in Ubuntu 13.04

MongoDB beginners must read (both concepts and practices)

MongoDB Installation Guide for Ubunu 14.04

MongoDB authoritative Guide (The Definitive Guide) in English [PDF]

Nagios monitoring MongoDB sharded cluster service practice

Build MongoDB Service Based on CentOS 6.5 Operating System

MongoDB details: click here
MongoDB: click here

This article permanently updates the link address:

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.