MongoDB by Tonny

1,357 views

Published on

Presentasi dari Tonny Kusdarwanto, Crew dari Agate Studio dalam event Talent Development Saturday Agate Studio. http://agatestudio.com

Talent Development Saturday adalah acara Agate Studio crew sharing berbagai topik. Mulai dari Art, Programming, Game Production dan General Business/Management. TDS ini dilakukan tanggal 8 Februari 2014 di Bandung Digital Valley.

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,357
On SlideShare
0
From Embeds
0
Number of Embeds
92
Actions
Shares
0
Downloads
910
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

MongoDB by Tonny

  1. 1. @agatestudio Replication and Sharding on MongoDB Tonny K Publishing Agate Studio
  2. 2. @agatestudio CONTENT Introduction Replication • Replication: Concepts • Replication: How to Sharding • Sharding: Concepts • Sharding: How to
  3. 3. @agatestudio Introduction • Replication increases data availability With multiple copies of data on different database servers, replication protects a database from the loss of a single server • Sharding addresses the challenge of scaling to support large data sets As the size of the data increases, a single machine may not be sufficient to store the data. With Sharding we can distribute data across multiple servers
  4. 4. @agatestudio Replication: Concepts • Replication is the process of synchronizing data across multiple servers • You can use replication to increase read capacity • Provide high availability using automatic failover
  5. 5. Replication: Concepts• Replica set Members – Primary: accepts all write operations from clients – Secondary: maintains a copy of the primary’s data set.
  6. 6. Replication: Concepts• Automatic Failover The loss of a primary triggers an election where one of the secondaries becomes the new primary
  7. 7. @agatestudio Replication: How to 1. Install MongoDB – # yum install mongo-10gen mongo-10gen-server 2. Configure – port = 27017 – bind_ip = 192.168.56.107 – dbpath = /srv/mongodb/ – fork = true – replSet = rs1 3. Start Instances – # mongod --config /etc/mongodb.conf 4. Connect To Instance – $ mongo <host> 5. Initiate and Add Replica set member – rs.initiate() – rs.add("<hostname>:<port>") – rs.conf()
  8. 8. @agatestudio Sharding: Concepts • Sharding is the process of storing data records across multiple machines • Sharding reduces the amount of data that each server needs to store • MongoDB distributes data, or shards, at the collection level • Sharding partitions a collection’s data by the shard key.
  9. 9. @agatestudio Sharding: Concepts • Shard Key – A shard key is either an indexed field or an indexed compound field that exists in every document in the collection – MongoDB divides the shard key values into chunks and distributes the chunks evenly across the shards
  10. 10. Sharding: Concepts • Data Partitioning – Range Based Sharding – Hash Based Sharding
  11. 11. Sharding: Concepts • Components – Router routes the reads and writes from applications to the shards – Config Server holds metadata about the cluster – Shard holds a subset of a collection’s data
  12. 12. Sharding: Concepts • Maintaining a Balanced Data Distribution ChunkMigration Chunk Splitting
  13. 13. @agatestudio Sharding: How to 1. Create Data directory for each Config Server & start instances – mkdir /data/configdb – mongod --configsvr --dbpath <path> --port <port> 2. Start Router (mongos instance) – mongos --configdb <config server hostnames> 3. Connect To Mongos Instance – mongo --host <hostname> --port <port> 4. Add each shard to the cluster – sh.addShard( "mongodb0.example.net:27017" ) 5. Enable Sharding for A Database – sh.enableSharding("<database>") 6. Enable Sharding for Collections – sh.shardCollection("<database>.<collection>", shard-key-pattern)
  14. 14. THANK YOU

×