SlideShare a Scribd company logo
Getting Started with Replica Set
Why Replication?
• How many have faced node failures?
• How many have been woken up from sleep to do
• a fail-over(s)?
• How many have experienced issues due to
network latency?
• Different uses for data
Normal processing
Simple analytics
Replicas Lifecycle
Replica Set – Initialize
Replica Set – Failure
Replica Set – Failover
Replica Set – Recovery
Replica Set – Recovered
Replication
Communication Test
Step 1. Start all instants
Step 2. All members of a replica set must be able to connect to every other
member of the set to support replication.
E.g. given replica set with three members running on three different
machines
host1 : 27017
host2 : 27017
host3 : 27017
Check from host1
./mongo --host host2IP - - port
./mongo --host host3IP - - port
Similar way one by one check from host2 and host3.
Step 3. Start all mongod instance by issuing following command
mongod –host 10.1.1.61 --port 27017 --replSet rs0
mongod –host 10.1.1.62 --port 27017 --replSet rs0
mongod –host 10.1.1.63 --port 27017 --replSet rs0
Here rs0 is name of replicaSet name.
Step 4. open mongo shell and connect to the first mongod instance
./mongo 10.1.1.61 –port 27017
Step 5. Use rs.initiate() to initiate a replica set consisting of the
current member and using the default configuration:
rs.initiate()
Step 6. Display the current replica configuration
rs.conf()
Step 7. Add two members to the replica set by issuing a sequence of
commands similar to the following.
rs.add(“10.1.1.62:27017")
rs.add(“10.1.1.63:27017")
Step 8. Check the status of your replica set at any time with the rs.status()
operation.
Step 9. Using Configuration file
create mongodb.conf file by issuing following commands
vi /etc.mongodb.conf with following details
port = 27017
bind_ip = 10.1.1.61
dbpath = /data/db
fork = true ( not working in windows)
replSet = rs0
Step 10. Start mongod by following operation
./mongod --config /etc/mongodb.config
Add Members to a Replica Set
Requirements
1. An active replica set.
2. A new MongoDB system capable of supporting your dataset, accessible
by the active replica set through the network.
3. Deploy MongoDB new instance, specifying name of replica set.
4. Open mongo shell and connect to replica set’s primary. If you don’t know
which member is primary, then issue following commands in mongo
shell,
db.isMaster()
5. In the mongo shell, issue the following command to add the new member
to the replica set.
rs.add(“10.1.1.61:27017")
6. Confirm new member is instance of replica set’s.
Replica set Maintenance
and Administration
1. No downtime
2. Rolling Upgrade maintenance
Start with secondary
Primary Last
Sharding
Shard: A single replica set that stores some portion of total sharded cluster
data set.
Shard Key : In the sharded collection, shard key is the field that MongoDB
uses to distribute the document among the member of sharded
clusters.
Feature of sharding
1. Range-base Data Partitioning
MongoDB distribute document among shards base on the shard key.
Each chunk is block of document with value that fall within specific
range.
2. Automatic Data Volume Distribution
sharding system automatic balance data across cluster without in
intervention from application layer. Effective automatic sharding depend
on well chosen sharding key.
3. Transparent Query Routing
Sharding is completely transparent to the application layer, because
all connection goes through mongos.
4. Horizontal Capacity
A typical sharded cluster consist of,
• 3 config server that store metadata. Metadata map chunks to shard.
• More than one replica set or mongod instances. These are the shard.
• A number of lightweight process, called mongos.
Sharding
When to use sharding
1. your data set approaches or exceeds the storage capacity of a single node
in your system.
2. The size of your system’s active working set will soon exceed the capacity
of the maximum amount of RAM for your system.
3. your system has a large amount of write activity, a single MongoDB
instance cannot write data fast enough to meet demand, and all other
approaches have not reduced contention.
if these attribute are not in your system, sharding will add additional
complexity to your system without providing much benefits.
Sharding Requirements
1. Three config sever.
For development and testing purposes you may deploy a cluster with a
single configuration server process, but always use exactly three config
servers for redundancy and safety in production.
2. Two or more shard
each shard consist of one or more mongod. Typically each shard is a
replica sets.
3. One or more mongos instance.
4. Shard key
“Shard keys” refer to the field that exists in every document in a collection
that MongoDB uses to distribute documents among the shards.
Setting Up Sharding
Step 1. Starting the Servers
create a config server database directory by issuing following
command,
$mkdir –p /configsvr/config
The config server needs to be started first, because mongos uses it
to get its configuration.
$./mongod - -dbpath /configsvr/config - - port 10000
Step 2. Starting mongos servers
Routing servers don’t even need a data directory, but they need to
know where the config server is:
$./mongos --port 20000 --configdb localhost:10000
Shard administration is always done through a mongos.
Step 3. Adding shard
A shard is just MongoDB instance (or replica set).
Start three MongoDB instances using following operations,
$./mongod –dbpath /data/sard1 - - port 10001
$./mongod –dbpath /data/sard2 - - port 10002
$./mongod –dbpath /data/sard3 - - port 10003
Now connect monos process using mongo by issuing following commands
$ ./mongo localhost:20000/admin
Make sure that you are connected to mongos not to mongod.
Now you can add shard by following commands,
>db.runCommands ( { addShard : “localhost:10001”, allowLocal : true } )
Out put > {
"added" : "localhost:10000",
"ok" : true
}
The "allowLocal" key is necessary only if you are running the shard
on localhost.
Step 4. similar way add remain shards
Sharding Data
1. MongoDB won’t just distribute every piece of data you’ve ever stored:
you have to explicitly turn sharding on at both the database and
collection levels.
Create database “shardDB”, first we enable sharding for database blog
> db.runCommands ( { “enablesharding” : “shardDB” } )
2. Once you’ve enabled sharding on the database level, you can shard a
collection by running the shardcollection command:
> db.runCommands ( { “shardcollection” : “shardDB.blog” ,
“key” : { “_id” : 1} } )
3. User define sharding key
you must create index on sharding key if it is not a “_id” field.
Many Mongos
You can also run as many mongos processes as you want. One
recommended setup is to run a mongos process for every application
server. That way, each application server can talk mongos locally. If server
goes down, no will be trying to talk with mongos.
A Sturdy Shard
In production, production each shard should be a replica set. That way
individual server can fail without bringing whole shard. To add replica set
as a shard, pass its name and a seed to the addshard command.
> db.runCommand ( { "addshard" : "foo/10.1.1.61:27017“ } )
Sharding Administration
1. Sharding information mostly stored on config server, which can be
accessed by any mongos process.
2. Connect to mongos process to access config database. Switch to config
DB issue following commands,
> db.getCollectionNames()
it shows all collection name.
You can find list of shards in shards collection
> db.shards.find()
each shard assigning unique human readable id.
3. Databases
The databases collection contain a list of databases that exist on shards
and information about that.
>db.databases.find()
> db.databases.find()
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "foo", "partitioned" : false, "primary" : "shard1" }
{ "_id" : "x", "partitioned" : false, "primary" : "shard0" }
{
"_id" : "test",
"partitioned" : true,
"primary" : "shard0",
"sharded" : {
"test.foo" : {
"key" : {“id" : 1},
"unique" : false
}
}
}
4. Chunks
chunks information stored in chunks collection. You can actually see how your data
has been divided up across the cluster.
> db.chunks.find()
{
"_id" : "test.foo-x_MinKey",
"lastmod" : { "t" : 1276636243000, "i" : 1 },
"ns" : "test.foo",
"min" : {
"x" : { $minKey : 1 }
},
"max" : {
"x" : { $maxKey : 1 }
}
"shard" : "shard0"
}
Sharding Commands
1. The printing sharding status give a quick summary of sharded collection.
>db.printShardingStatus()
2. Removing a shard
Shards can be removed from a cluster with the removeshard command.
Removeshard drains all of the chunks on a given shard to the other shards.
>db.runCommand({"removeshard" : "localhost:10000"});
As the shard is drained, removeshard will give you the status of how much
remains on the shard.
>db.runCommand({"removeshard" : "localhost:10000"});
when the shard has finished draining, removeshard shows that the shard
has been successfully removed.
Ad

More Related Content

What's hot (20)

My sql fabric ha and sharding solutions
My sql fabric ha and sharding solutionsMy sql fabric ha and sharding solutions
My sql fabric ha and sharding solutions
Louis liu
 
Percona Live 2017 ­- Sharded cluster tutorial
Percona Live 2017 ­- Sharded cluster tutorialPercona Live 2017 ­- Sharded cluster tutorial
Percona Live 2017 ­- Sharded cluster tutorial
Antonios Giannopoulos
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in action
Sveta Smirnova
 
MySQL replication & cluster
MySQL replication & clusterMySQL replication & cluster
MySQL replication & cluster
elliando dias
 
MySQL async message subscription platform
MySQL async message subscription platformMySQL async message subscription platform
MySQL async message subscription platform
Louis liu
 
Cassandra for Python Developers
Cassandra for Python DevelopersCassandra for Python Developers
Cassandra for Python Developers
Tyler Hobbs
 
My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestrator
YoungHeon (Roy) Kim
 
MongoDB – Sharded cluster tutorial - Percona Europe 2017
MongoDB – Sharded cluster tutorial - Percona Europe 2017MongoDB – Sharded cluster tutorial - Percona Europe 2017
MongoDB – Sharded cluster tutorial - Percona Europe 2017
Antonios Giannopoulos
 
MongoDB Replication (Dwight Merriman)
MongoDB Replication (Dwight Merriman)MongoDB Replication (Dwight Merriman)
MongoDB Replication (Dwight Merriman)
MongoSF
 
Being closer to Cassandra by Oleg Anastasyev. Talk at Cassandra Summit EU 2013
Being closer to Cassandra by Oleg Anastasyev. Talk at Cassandra Summit EU 2013Being closer to Cassandra by Oleg Anastasyev. Talk at Cassandra Summit EU 2013
Being closer to Cassandra by Oleg Anastasyev. Talk at Cassandra Summit EU 2013
odnoklassniki.ru
 
Recent my sql_performance Test detail
Recent my sql_performance Test detailRecent my sql_performance Test detail
Recent my sql_performance Test detail
Louis liu
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
Wim Godden
 
WiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-TreeWiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-Tree
Sveta Smirnova
 
Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018 Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018
Antonios Giannopoulos
 
MySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELKMySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELK
I Goo Lee
 
HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)
akirahiguchi
 
MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016
Dave Stokes
 
MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016
Dave Stokes
 
MySQL Audit using Percona audit plugin and ELK
MySQL Audit using Percona audit plugin and ELKMySQL Audit using Percona audit plugin and ELK
MySQL Audit using Percona audit plugin and ELK
I Goo Lee
 
Mysql all
Mysql allMysql all
Mysql all
Prof. Wim Van Criekinge
 
My sql fabric ha and sharding solutions
My sql fabric ha and sharding solutionsMy sql fabric ha and sharding solutions
My sql fabric ha and sharding solutions
Louis liu
 
Percona Live 2017 ­- Sharded cluster tutorial
Percona Live 2017 ­- Sharded cluster tutorialPercona Live 2017 ­- Sharded cluster tutorial
Percona Live 2017 ­- Sharded cluster tutorial
Antonios Giannopoulos
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in action
Sveta Smirnova
 
MySQL replication & cluster
MySQL replication & clusterMySQL replication & cluster
MySQL replication & cluster
elliando dias
 
MySQL async message subscription platform
MySQL async message subscription platformMySQL async message subscription platform
MySQL async message subscription platform
Louis liu
 
Cassandra for Python Developers
Cassandra for Python DevelopersCassandra for Python Developers
Cassandra for Python Developers
Tyler Hobbs
 
My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestrator
YoungHeon (Roy) Kim
 
MongoDB – Sharded cluster tutorial - Percona Europe 2017
MongoDB – Sharded cluster tutorial - Percona Europe 2017MongoDB – Sharded cluster tutorial - Percona Europe 2017
MongoDB – Sharded cluster tutorial - Percona Europe 2017
Antonios Giannopoulos
 
MongoDB Replication (Dwight Merriman)
MongoDB Replication (Dwight Merriman)MongoDB Replication (Dwight Merriman)
MongoDB Replication (Dwight Merriman)
MongoSF
 
Being closer to Cassandra by Oleg Anastasyev. Talk at Cassandra Summit EU 2013
Being closer to Cassandra by Oleg Anastasyev. Talk at Cassandra Summit EU 2013Being closer to Cassandra by Oleg Anastasyev. Talk at Cassandra Summit EU 2013
Being closer to Cassandra by Oleg Anastasyev. Talk at Cassandra Summit EU 2013
odnoklassniki.ru
 
Recent my sql_performance Test detail
Recent my sql_performance Test detailRecent my sql_performance Test detail
Recent my sql_performance Test detail
Louis liu
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
Wim Godden
 
WiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-TreeWiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-Tree
Sveta Smirnova
 
Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018 Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018
Antonios Giannopoulos
 
MySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELKMySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELK
I Goo Lee
 
HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)
akirahiguchi
 
MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016
Dave Stokes
 
MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016
Dave Stokes
 
MySQL Audit using Percona audit plugin and ELK
MySQL Audit using Percona audit plugin and ELKMySQL Audit using Percona audit plugin and ELK
MySQL Audit using Percona audit plugin and ELK
I Goo Lee
 

Viewers also liked (13)

Spring Data MongoDB Webiner
Spring Data MongoDB WebinerSpring Data MongoDB Webiner
Spring Data MongoDB Webiner
Hakan Özler
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
MongoDB
 
Setting up mongo replica set
Setting up mongo replica setSetting up mongo replica set
Setting up mongo replica set
Sudheer Kondla
 
MongoDB Replica Sets
MongoDB Replica SetsMongoDB Replica Sets
MongoDB Replica Sets
MongoDB
 
Back to Basics: Build Something Big With MongoDB
Back to Basics: Build Something Big With MongoDB Back to Basics: Build Something Big With MongoDB
Back to Basics: Build Something Big With MongoDB
MongoDB
 
A complete hadoop stack
A complete hadoop stackA complete hadoop stack
A complete hadoop stack
Abhra Pal
 
MongoDb scalability and high availability with Replica-Set
MongoDb scalability and high availability with Replica-SetMongoDb scalability and high availability with Replica-Set
MongoDb scalability and high availability with Replica-Set
Vivek Parihar
 
Mongodb sharding
Mongodb shardingMongodb sharding
Mongodb sharding
xiangrong
 
Configuring MongoDB HA Replica Set on AWS EC2
Configuring MongoDB HA Replica Set on AWS EC2Configuring MongoDB HA Replica Set on AWS EC2
Configuring MongoDB HA Replica Set on AWS EC2
ShepHertz
 
MongoDB Administration 101
MongoDB Administration 101MongoDB Administration 101
MongoDB Administration 101
MongoDB
 
High Availabiltity & Replica Sets with mongoDB
High Availabiltity & Replica Sets with mongoDBHigh Availabiltity & Replica Sets with mongoDB
High Availabiltity & Replica Sets with mongoDB
Gareth Davies
 
Mongo DB
Mongo DBMongo DB
Mongo DB
Karan Kukreja
 
Back to Basics Webinar 3: Introduction to Replica Sets
Back to Basics Webinar 3: Introduction to Replica SetsBack to Basics Webinar 3: Introduction to Replica Sets
Back to Basics Webinar 3: Introduction to Replica Sets
MongoDB
 
Spring Data MongoDB Webiner
Spring Data MongoDB WebinerSpring Data MongoDB Webiner
Spring Data MongoDB Webiner
Hakan Özler
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
MongoDB
 
Setting up mongo replica set
Setting up mongo replica setSetting up mongo replica set
Setting up mongo replica set
Sudheer Kondla
 
MongoDB Replica Sets
MongoDB Replica SetsMongoDB Replica Sets
MongoDB Replica Sets
MongoDB
 
Back to Basics: Build Something Big With MongoDB
Back to Basics: Build Something Big With MongoDB Back to Basics: Build Something Big With MongoDB
Back to Basics: Build Something Big With MongoDB
MongoDB
 
A complete hadoop stack
A complete hadoop stackA complete hadoop stack
A complete hadoop stack
Abhra Pal
 
MongoDb scalability and high availability with Replica-Set
MongoDb scalability and high availability with Replica-SetMongoDb scalability and high availability with Replica-Set
MongoDb scalability and high availability with Replica-Set
Vivek Parihar
 
Mongodb sharding
Mongodb shardingMongodb sharding
Mongodb sharding
xiangrong
 
Configuring MongoDB HA Replica Set on AWS EC2
Configuring MongoDB HA Replica Set on AWS EC2Configuring MongoDB HA Replica Set on AWS EC2
Configuring MongoDB HA Replica Set on AWS EC2
ShepHertz
 
MongoDB Administration 101
MongoDB Administration 101MongoDB Administration 101
MongoDB Administration 101
MongoDB
 
High Availabiltity & Replica Sets with mongoDB
High Availabiltity & Replica Sets with mongoDBHigh Availabiltity & Replica Sets with mongoDB
High Availabiltity & Replica Sets with mongoDB
Gareth Davies
 
Back to Basics Webinar 3: Introduction to Replica Sets
Back to Basics Webinar 3: Introduction to Replica SetsBack to Basics Webinar 3: Introduction to Replica Sets
Back to Basics Webinar 3: Introduction to Replica Sets
MongoDB
 
Ad

Similar to Getting started with replica set in MongoDB (20)

Setting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutesSetting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutes
Sudheer Kondla
 
MongoDB Replication and Sharding
MongoDB Replication and ShardingMongoDB Replication and Sharding
MongoDB Replication and Sharding
Tharun Srinivasa
 
Mongodb replication
Mongodb replicationMongodb replication
Mongodb replication
PoguttuezhiniVP
 
Sharded cluster tutorial
Sharded cluster tutorialSharded cluster tutorial
Sharded cluster tutorial
Antonios Giannopoulos
 
MongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster TutorialMongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster Tutorial
Jason Terpko
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & Introduction
Jerwin Roy
 
Armitage – The Ultimate Attack Platform for Metasploit
Armitage – The  Ultimate Attack  Platform for Metasploit Armitage – The  Ultimate Attack  Platform for Metasploit
Armitage – The Ultimate Attack Platform for Metasploit
Ishan Girdhar
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
Enoch Joshua
 
2014 05-07-fr - add dev series - session 6 - deploying your application-2
2014 05-07-fr - add dev series - session 6 - deploying your application-22014 05-07-fr - add dev series - session 6 - deploying your application-2
2014 05-07-fr - add dev series - session 6 - deploying your application-2
MongoDB
 
Building Apache Cassandra clusters for massive scale
Building Apache Cassandra clusters for massive scaleBuilding Apache Cassandra clusters for massive scale
Building Apache Cassandra clusters for massive scale
Alex Thompson
 
The Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterThe Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb Cluster
Chris Henry
 
Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo db
Amit Thakkar
 
Elastic101tutorial Percona Live Europe 2018
Elastic101tutorial Percona Live Europe 2018Elastic101tutorial Percona Live Europe 2018
Elastic101tutorial Percona Live Europe 2018
Alex Cercel
 
Performance Tuning
Performance TuningPerformance Tuning
Performance Tuning
Ligaya Turmelle
 
MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017
Dave Stokes
 
MongoDB Backup & Disaster Recovery
MongoDB Backup & Disaster RecoveryMongoDB Backup & Disaster Recovery
MongoDB Backup & Disaster Recovery
Elankumaran Srinivasan
 
Attacking Oracle with the Metasploit Framework
Attacking Oracle with the Metasploit FrameworkAttacking Oracle with the Metasploit Framework
Attacking Oracle with the Metasploit Framework
Chris Gates
 
linux installation.pdf
linux installation.pdflinux installation.pdf
linux installation.pdf
MuhammadShoaibHussai2
 
Dbdeployer, the universal installer
Dbdeployer, the universal installerDbdeployer, the universal installer
Dbdeployer, the universal installer
Giuseppe Maxia
 
MariaDB10.7_install_Ubuntu.docx
MariaDB10.7_install_Ubuntu.docxMariaDB10.7_install_Ubuntu.docx
MariaDB10.7_install_Ubuntu.docx
NeoClova
 
Setting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutesSetting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutes
Sudheer Kondla
 
MongoDB Replication and Sharding
MongoDB Replication and ShardingMongoDB Replication and Sharding
MongoDB Replication and Sharding
Tharun Srinivasa
 
MongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster TutorialMongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster Tutorial
Jason Terpko
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & Introduction
Jerwin Roy
 
Armitage – The Ultimate Attack Platform for Metasploit
Armitage – The  Ultimate Attack  Platform for Metasploit Armitage – The  Ultimate Attack  Platform for Metasploit
Armitage – The Ultimate Attack Platform for Metasploit
Ishan Girdhar
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
Enoch Joshua
 
2014 05-07-fr - add dev series - session 6 - deploying your application-2
2014 05-07-fr - add dev series - session 6 - deploying your application-22014 05-07-fr - add dev series - session 6 - deploying your application-2
2014 05-07-fr - add dev series - session 6 - deploying your application-2
MongoDB
 
Building Apache Cassandra clusters for massive scale
Building Apache Cassandra clusters for massive scaleBuilding Apache Cassandra clusters for massive scale
Building Apache Cassandra clusters for massive scale
Alex Thompson
 
The Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterThe Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb Cluster
Chris Henry
 
Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo db
Amit Thakkar
 
Elastic101tutorial Percona Live Europe 2018
Elastic101tutorial Percona Live Europe 2018Elastic101tutorial Percona Live Europe 2018
Elastic101tutorial Percona Live Europe 2018
Alex Cercel
 
MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017
Dave Stokes
 
Attacking Oracle with the Metasploit Framework
Attacking Oracle with the Metasploit FrameworkAttacking Oracle with the Metasploit Framework
Attacking Oracle with the Metasploit Framework
Chris Gates
 
Dbdeployer, the universal installer
Dbdeployer, the universal installerDbdeployer, the universal installer
Dbdeployer, the universal installer
Giuseppe Maxia
 
MariaDB10.7_install_Ubuntu.docx
MariaDB10.7_install_Ubuntu.docxMariaDB10.7_install_Ubuntu.docx
MariaDB10.7_install_Ubuntu.docx
NeoClova
 
Ad

More from Kishor Parkhe (6)

Big data and hadoop
Big data and hadoopBig data and hadoop
Big data and hadoop
Kishor Parkhe
 
Redis
RedisRedis
Redis
Kishor Parkhe
 
Aggregation in MongoDB
Aggregation in MongoDBAggregation in MongoDB
Aggregation in MongoDB
Kishor Parkhe
 
Indexing In MongoDB
Indexing In MongoDBIndexing In MongoDB
Indexing In MongoDB
Kishor Parkhe
 
Mongo db basic installation
Mongo db basic installationMongo db basic installation
Mongo db basic installation
Kishor Parkhe
 
C aptitude 1st jan 2012
C aptitude 1st jan 2012C aptitude 1st jan 2012
C aptitude 1st jan 2012
Kishor Parkhe
 

Recently uploaded (20)

The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 

Getting started with replica set in MongoDB

  • 1. Getting Started with Replica Set
  • 2. Why Replication? • How many have faced node failures? • How many have been woken up from sleep to do • a fail-over(s)? • How many have experienced issues due to network latency? • Different uses for data Normal processing Simple analytics
  • 4. Replica Set – Initialize
  • 5. Replica Set – Failure
  • 6. Replica Set – Failover
  • 7. Replica Set – Recovery
  • 8. Replica Set – Recovered
  • 10. Communication Test Step 1. Start all instants Step 2. All members of a replica set must be able to connect to every other member of the set to support replication. E.g. given replica set with three members running on three different machines host1 : 27017 host2 : 27017 host3 : 27017 Check from host1 ./mongo --host host2IP - - port ./mongo --host host3IP - - port Similar way one by one check from host2 and host3.
  • 11. Step 3. Start all mongod instance by issuing following command mongod –host 10.1.1.61 --port 27017 --replSet rs0 mongod –host 10.1.1.62 --port 27017 --replSet rs0 mongod –host 10.1.1.63 --port 27017 --replSet rs0 Here rs0 is name of replicaSet name. Step 4. open mongo shell and connect to the first mongod instance ./mongo 10.1.1.61 –port 27017 Step 5. Use rs.initiate() to initiate a replica set consisting of the current member and using the default configuration: rs.initiate() Step 6. Display the current replica configuration rs.conf() Step 7. Add two members to the replica set by issuing a sequence of commands similar to the following. rs.add(“10.1.1.62:27017") rs.add(“10.1.1.63:27017")
  • 12. Step 8. Check the status of your replica set at any time with the rs.status() operation. Step 9. Using Configuration file create mongodb.conf file by issuing following commands vi /etc.mongodb.conf with following details port = 27017 bind_ip = 10.1.1.61 dbpath = /data/db fork = true ( not working in windows) replSet = rs0 Step 10. Start mongod by following operation ./mongod --config /etc/mongodb.config
  • 13. Add Members to a Replica Set Requirements 1. An active replica set. 2. A new MongoDB system capable of supporting your dataset, accessible by the active replica set through the network. 3. Deploy MongoDB new instance, specifying name of replica set. 4. Open mongo shell and connect to replica set’s primary. If you don’t know which member is primary, then issue following commands in mongo shell, db.isMaster() 5. In the mongo shell, issue the following command to add the new member to the replica set. rs.add(“10.1.1.61:27017") 6. Confirm new member is instance of replica set’s.
  • 14. Replica set Maintenance and Administration 1. No downtime 2. Rolling Upgrade maintenance Start with secondary Primary Last
  • 15. Sharding Shard: A single replica set that stores some portion of total sharded cluster data set. Shard Key : In the sharded collection, shard key is the field that MongoDB uses to distribute the document among the member of sharded clusters. Feature of sharding 1. Range-base Data Partitioning MongoDB distribute document among shards base on the shard key. Each chunk is block of document with value that fall within specific range. 2. Automatic Data Volume Distribution sharding system automatic balance data across cluster without in intervention from application layer. Effective automatic sharding depend on well chosen sharding key.
  • 16. 3. Transparent Query Routing Sharding is completely transparent to the application layer, because all connection goes through mongos. 4. Horizontal Capacity A typical sharded cluster consist of, • 3 config server that store metadata. Metadata map chunks to shard. • More than one replica set or mongod instances. These are the shard. • A number of lightweight process, called mongos.
  • 18. When to use sharding 1. your data set approaches or exceeds the storage capacity of a single node in your system. 2. The size of your system’s active working set will soon exceed the capacity of the maximum amount of RAM for your system. 3. your system has a large amount of write activity, a single MongoDB instance cannot write data fast enough to meet demand, and all other approaches have not reduced contention. if these attribute are not in your system, sharding will add additional complexity to your system without providing much benefits.
  • 19. Sharding Requirements 1. Three config sever. For development and testing purposes you may deploy a cluster with a single configuration server process, but always use exactly three config servers for redundancy and safety in production. 2. Two or more shard each shard consist of one or more mongod. Typically each shard is a replica sets. 3. One or more mongos instance. 4. Shard key “Shard keys” refer to the field that exists in every document in a collection that MongoDB uses to distribute documents among the shards.
  • 20. Setting Up Sharding Step 1. Starting the Servers create a config server database directory by issuing following command, $mkdir –p /configsvr/config The config server needs to be started first, because mongos uses it to get its configuration. $./mongod - -dbpath /configsvr/config - - port 10000 Step 2. Starting mongos servers Routing servers don’t even need a data directory, but they need to know where the config server is: $./mongos --port 20000 --configdb localhost:10000 Shard administration is always done through a mongos.
  • 21. Step 3. Adding shard A shard is just MongoDB instance (or replica set). Start three MongoDB instances using following operations, $./mongod –dbpath /data/sard1 - - port 10001 $./mongod –dbpath /data/sard2 - - port 10002 $./mongod –dbpath /data/sard3 - - port 10003 Now connect monos process using mongo by issuing following commands $ ./mongo localhost:20000/admin Make sure that you are connected to mongos not to mongod. Now you can add shard by following commands, >db.runCommands ( { addShard : “localhost:10001”, allowLocal : true } ) Out put > { "added" : "localhost:10000", "ok" : true }
  • 22. The "allowLocal" key is necessary only if you are running the shard on localhost. Step 4. similar way add remain shards
  • 23. Sharding Data 1. MongoDB won’t just distribute every piece of data you’ve ever stored: you have to explicitly turn sharding on at both the database and collection levels. Create database “shardDB”, first we enable sharding for database blog > db.runCommands ( { “enablesharding” : “shardDB” } ) 2. Once you’ve enabled sharding on the database level, you can shard a collection by running the shardcollection command: > db.runCommands ( { “shardcollection” : “shardDB.blog” , “key” : { “_id” : 1} } ) 3. User define sharding key you must create index on sharding key if it is not a “_id” field.
  • 24. Many Mongos You can also run as many mongos processes as you want. One recommended setup is to run a mongos process for every application server. That way, each application server can talk mongos locally. If server goes down, no will be trying to talk with mongos. A Sturdy Shard In production, production each shard should be a replica set. That way individual server can fail without bringing whole shard. To add replica set as a shard, pass its name and a seed to the addshard command. > db.runCommand ( { "addshard" : "foo/10.1.1.61:27017“ } )
  • 25. Sharding Administration 1. Sharding information mostly stored on config server, which can be accessed by any mongos process. 2. Connect to mongos process to access config database. Switch to config DB issue following commands, > db.getCollectionNames() it shows all collection name. You can find list of shards in shards collection > db.shards.find() each shard assigning unique human readable id. 3. Databases The databases collection contain a list of databases that exist on shards and information about that. >db.databases.find()
  • 26. > db.databases.find() { "_id" : "admin", "partitioned" : false, "primary" : "config" } { "_id" : "foo", "partitioned" : false, "primary" : "shard1" } { "_id" : "x", "partitioned" : false, "primary" : "shard0" } { "_id" : "test", "partitioned" : true, "primary" : "shard0", "sharded" : { "test.foo" : { "key" : {“id" : 1}, "unique" : false } } }
  • 27. 4. Chunks chunks information stored in chunks collection. You can actually see how your data has been divided up across the cluster. > db.chunks.find() { "_id" : "test.foo-x_MinKey", "lastmod" : { "t" : 1276636243000, "i" : 1 }, "ns" : "test.foo", "min" : { "x" : { $minKey : 1 } }, "max" : { "x" : { $maxKey : 1 } } "shard" : "shard0" }
  • 28. Sharding Commands 1. The printing sharding status give a quick summary of sharded collection. >db.printShardingStatus() 2. Removing a shard Shards can be removed from a cluster with the removeshard command. Removeshard drains all of the chunks on a given shard to the other shards. >db.runCommand({"removeshard" : "localhost:10000"}); As the shard is drained, removeshard will give you the status of how much remains on the shard. >db.runCommand({"removeshard" : "localhost:10000"}); when the shard has finished draining, removeshard shows that the shard has been successfully removed.