SlideShare a Scribd company logo
1 of 28
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.

More Related Content

What's hot

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 solutionsLouis liu
 
Percona Live 2017 ­- Sharded cluster tutorial
Percona Live 2017 ­- Sharded cluster tutorialPercona Live 2017 ­- Sharded cluster tutorial
Percona Live 2017 ­- Sharded cluster tutorialAntonios 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 actionSveta Smirnova
 
MySQL replication & cluster
MySQL replication & clusterMySQL replication & cluster
MySQL replication & clusterelliando dias
 
MySQL async message subscription platform
MySQL async message subscription platformMySQL async message subscription platform
MySQL async message subscription platformLouis liu
 
Cassandra for Python Developers
Cassandra for Python DevelopersCassandra for Python Developers
Cassandra for Python DevelopersTyler Hobbs
 
My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestratorYoungHeon (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 2017Antonios 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 2013odnoklassniki.ru
 
Recent my sql_performance Test detail
Recent my sql_performance Test detailRecent my sql_performance Test detail
Recent my sql_performance Test detailLouis 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 scalabilityWim 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-TreeSveta 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 & ELKI 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 2016Dave Stokes
 
MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016Dave 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 ELKI Goo Lee
 

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
 
Percona Live 2017 ­- Sharded cluster tutorial
Percona Live 2017 ­- Sharded cluster tutorialPercona Live 2017 ­- Sharded cluster tutorial
Percona Live 2017 ­- Sharded cluster tutorial
 
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
 
MySQL replication & cluster
MySQL replication & clusterMySQL replication & cluster
MySQL replication & cluster
 
MySQL async message subscription platform
MySQL async message subscription platformMySQL async message subscription platform
MySQL async message subscription platform
 
Cassandra for Python Developers
Cassandra for Python DevelopersCassandra for Python Developers
Cassandra for Python Developers
 
My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestrator
 
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
 
MongoDB Replication (Dwight Merriman)
MongoDB Replication (Dwight Merriman)MongoDB Replication (Dwight Merriman)
MongoDB Replication (Dwight Merriman)
 
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
 
Recent my sql_performance Test detail
Recent my sql_performance Test detailRecent my sql_performance Test detail
Recent my sql_performance Test detail
 
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
 
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
 
Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018 Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018
 
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
 
HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)
 
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
 
MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016
 
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
 
Mysql all
Mysql allMysql all
Mysql all
 

Viewers also liked

Spring Data MongoDB Webiner
Spring Data MongoDB WebinerSpring Data MongoDB Webiner
Spring Data MongoDB WebinerHakan Özler
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica SetsMongoDB
 
Setting up mongo replica set
Setting up mongo replica setSetting up mongo replica set
Setting up mongo replica setSudheer Kondla
 
MongoDB Replica Sets
MongoDB Replica SetsMongoDB Replica Sets
MongoDB Replica SetsMongoDB
 
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 stackAbhra 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-SetVivek Parihar
 
Mongodb sharding
Mongodb shardingMongodb sharding
Mongodb shardingxiangrong
 
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 EC2ShepHertz
 
MongoDB Administration 101
MongoDB Administration 101MongoDB Administration 101
MongoDB Administration 101MongoDB
 
High Availabiltity & Replica Sets with mongoDB
High Availabiltity & Replica Sets with mongoDBHigh Availabiltity & Replica Sets with mongoDB
High Availabiltity & Replica Sets with mongoDBGareth 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 SetsMongoDB
 

Viewers also liked (13)

Spring Data MongoDB Webiner
Spring Data MongoDB WebinerSpring Data MongoDB Webiner
Spring Data MongoDB Webiner
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
 
Setting up mongo replica set
Setting up mongo replica setSetting up mongo replica set
Setting up mongo replica set
 
MongoDB Replica Sets
MongoDB Replica SetsMongoDB Replica Sets
MongoDB Replica Sets
 
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
 
A complete hadoop stack
A complete hadoop stackA complete hadoop stack
A complete hadoop stack
 
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
 
Mongodb sharding
Mongodb shardingMongodb sharding
Mongodb sharding
 
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
 
MongoDB Administration 101
MongoDB Administration 101MongoDB Administration 101
MongoDB Administration 101
 
High Availabiltity & Replica Sets with mongoDB
High Availabiltity & Replica Sets with mongoDBHigh Availabiltity & Replica Sets with mongoDB
High Availabiltity & Replica Sets with mongoDB
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 
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
 

Similar to Getting started with replica set in MongoDB

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 minutesSudheer Kondla
 
MongoDB Replication and Sharding
MongoDB Replication and ShardingMongoDB Replication and Sharding
MongoDB Replication and ShardingTharun Srinivasa
 
MongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster TutorialMongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster TutorialJason Terpko
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & IntroductionJerwin 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 BeginnersEnoch 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-2MongoDB
 
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 scaleAlex 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 ClusterChris Henry
 
Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo dbAmit Thakkar
 
Elastic101tutorial Percona Live Europe 2018
Elastic101tutorial Percona Live Europe 2018Elastic101tutorial Percona Live Europe 2018
Elastic101tutorial Percona Live Europe 2018Alex Cercel
 
MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017Dave Stokes
 
Attacking Oracle with the Metasploit Framework
Attacking Oracle with the Metasploit FrameworkAttacking Oracle with the Metasploit Framework
Attacking Oracle with the Metasploit FrameworkChris Gates
 
Dbdeployer, the universal installer
Dbdeployer, the universal installerDbdeployer, the universal installer
Dbdeployer, the universal installerGiuseppe Maxia
 
MariaDB10.7_install_Ubuntu.docx
MariaDB10.7_install_Ubuntu.docxMariaDB10.7_install_Ubuntu.docx
MariaDB10.7_install_Ubuntu.docxNeoClova
 

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
 
MongoDB Replication and Sharding
MongoDB Replication and ShardingMongoDB Replication and Sharding
MongoDB Replication and Sharding
 
Mongodb replication
Mongodb replicationMongodb replication
Mongodb replication
 
Sharded cluster tutorial
Sharded cluster tutorialSharded cluster tutorial
Sharded cluster tutorial
 
MongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster TutorialMongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster Tutorial
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & Introduction
 
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
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
 
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
 
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
 
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
 
Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo db
 
Elastic101tutorial Percona Live Europe 2018
Elastic101tutorial Percona Live Europe 2018Elastic101tutorial Percona Live Europe 2018
Elastic101tutorial Percona Live Europe 2018
 
Performance Tuning
Performance TuningPerformance Tuning
Performance Tuning
 
MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017
 
MongoDB Backup & Disaster Recovery
MongoDB Backup & Disaster RecoveryMongoDB Backup & Disaster Recovery
MongoDB Backup & Disaster Recovery
 
Attacking Oracle with the Metasploit Framework
Attacking Oracle with the Metasploit FrameworkAttacking Oracle with the Metasploit Framework
Attacking Oracle with the Metasploit Framework
 
linux installation.pdf
linux installation.pdflinux installation.pdf
linux installation.pdf
 
Dbdeployer, the universal installer
Dbdeployer, the universal installerDbdeployer, the universal installer
Dbdeployer, the universal installer
 
MariaDB10.7_install_Ubuntu.docx
MariaDB10.7_install_Ubuntu.docxMariaDB10.7_install_Ubuntu.docx
MariaDB10.7_install_Ubuntu.docx
 

More from Kishor Parkhe

More from Kishor Parkhe (6)

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

Recently uploaded

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

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.