SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
MongoDB
Replication and Sharding

      Workshop
         by Harun Yardımcı

           @h_yardimci
What we will do today?
 - Following Replicated Shard
What is MongoDB?

●   Document-oriented database

●   in MongoDB you store JSON-like documents
    with dynamic schemas

●   Bridge the gap between key-value stores
    and relational databases
What is MongoDB?
Why MongoDB?

●   Document-oriented

●   High performance

●   High availability

●   Easy scalability

●   Rich query language + MapReduce
Use Cases
                                                   Well Suited
●   Archiving and event logging
●   Document and Content Management Systems
●   ECommerce Often in combination with an RDBMS for the final
    order processing and accounting
●   Gaming Small read/writes are a good fit for MongoDB
●   Mobile Specifically, the server-side infrastructure of mobile
    systems. Geospatial.
●   Operational data store of a web site MongoDB is very good at
    real-time inserts, updates, and queries. Specific web use
    case examples:
    ●   content management
    ●   comment storage, management, voting
    ●   user registration, profile, session data
●   Real-time stats/analytics
What is a Document?


{'id':1, 'category_name' : 'Computer'}
Mongo Data Model

Key:
  'category_name'

Value:
  'Computer'

Field: key-value pair
  'category_name':'Computer'

Document: set of fields
  {'id':1, 'category_name' : 'Computer'}
Mongo Data Model

Collection: set of documents
(say categories)
  {'id':1, 'category_name' : 'Computer'},
  {'id':2, 'category_name' : 'Mobile'},
  ...

Database: set of collections
  categories
  products
  members
Simple Usage and Introduction
First Run

$ mkdir -p /data/db/                  Create a data path
                                     and give permissions
$ chown -R mongod:mongod /data/db/

                                     Start mongod deamon
$ mongod [--dbpath /data/db/] &
$ mongo                               Connect to mongod



> show dbs
> use admin
> show collections
Intro

CRUD Operations

> use testdb
switched to db testdb
> j = { name : "deneme" };
{"name" : "deneme"}
> t = { x : 3 };
{ "x" : 3 }
> db.col.save(j);
> db.col.insert(j); /* see the error message */
> db.col.save(t);
> for (var x = 1; x <= 20; x++) db.col.save({x:x, j:x*x})
>
Intro

> db.col.find();
{ "_id" : ObjectId("4c2209f9f3924d31102bd84a"), "name" : "mongo" }
{ "_id" : ObjectId("4c2209fef3924d31102bd84b"), "x" : 3 }
{ "_id" : ObjectId("4f971ab51c3fde3bc55f286f"), "x" : 1, "j" : 1 }
{ "_id" : ObjectId("4f971ab51c3fde3bc55f2870"), "x" : 2, "j" : 4 }
{ "_id" : ObjectId("4f971ab51c3fde3bc55f2871"), "x" : 3, "j" : 9 }
…
has more
> db.col.remove({"x":"3"});
>
The Big Picture!
Replication

Two Types of Replications
●   Master / Slave Replication
●   ReplicaSet
Master-Slave Rep.

$ mkdir -p /data/db/ms             Different data paths
$ mkdir -p /data/db/sl              for each instances


$ bin/mongod --master [--port <port>]   [--dbpath /data/masterdb/]


$ bin/mongod --slave [--port <port>] --source <masterhostname>[:<port>]
 [--dbpath /data/slavedb/]


…
> db.printReplicationInfo() - on master
> db.printSlaveReplicationInfo() - on slave
> use admin
> db.runCommand({resync: 1})
ReplicaSet - Voting

Consensus Vote
For a node to be elected primary, it must receive a
majority of votes by the following formula
                           (floor(5/2)+1)


Arbiters - {_id: 2, host: 'localhost:27019', arbiterOnly:
true}


Reachable Node – heartbeat

Each replica set is limited to 12 total nodes and 7 voting nodes.
ReplicaSet

Starting The Nodes                         myRSet

                               localhost   localhost   localhost
                                 27017       27018       27019
$ mkdir -p /data/r0             /data/r0    /data/r1    /data/r2

$ mkdir -p /data/r1
$ mkdir -p /data/r2


$ mongod --replSet myRSet --port 27017 --dbpath /data/r0
$ mongod --replSet myRSet --port 27018 --dbpath /data/r1
$ mongod --replSet myRSet --port 27019 --dbpath /data/r2
ReplicaSet

Initiating The Set


> config = {_id: 'myRSet', members: [
                          {_id: 0, host: 'localhost:27017'},
                          {_id: 1, host: 'localhost:27018'},
                          {_id: 2, host: 'localhost:27019'}]
               }
> rs.initiate(config);
{
   "info" : "Config now saved locally. Should come online in about a
minute.",
    "ok" : 1
}
> rs.status();
Sharding

Sharding Components

  ●   Shard Servers

  ●   Config Servers

  ●   mongos Router
Sharding
Sharding

$ mkdir -p /data/db/s1 /data/db/s2 /data/db/config


$ mongod --shardsvr --port 27001 --dbpath /data/db/s1 &
$ mongod --shardsvr --port 27002 --dbpath /data/db/s2 &


$ mongod --configsvr --port 27003 --dbpath /data/db/config &


$ mongos --port 27017 --configdb localhost:27003 &
Sharding

Add Shards to Config
                                  Connect to mongos to add shards


> use admin
> db.runCommand( {addShard : "localhost:27001"} );
{"ok" : 1 , "added" : "localhost:27001"}
> db.runCommand( {addShard : "localhost:27002"} );
{"ok" : 1 , "added" : "localhost:27002"}
Sharding

Enable Sharding

> db.runCommand( { enablesharding: "test_database"} );
{ "ok" : 1 }


> db.runCommand( { shardcollection :
"test_database.myCollection", key : {"_id" :1} })
{ "collectionsharded" : "test_database.myCollection",
"ok" : 1 }
ReplicaSet + Sharding

host1$ mongod --shardsvr --replSet rs_a
host2$ mongod --shardsvr --replSet rs_a          Same replica set name
host3$ mongod --shardsvr --replSet rs_a

> cfg = {
    _id : "rs_a",
    members : [
        {_id : 0, host : "host1:27018", priority : 1},
        {_id : 1, host : "host2:27018", priority : 1},
        {_id : 2, host : "host3:27018", priority : 0}
    ]
}

> rs.initiate(cfg)
ReplicaSet + Sharding

host1$ mongod --configsvr
host2$ mongod --configsvr
host3$ mongod --configsvr

$ mongos --configdb host1:27019,host2:27019,host3:27019
$ mongo

> db.adminCommand( { addShard :
"rs_a/host1:27018,host2:27018,host3:27018" } )
> db.adminCommand( { addShard :
"rs_b/host4:27018,host5:27018,host6:27018" } )
> db.adminCommand( { addShard :
"rs_c/host7:27018,host8:27018,host9:27018" } )
What is Next?

        Please
    Try it Yourself
          and
Share Your Experiences

       Thanks

Más contenido relacionado

La actualidad más candente

MongoDB Database Replication
MongoDB Database ReplicationMongoDB Database Replication
MongoDB Database ReplicationMehdi Valikhani
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)Night Sailer
 
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...MongoDB
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica SetsMongoDB
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica SetsMongoDB
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)Mike Dirolf
 
MongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduceMongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduceTakahiro Inoue
 
MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤Takahiro Inoue
 
Redis for the Everyday Developer
Redis for the Everyday DeveloperRedis for the Everyday Developer
Redis for the Everyday DeveloperRoss Tuck
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineJason Terpko
 
MongoDB全機能解説2
MongoDB全機能解説2MongoDB全機能解説2
MongoDB全機能解説2Takahiro Inoue
 
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHPichikaway
 
Advanced Redis data structures
Advanced Redis data structuresAdvanced Redis data structures
Advanced Redis data structuresamix3k
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsMongoDB
 
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right WayMongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right WayMongoDB
 
MySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of ThingsMySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of ThingsAlexander Rubin
 

La actualidad más candente (20)

MongoDB Database Replication
MongoDB Database ReplicationMongoDB Database Replication
MongoDB Database Replication
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica Sets
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)
 
MongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduceMongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduce
 
MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤
 
Redis for the Everyday Developer
Redis for the Everyday DeveloperRedis for the Everyday Developer
Redis for the Everyday Developer
 
Javantura v2 - Replication with MongoDB - what could go wrong... - Philipp Krenn
Javantura v2 - Replication with MongoDB - what could go wrong... - Philipp KrennJavantura v2 - Replication with MongoDB - what could go wrong... - Philipp Krenn
Javantura v2 - Replication with MongoDB - what could go wrong... - Philipp Krenn
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation Pipeline
 
Latinoware
LatinowareLatinoware
Latinoware
 
MongoDB全機能解説2
MongoDB全機能解説2MongoDB全機能解説2
MongoDB全機能解説2
 
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB Performance
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHP
 
Advanced Redis data structures
Advanced Redis data structuresAdvanced Redis data structures
Advanced Redis data structures
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
 
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right WayMongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
 
Elastic search 검색
Elastic search 검색Elastic search 검색
Elastic search 검색
 
MySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of ThingsMySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of Things
 

Destacado

MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...
MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...
MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...MongoDB
 
รู้สิ่งใดไม่สู้...รู้งี้....
รู้สิ่งใดไม่สู้...รู้งี้....รู้สิ่งใดไม่สู้...รู้งี้....
รู้สิ่งใดไม่สู้...รู้งี้....Supasate Choochaisri
 
Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)MongoSF
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Elyse Kolker Gordon
 
Sharding Methods for MongoDB
Sharding Methods for MongoDBSharding Methods for MongoDB
Sharding Methods for MongoDBMongoDB
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesomeAndrew Hull
 
React Nativeはクロスプラットフォームモバイルアプリ開発の夢を見るか #DroidKaigi
React Nativeはクロスプラットフォームモバイルアプリ開発の夢を見るか #DroidKaigiReact Nativeはクロスプラットフォームモバイルアプリ開発の夢を見るか #DroidKaigi
React Nativeはクロスプラットフォームモバイルアプリ開発の夢を見るか #DroidKaigiYukiya Nakagawa
 

Destacado (8)

MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...
MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...
MongoDB San Francisco 2013: Basic Sharding in MongoDB presented by Brandon Bl...
 
MongoDB Shard Cluster
MongoDB Shard ClusterMongoDB Shard Cluster
MongoDB Shard Cluster
 
รู้สิ่งใดไม่สู้...รู้งี้....
รู้สิ่งใดไม่สู้...รู้งี้....รู้สิ่งใดไม่สู้...รู้งี้....
รู้สิ่งใดไม่สู้...รู้งี้....
 
Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017
 
Sharding Methods for MongoDB
Sharding Methods for MongoDBSharding Methods for MongoDB
Sharding Methods for MongoDB
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesome
 
React Nativeはクロスプラットフォームモバイルアプリ開発の夢を見るか #DroidKaigi
React Nativeはクロスプラットフォームモバイルアプリ開発の夢を見るか #DroidKaigiReact Nativeはクロスプラットフォームモバイルアプリ開発の夢を見るか #DroidKaigi
React Nativeはクロスプラットフォームモバイルアプリ開発の夢を見るか #DroidKaigi
 

Similar a Mongodb workshop

Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo dbAmit Thakkar
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introductionTse-Ching Ho
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsMongoDB
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsMongoDB
 
MongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: ShardingMongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: ShardingMongoDB
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppSmartLogic
 
Introduction to cloudforecast
Introduction to cloudforecastIntroduction to cloudforecast
Introduction to cloudforecastMasahiro Nagano
 
NoSQL Infrastructure - Late 2013
NoSQL Infrastructure - Late 2013NoSQL Infrastructure - Late 2013
NoSQL Infrastructure - Late 2013Server Density
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Cosimo Streppone
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsServer Density
 
OSDC 2012 | Scaling with MongoDB by Ross Lawley
OSDC 2012 | Scaling with MongoDB by Ross LawleyOSDC 2012 | Scaling with MongoDB by Ross Lawley
OSDC 2012 | Scaling with MongoDB by Ross LawleyNETWAYS
 
Introduction to MongoDB with PHP
Introduction to MongoDB with PHPIntroduction to MongoDB with PHP
Introduction to MongoDB with PHPfwso
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newYiwei Ma
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeWim Godden
 

Similar a Mongodb workshop (20)

Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo db
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
 
MongoDB and DynamoDB
MongoDB and DynamoDBMongoDB and DynamoDB
MongoDB and DynamoDB
 
Mongo db roma replication and sharding
Mongo db roma replication and shardingMongo db roma replication and sharding
Mongo db roma replication and sharding
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.js
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.js
 
NoSQL Infrastructure
NoSQL InfrastructureNoSQL Infrastructure
NoSQL Infrastructure
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
 
MongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: ShardingMongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: Sharding
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 
Introduction to cloudforecast
Introduction to cloudforecastIntroduction to cloudforecast
Introduction to cloudforecast
 
NoSQL Infrastructure - Late 2013
NoSQL Infrastructure - Late 2013NoSQL Infrastructure - Late 2013
NoSQL Infrastructure - Late 2013
 
Rails with mongodb
Rails with mongodbRails with mongodb
Rails with mongodb
 
R-House (LSRC)
R-House (LSRC)R-House (LSRC)
R-House (LSRC)
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & Analytics
 
OSDC 2012 | Scaling with MongoDB by Ross Lawley
OSDC 2012 | Scaling with MongoDB by Ross LawleyOSDC 2012 | Scaling with MongoDB by Ross Lawley
OSDC 2012 | Scaling with MongoDB by Ross Lawley
 
Introduction to MongoDB with PHP
Introduction to MongoDB with PHPIntroduction to MongoDB with PHP
Introduction to MongoDB with PHP
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the code
 

Más de Harun Yardımcı

Webrazzi Online: Code - GittiGidiyor’a Teknik Bakış 2016
Webrazzi Online: Code - GittiGidiyor’a Teknik Bakış 2016Webrazzi Online: Code - GittiGidiyor’a Teknik Bakış 2016
Webrazzi Online: Code - GittiGidiyor’a Teknik Bakış 2016Harun Yardımcı
 
"It Works On My Machine" Problem
"It Works On My Machine" Problem"It Works On My Machine" Problem
"It Works On My Machine" ProblemHarun Yardımcı
 
What you don't learn in the school
What you don't learn in the schoolWhat you don't learn in the school
What you don't learn in the schoolHarun Yardımcı
 
Scalability at Gittigidiyor
Scalability at GittigidiyorScalability at Gittigidiyor
Scalability at GittigidiyorHarun Yardımcı
 
Software Development Whats & Whys
Software Development Whats & Whys Software Development Whats & Whys
Software Development Whats & Whys Harun Yardımcı
 
Gittigidiyor.com'da Acik Kaynak Uygulamalar
Gittigidiyor.com'da Acik Kaynak UygulamalarGittigidiyor.com'da Acik Kaynak Uygulamalar
Gittigidiyor.com'da Acik Kaynak UygulamalarHarun Yardımcı
 

Más de Harun Yardımcı (10)

Webrazzi Online: Code - GittiGidiyor’a Teknik Bakış 2016
Webrazzi Online: Code - GittiGidiyor’a Teknik Bakış 2016Webrazzi Online: Code - GittiGidiyor’a Teknik Bakış 2016
Webrazzi Online: Code - GittiGidiyor’a Teknik Bakış 2016
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
"It Works On My Machine" Problem
"It Works On My Machine" Problem"It Works On My Machine" Problem
"It Works On My Machine" Problem
 
What you don't learn in the school
What you don't learn in the schoolWhat you don't learn in the school
What you don't learn in the school
 
CFEX 2014 - DAU
CFEX 2014 - DAUCFEX 2014 - DAU
CFEX 2014 - DAU
 
Scalability at Gittigidiyor
Scalability at GittigidiyorScalability at Gittigidiyor
Scalability at Gittigidiyor
 
Software Development Whats & Whys
Software Development Whats & Whys Software Development Whats & Whys
Software Development Whats & Whys
 
Introduction to Mongodb
Introduction to MongodbIntroduction to Mongodb
Introduction to Mongodb
 
Gittigidiyor.com'da Acik Kaynak Uygulamalar
Gittigidiyor.com'da Acik Kaynak UygulamalarGittigidiyor.com'da Acik Kaynak Uygulamalar
Gittigidiyor.com'da Acik Kaynak Uygulamalar
 
Git Branching Model
Git Branching ModelGit Branching Model
Git Branching Model
 

Último

Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 

Último (20)

Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 

Mongodb workshop

  • 1. MongoDB Replication and Sharding Workshop by Harun Yardımcı @h_yardimci
  • 2. What we will do today? - Following Replicated Shard
  • 3. What is MongoDB? ● Document-oriented database ● in MongoDB you store JSON-like documents with dynamic schemas ● Bridge the gap between key-value stores and relational databases
  • 5. Why MongoDB? ● Document-oriented ● High performance ● High availability ● Easy scalability ● Rich query language + MapReduce
  • 6. Use Cases Well Suited ● Archiving and event logging ● Document and Content Management Systems ● ECommerce Often in combination with an RDBMS for the final order processing and accounting ● Gaming Small read/writes are a good fit for MongoDB ● Mobile Specifically, the server-side infrastructure of mobile systems. Geospatial. ● Operational data store of a web site MongoDB is very good at real-time inserts, updates, and queries. Specific web use case examples: ● content management ● comment storage, management, voting ● user registration, profile, session data ● Real-time stats/analytics
  • 7. What is a Document? {'id':1, 'category_name' : 'Computer'}
  • 8. Mongo Data Model Key: 'category_name' Value: 'Computer' Field: key-value pair 'category_name':'Computer' Document: set of fields {'id':1, 'category_name' : 'Computer'}
  • 9. Mongo Data Model Collection: set of documents (say categories) {'id':1, 'category_name' : 'Computer'}, {'id':2, 'category_name' : 'Mobile'}, ... Database: set of collections categories products members
  • 10. Simple Usage and Introduction
  • 11. First Run $ mkdir -p /data/db/ Create a data path and give permissions $ chown -R mongod:mongod /data/db/ Start mongod deamon $ mongod [--dbpath /data/db/] & $ mongo Connect to mongod > show dbs > use admin > show collections
  • 12. Intro CRUD Operations > use testdb switched to db testdb > j = { name : "deneme" }; {"name" : "deneme"} > t = { x : 3 }; { "x" : 3 } > db.col.save(j); > db.col.insert(j); /* see the error message */ > db.col.save(t); > for (var x = 1; x <= 20; x++) db.col.save({x:x, j:x*x}) >
  • 13. Intro > db.col.find(); { "_id" : ObjectId("4c2209f9f3924d31102bd84a"), "name" : "mongo" } { "_id" : ObjectId("4c2209fef3924d31102bd84b"), "x" : 3 } { "_id" : ObjectId("4f971ab51c3fde3bc55f286f"), "x" : 1, "j" : 1 } { "_id" : ObjectId("4f971ab51c3fde3bc55f2870"), "x" : 2, "j" : 4 } { "_id" : ObjectId("4f971ab51c3fde3bc55f2871"), "x" : 3, "j" : 9 } … has more > db.col.remove({"x":"3"}); >
  • 15. Replication Two Types of Replications ● Master / Slave Replication ● ReplicaSet
  • 16. Master-Slave Rep. $ mkdir -p /data/db/ms Different data paths $ mkdir -p /data/db/sl for each instances $ bin/mongod --master [--port <port>] [--dbpath /data/masterdb/] $ bin/mongod --slave [--port <port>] --source <masterhostname>[:<port>] [--dbpath /data/slavedb/] … > db.printReplicationInfo() - on master > db.printSlaveReplicationInfo() - on slave > use admin > db.runCommand({resync: 1})
  • 17. ReplicaSet - Voting Consensus Vote For a node to be elected primary, it must receive a majority of votes by the following formula (floor(5/2)+1) Arbiters - {_id: 2, host: 'localhost:27019', arbiterOnly: true} Reachable Node – heartbeat Each replica set is limited to 12 total nodes and 7 voting nodes.
  • 18. ReplicaSet Starting The Nodes myRSet localhost localhost localhost 27017 27018 27019 $ mkdir -p /data/r0 /data/r0 /data/r1 /data/r2 $ mkdir -p /data/r1 $ mkdir -p /data/r2 $ mongod --replSet myRSet --port 27017 --dbpath /data/r0 $ mongod --replSet myRSet --port 27018 --dbpath /data/r1 $ mongod --replSet myRSet --port 27019 --dbpath /data/r2
  • 19. ReplicaSet Initiating The Set > config = {_id: 'myRSet', members: [ {_id: 0, host: 'localhost:27017'}, {_id: 1, host: 'localhost:27018'}, {_id: 2, host: 'localhost:27019'}] } > rs.initiate(config); { "info" : "Config now saved locally. Should come online in about a minute.", "ok" : 1 } > rs.status();
  • 20. Sharding Sharding Components ● Shard Servers ● Config Servers ● mongos Router
  • 22. Sharding $ mkdir -p /data/db/s1 /data/db/s2 /data/db/config $ mongod --shardsvr --port 27001 --dbpath /data/db/s1 & $ mongod --shardsvr --port 27002 --dbpath /data/db/s2 & $ mongod --configsvr --port 27003 --dbpath /data/db/config & $ mongos --port 27017 --configdb localhost:27003 &
  • 23. Sharding Add Shards to Config Connect to mongos to add shards > use admin > db.runCommand( {addShard : "localhost:27001"} ); {"ok" : 1 , "added" : "localhost:27001"} > db.runCommand( {addShard : "localhost:27002"} ); {"ok" : 1 , "added" : "localhost:27002"}
  • 24. Sharding Enable Sharding > db.runCommand( { enablesharding: "test_database"} ); { "ok" : 1 } > db.runCommand( { shardcollection : "test_database.myCollection", key : {"_id" :1} }) { "collectionsharded" : "test_database.myCollection", "ok" : 1 }
  • 25. ReplicaSet + Sharding host1$ mongod --shardsvr --replSet rs_a host2$ mongod --shardsvr --replSet rs_a Same replica set name host3$ mongod --shardsvr --replSet rs_a > cfg = { _id : "rs_a", members : [ {_id : 0, host : "host1:27018", priority : 1}, {_id : 1, host : "host2:27018", priority : 1}, {_id : 2, host : "host3:27018", priority : 0} ] } > rs.initiate(cfg)
  • 26. ReplicaSet + Sharding host1$ mongod --configsvr host2$ mongod --configsvr host3$ mongod --configsvr $ mongos --configdb host1:27019,host2:27019,host3:27019 $ mongo > db.adminCommand( { addShard : "rs_a/host1:27018,host2:27018,host3:27018" } ) > db.adminCommand( { addShard : "rs_b/host4:27018,host5:27018,host6:27018" } ) > db.adminCommand( { addShard : "rs_c/host7:27018,host8:27018,host9:27018" } )
  • 27. What is Next? Please Try it Yourself and Share Your Experiences Thanks