SlideShare uma empresa Scribd logo
1 de 12
Baixar para ler offline
Configuring MongoDB HA Replica Set on AWS EC2
Background
It has always been a tedious task to choose the right configuration for
MongoDB on AWS EC2
Choosing the right configuration in this environment is always challenging
and it takes a lots of time to make your system Production Ready.
What does it take?
All it needs is two machines that will be used as PRIMARY (Master)
and SECONDARY (Slave) node and one ARBITER machine for the
replica set.
However, it might get changed based on your application
requirement and you can opt for higher number of nodes based on
your need
ARBITER is only required in case of even number replica set. If you
want to maintain replica set with one PRIMARY and two SECONDARY,
ARBITER is not required
Hardware Requirement
Two 64 bit EC2 instances of medium/large or higher configuration
based on your App requirement for PRIMARY and SECONDARY node
(There is a data storage limitation of using 32 bit machine and can only
support upto 2.5 GB storage)

A small 32 bit EC2 machine for MongoDB ARBITER
It is recommended –

• to have machines in different availability zone to make it High
available in-case of a shutdown of one availability zone
• to use Ext4 EBS volume to support I/O suspend and write-cache
flushing for multi-disk consistent snapshots
Installation Steps
Create and Launch an EC2 instance of required configuration as
stated above for PRIMARY, SECONDARY and ARBITER nodes
Create an EBS volume of required size to be used for MongoDB storage
for both nodes
Connect to EC2 instances on PRIMARY and SECONDARY node via SSH
Make an Ext4 file system on both nodes via sudo mkfs -t ext4
/dev/<Created EBS Volume>

Create directory /data/db or any other of your own choice and mount
it to attached volume using sudo mount -a /dev/< Created EBS
Volume > /data/db
Contd..
Edit your /etc/fstab to enumerate it on start up of instance using
sudo echo ‘/dev/sdf /data/db auto noatime,noexec,nodiratime 0 0’
>> /etc/fstab
Download and Install MongoDB on all instances
Start the PRIMARY node with following command in MongoDB
directory using mongod --rest --replSet myHASet (where myHASet is
the name of Replica set; you can choose any name of your choice)
Go to Mongo terminal in MongoDB directory.
Initialize the set using command rs.initiate() on mongo terminal
Check the status of Replica set after initialization using rs.status()
command.
Contd..
If initialization is success you will see OK in the output something like
this
{
"set" : "sample",
"myState" : 1,
"members" : [
{
"name" : "<PRIMARY_HOSTNAME>:27017",
"self" : true
}
],
"ok" : 1
}
You can also check the status on
http://<PRIMARY_NODE>:27017/_replSet
Your Primary node is ready to use now. You can insert/update document
on this node
Contd..
Now start the SECONDARY node with same command as on primary
mongod --rest --replSet myHASet
Tell the PRIMARY node to add SECONDARY node in replica set. Go to
mongo console on PRIMARY node and add this using
rs.add(“<SECONDARY_HOSTNAME>”);
If addition is successful you will see the response
Once your SECONDARY node is attached to replica set you can check
the status on http://<PRIMARY_NODE>:27017/_replSet
Now start the ARBITER node using mongod --rest --replSet myset -oplogSize 8
Contd..
Add the ARBITER node in replica set using command rs.add( {
_id:2, host:”<ARBITER_HOSTNAME>”, arbiterOnly:true } )
Once ARBITER is added successfully, you are done with the
configuration and your replica set is ready to use.
Got o http://<PRIMARY_NODE>:27017/_replSet and you should
be able to see the status of each node.
To test the replica, take down the primary node, and see if
SECONDARY is able to pick up and will become PRIMARY node.
You can fire the command db.isMaster() to check the status if
SECONDARY node has turned up as Master node.
Connecting Replica
• After you have setup the replica set successfully, you can connect with it
using JAVA driver from your client application
• You can use the following code snippet for making connection to replica set
List addrs = new ArrayList();
addrs.add( new ServerAddress(“<PRIMARY_HOST>",”<MONGO_PORT>" ) );
addrs.add( new ServerAddress(“<SECONDARY_HOST>",“<MONGO_PORT>"));
Mongo m = new Mongo(addrs);
DB db = m.getDB(“<NAME_OF_DB>");

• MongoDB driver is smart enough to connect to PRIMARY node only, in-case if
PRIMARY node is down, it will automatically switch to another node for
communication
Conclusion
Here is an honest attempt to guide you to setup MongoDB on AWS
EC2. Though this is an open forum and you all are open to post your
comments if I have missed anything
Also, if you don’t want to get into setting up the infrastructure and
administration for MongoDB, you can directly use our App42 NoSQL
Cloud Storage Service.
This service can be accessed using our REST API or using native
platform SDKs available in different languages like iOS, Android,
J2ME, JAVA, PHP, Ruby, Windows Phone and C#
Links for Reference :
http://www.shephertz.com
http://api.shephertz.com
http://appwarp.shephertz.com

http://app42paas.shephertz.com/

Follow us on:

Contact: sales@shephertz.com
Skype: ShepHertz

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Windows Azure Virtual Machines
Windows Azure Virtual MachinesWindows Azure Virtual Machines
Windows Azure Virtual Machines
 
AWS Lambda at JUST EAT
AWS Lambda at JUST EATAWS Lambda at JUST EAT
AWS Lambda at JUST EAT
 
Setup Kubernetes Cluster On AWS Using KOPS
Setup Kubernetes Cluster On AWS Using KOPSSetup Kubernetes Cluster On AWS Using KOPS
Setup Kubernetes Cluster On AWS Using KOPS
 
Solr Performance Monitoring with SPM
Solr Performance Monitoring with SPMSolr Performance Monitoring with SPM
Solr Performance Monitoring with SPM
 
Terraform
TerraformTerraform
Terraform
 
How to Run Solr on Docker and Why
How to Run Solr on Docker and WhyHow to Run Solr on Docker and Why
How to Run Solr on Docker and Why
 
NFS and CIFS Options for AWS (STG401) | AWS re:Invent 2013
NFS and CIFS Options for AWS (STG401) | AWS re:Invent 2013NFS and CIFS Options for AWS (STG401) | AWS re:Invent 2013
NFS and CIFS Options for AWS (STG401) | AWS re:Invent 2013
 
Erlang scheduler
Erlang schedulerErlang scheduler
Erlang scheduler
 
Apache Kafka, HDFS, Accumulo and more on Mesos
Apache Kafka, HDFS, Accumulo and more on MesosApache Kafka, HDFS, Accumulo and more on Mesos
Apache Kafka, HDFS, Accumulo and more on Mesos
 
(APP313) NEW LAUNCH: Amazon EC2 Container Service in Action | AWS re:Invent 2014
(APP313) NEW LAUNCH: Amazon EC2 Container Service in Action | AWS re:Invent 2014(APP313) NEW LAUNCH: Amazon EC2 Container Service in Action | AWS re:Invent 2014
(APP313) NEW LAUNCH: Amazon EC2 Container Service in Action | AWS re:Invent 2014
 
Security features In MySQL 8.0
Security features In MySQL 8.0Security features In MySQL 8.0
Security features In MySQL 8.0
 
AWS re:Invent re:Cap - 새로운 관계형 데이터베이스 엔진: Amazon Aurora - 양승도
AWS re:Invent re:Cap - 새로운 관계형 데이터베이스 엔진: Amazon Aurora - 양승도AWS re:Invent re:Cap - 새로운 관계형 데이터베이스 엔진: Amazon Aurora - 양승도
AWS re:Invent re:Cap - 새로운 관계형 데이터베이스 엔진: Amazon Aurora - 양승도
 
Introduction To Apache Mesos
Introduction To Apache MesosIntroduction To Apache Mesos
Introduction To Apache Mesos
 
ACS & vSphere Draft
ACS & vSphere DraftACS & vSphere Draft
ACS & vSphere Draft
 
Apache Mesos
Apache MesosApache Mesos
Apache Mesos
 
DataStax: Backup and Restore in Cassandra and OpsCenter
DataStax: Backup and Restore in Cassandra and OpsCenterDataStax: Backup and Restore in Cassandra and OpsCenter
DataStax: Backup and Restore in Cassandra and OpsCenter
 
Docker, Mesos, Spark
Docker, Mesos, Spark Docker, Mesos, Spark
Docker, Mesos, Spark
 
HashiCorp at Just Eat
HashiCorp at Just EatHashiCorp at Just Eat
HashiCorp at Just Eat
 
(SDD416) Amazon EBS Deep Dive | AWS re:Invent 2014
(SDD416) Amazon EBS Deep Dive | AWS re:Invent 2014(SDD416) Amazon EBS Deep Dive | AWS re:Invent 2014
(SDD416) Amazon EBS Deep Dive | AWS re:Invent 2014
 
Building Scalable Web Apps - LVL.UP KL
Building Scalable Web Apps - LVL.UP KLBuilding Scalable Web Apps - LVL.UP KL
Building Scalable Web Apps - LVL.UP KL
 

Destaque

Data Center Migration to the AWS Cloud
Data Center Migration to the AWS CloudData Center Migration to the AWS Cloud
Data Center Migration to the AWS Cloud
Tom Laszewski
 
Setting up mongo replica set
Setting up mongo replica setSetting up mongo replica set
Setting up mongo replica set
Sudheer Kondla
 
Getting started with replica set in MongoDB
Getting started with replica set in MongoDBGetting started with replica set in MongoDB
Getting started with replica set in MongoDB
Kishor Parkhe
 
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
 

Destaque (20)

AWS Webcast - Getting Started with Amazon Web Services
AWS Webcast - Getting Started with Amazon Web ServicesAWS Webcast - Getting Started with Amazon Web Services
AWS Webcast - Getting Started with Amazon Web Services
 
Introduction to Amazon Web Services
Introduction to Amazon Web ServicesIntroduction to Amazon Web Services
Introduction to Amazon Web Services
 
Using Amazon RDS to power enterprise applications (Peoplesoft)
Using Amazon RDS to power enterprise applications (Peoplesoft) Using Amazon RDS to power enterprise applications (Peoplesoft)
Using Amazon RDS to power enterprise applications (Peoplesoft)
 
AWS Summit London 2014 - JUST EAT - High Availability and Rapid Change
AWS Summit London 2014 - JUST EAT - High Availability and Rapid ChangeAWS Summit London 2014 - JUST EAT - High Availability and Rapid Change
AWS Summit London 2014 - JUST EAT - High Availability and Rapid Change
 
AWS Enterprise Day | Running Critical Business Applications on AWS
AWS Enterprise Day | Running Critical Business Applications on AWSAWS Enterprise Day | Running Critical Business Applications on AWS
AWS Enterprise Day | Running Critical Business Applications on AWS
 
AWS CloudFormation template with single & redundant system
AWS CloudFormation template with single & redundant systemAWS CloudFormation template with single & redundant system
AWS CloudFormation template with single & redundant system
 
From One to Many: Evolving VPC Design
From One to Many: Evolving VPC DesignFrom One to Many: Evolving VPC Design
From One to Many: Evolving VPC Design
 
Incident Coordination Workshop
Incident Coordination WorkshopIncident Coordination Workshop
Incident Coordination Workshop
 
AWS Solutions Architect 準備心得
AWS Solutions Architect 準備心得AWS Solutions Architect 準備心得
AWS Solutions Architect 準備心得
 
Data Center Migration to the AWS Cloud
Data Center Migration to the AWS CloudData Center Migration to the AWS Cloud
Data Center Migration to the AWS Cloud
 
Overview of Amazon Web Services
Overview of Amazon Web ServicesOverview of Amazon Web Services
Overview of Amazon Web Services
 
What is AWS?
What is AWS?What is AWS?
What is AWS?
 
Mastering Access Control Policies
Mastering Access Control PoliciesMastering Access Control Policies
Mastering Access Control Policies
 
Introduction to Cloud Computing with Amazon Web Services
Introduction to Cloud Computing with Amazon Web ServicesIntroduction to Cloud Computing with Amazon Web Services
Introduction to Cloud Computing with Amazon Web Services
 
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
 
Getting started with replica set in MongoDB
Getting started with replica set in MongoDBGetting started with replica set in MongoDB
Getting started with replica set in 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
 

Semelhante a Configuring MongoDB HA Replica Set on AWS EC2

MongoDB Replication and Sharding
MongoDB Replication and ShardingMongoDB Replication and Sharding
MongoDB Replication and Sharding
Tharun Srinivasa
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
NIRMAL FELIX
 
R hive tutorial supplement 1 - Installing Hadoop
R hive tutorial supplement 1 - Installing HadoopR hive tutorial supplement 1 - Installing Hadoop
R hive tutorial supplement 1 - Installing Hadoop
Aiden Seonghak Hong
 

Semelhante a Configuring MongoDB HA Replica Set on AWS EC2 (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
Mongodb replicationMongodb replication
Mongodb replication
 
CoreOS, or How I Learned to Stop Worrying and Love Systemd
CoreOS, or How I Learned to Stop Worrying and Love SystemdCoreOS, or How I Learned to Stop Worrying and Love Systemd
CoreOS, or How I Learned to Stop Worrying and Love Systemd
 
Configuring Your First Hadoop Cluster On EC2
Configuring Your First Hadoop Cluster On EC2Configuring Your First Hadoop Cluster On EC2
Configuring Your First Hadoop Cluster On EC2
 
Hadoop on osx
Hadoop on osxHadoop on osx
Hadoop on osx
 
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 – 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 basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & Introduction
 
Eyeball XMPP Server Administrator Guide
Eyeball XMPP Server Administrator GuideEyeball XMPP Server Administrator Guide
Eyeball XMPP Server Administrator Guide
 
fard car.pptx
fard car.pptxfard car.pptx
fard car.pptx
 
Oracle 11g Installation With ASM and Data Guard Setup
Oracle 11g Installation With ASM and Data Guard SetupOracle 11g Installation With ASM and Data Guard Setup
Oracle 11g Installation With ASM and Data Guard Setup
 
linux installation.pdf
linux installation.pdflinux installation.pdf
linux installation.pdf
 
MongoDB Replication and Sharding
MongoDB Replication and ShardingMongoDB Replication and Sharding
MongoDB Replication and Sharding
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
R hive tutorial supplement 1 - Installing Hadoop
R hive tutorial supplement 1 - Installing HadoopR hive tutorial supplement 1 - Installing Hadoop
R hive tutorial supplement 1 - Installing Hadoop
 
Percona Live 2017 ­- Sharded cluster tutorial
Percona Live 2017 ­- Sharded cluster tutorialPercona Live 2017 ­- Sharded cluster tutorial
Percona Live 2017 ­- Sharded cluster tutorial
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy System
 
Cloud Meetup - Automation in the Cloud
Cloud Meetup - Automation in the CloudCloud Meetup - Automation in the Cloud
Cloud Meetup - Automation in the Cloud
 
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
 

Mais de ShepHertz

Mais de ShepHertz (15)

ShepHertz Facial recognition based attendance and visitor management system
ShepHertz Facial recognition based attendance and visitor management systemShepHertz Facial recognition based attendance and visitor management system
ShepHertz Facial recognition based attendance and visitor management system
 
Configure &amp; send push notification on i os device
Configure &amp; send push notification on i os deviceConfigure &amp; send push notification on i os device
Configure &amp; send push notification on i os device
 
Complete steps to Integrate Push Notification for Your Cocos2dx App with Push...
Complete steps to Integrate Push Notification for Your Cocos2dx App with Push...Complete steps to Integrate Push Notification for Your Cocos2dx App with Push...
Complete steps to Integrate Push Notification for Your Cocos2dx App with Push...
 
A Complete Tutorial to Develop Real-Time Fighting Game with Cocos2dx
A Complete Tutorial to Develop Real-Time Fighting Game with Cocos2dxA Complete Tutorial to Develop Real-Time Fighting Game with Cocos2dx
A Complete Tutorial to Develop Real-Time Fighting Game with Cocos2dx
 
Media &amp; entertainment marketing automation and omnichannel media
Media &amp; entertainment marketing automation and omnichannel mediaMedia &amp; entertainment marketing automation and omnichannel media
Media &amp; entertainment marketing automation and omnichannel media
 
Insurance marketing automation and omni channel insurance.
Insurance marketing automation and omni channel insurance.Insurance marketing automation and omni channel insurance.
Insurance marketing automation and omni channel insurance.
 
Travel and aviation marketing automation and omnichannel travel
Travel and aviation marketing automation and omnichannel travelTravel and aviation marketing automation and omnichannel travel
Travel and aviation marketing automation and omnichannel travel
 
Gaming marketing automation and multiplayer game development
Gaming marketing automation and multiplayer game developmentGaming marketing automation and multiplayer game development
Gaming marketing automation and multiplayer game development
 
Retail marketing automation and omni channel retail experience.
Retail marketing automation and omni channel retail experience.Retail marketing automation and omni channel retail experience.
Retail marketing automation and omni channel retail experience.
 
Banking Services Marketing Automation and Omni-channel Banking
Banking Services Marketing Automation and Omni-channel BankingBanking Services Marketing Automation and Omni-channel Banking
Banking Services Marketing Automation and Omni-channel Banking
 
ShepHertz Cloud Ecosystem for Apps
ShepHertz Cloud Ecosystem for AppsShepHertz Cloud Ecosystem for Apps
ShepHertz Cloud Ecosystem for Apps
 
Push Notification with Unity in iOS using App42 Backend
Push Notification with Unity in iOS using App42 BackendPush Notification with Unity in iOS using App42 Backend
Push Notification with Unity in iOS using App42 Backend
 
ShepHertz - アプリのための万全なエコシステム
ShepHertz - アプリのための万全なエコシステムShepHertz - アプリのための万全なエコシステム
ShepHertz - アプリのための万全なエコシステム
 
App42 Student Lab - Android Game Dev Series V 0.1
App42 Student Lab - Android Game Dev Series V 0.1App42 Student Lab - Android Game Dev Series V 0.1
App42 Student Lab - Android Game Dev Series V 0.1
 
ShepHertz - A Complete Cloud Ecosystem for your Apps
ShepHertz - A Complete Cloud Ecosystem for your AppsShepHertz - A Complete Cloud Ecosystem for your Apps
ShepHertz - A Complete Cloud Ecosystem for your Apps
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Configuring MongoDB HA Replica Set on AWS EC2

  • 1. Configuring MongoDB HA Replica Set on AWS EC2
  • 2. Background It has always been a tedious task to choose the right configuration for MongoDB on AWS EC2 Choosing the right configuration in this environment is always challenging and it takes a lots of time to make your system Production Ready.
  • 3. What does it take? All it needs is two machines that will be used as PRIMARY (Master) and SECONDARY (Slave) node and one ARBITER machine for the replica set. However, it might get changed based on your application requirement and you can opt for higher number of nodes based on your need ARBITER is only required in case of even number replica set. If you want to maintain replica set with one PRIMARY and two SECONDARY, ARBITER is not required
  • 4. Hardware Requirement Two 64 bit EC2 instances of medium/large or higher configuration based on your App requirement for PRIMARY and SECONDARY node (There is a data storage limitation of using 32 bit machine and can only support upto 2.5 GB storage) A small 32 bit EC2 machine for MongoDB ARBITER It is recommended – • to have machines in different availability zone to make it High available in-case of a shutdown of one availability zone • to use Ext4 EBS volume to support I/O suspend and write-cache flushing for multi-disk consistent snapshots
  • 5. Installation Steps Create and Launch an EC2 instance of required configuration as stated above for PRIMARY, SECONDARY and ARBITER nodes Create an EBS volume of required size to be used for MongoDB storage for both nodes Connect to EC2 instances on PRIMARY and SECONDARY node via SSH Make an Ext4 file system on both nodes via sudo mkfs -t ext4 /dev/<Created EBS Volume> Create directory /data/db or any other of your own choice and mount it to attached volume using sudo mount -a /dev/< Created EBS Volume > /data/db
  • 6. Contd.. Edit your /etc/fstab to enumerate it on start up of instance using sudo echo ‘/dev/sdf /data/db auto noatime,noexec,nodiratime 0 0’ >> /etc/fstab Download and Install MongoDB on all instances Start the PRIMARY node with following command in MongoDB directory using mongod --rest --replSet myHASet (where myHASet is the name of Replica set; you can choose any name of your choice) Go to Mongo terminal in MongoDB directory. Initialize the set using command rs.initiate() on mongo terminal Check the status of Replica set after initialization using rs.status() command.
  • 7. Contd.. If initialization is success you will see OK in the output something like this { "set" : "sample", "myState" : 1, "members" : [ { "name" : "<PRIMARY_HOSTNAME>:27017", "self" : true } ], "ok" : 1 } You can also check the status on http://<PRIMARY_NODE>:27017/_replSet Your Primary node is ready to use now. You can insert/update document on this node
  • 8. Contd.. Now start the SECONDARY node with same command as on primary mongod --rest --replSet myHASet Tell the PRIMARY node to add SECONDARY node in replica set. Go to mongo console on PRIMARY node and add this using rs.add(“<SECONDARY_HOSTNAME>”); If addition is successful you will see the response Once your SECONDARY node is attached to replica set you can check the status on http://<PRIMARY_NODE>:27017/_replSet Now start the ARBITER node using mongod --rest --replSet myset -oplogSize 8
  • 9. Contd.. Add the ARBITER node in replica set using command rs.add( { _id:2, host:”<ARBITER_HOSTNAME>”, arbiterOnly:true } ) Once ARBITER is added successfully, you are done with the configuration and your replica set is ready to use. Got o http://<PRIMARY_NODE>:27017/_replSet and you should be able to see the status of each node. To test the replica, take down the primary node, and see if SECONDARY is able to pick up and will become PRIMARY node. You can fire the command db.isMaster() to check the status if SECONDARY node has turned up as Master node.
  • 10. Connecting Replica • After you have setup the replica set successfully, you can connect with it using JAVA driver from your client application • You can use the following code snippet for making connection to replica set List addrs = new ArrayList(); addrs.add( new ServerAddress(“<PRIMARY_HOST>",”<MONGO_PORT>" ) ); addrs.add( new ServerAddress(“<SECONDARY_HOST>",“<MONGO_PORT>")); Mongo m = new Mongo(addrs); DB db = m.getDB(“<NAME_OF_DB>"); • MongoDB driver is smart enough to connect to PRIMARY node only, in-case if PRIMARY node is down, it will automatically switch to another node for communication
  • 11. Conclusion Here is an honest attempt to guide you to setup MongoDB on AWS EC2. Though this is an open forum and you all are open to post your comments if I have missed anything Also, if you don’t want to get into setting up the infrastructure and administration for MongoDB, you can directly use our App42 NoSQL Cloud Storage Service. This service can be accessed using our REST API or using native platform SDKs available in different languages like iOS, Android, J2ME, JAVA, PHP, Ruby, Windows Phone and C#
  • 12. Links for Reference : http://www.shephertz.com http://api.shephertz.com http://appwarp.shephertz.com http://app42paas.shephertz.com/ Follow us on: Contact: sales@shephertz.com Skype: ShepHertz