jordan
jordan

Reputation: 10742

How to run mongodb on AWS

I'm looking for a little direction on how to set up services on AWS. I have an application that is build with Node.js and uses mongodb (and mongoose as the ODM). I'm porting everything over to AWS and would like to set up an autoscaling group behind a load balancer. What I am not really understanding, however, is where my mongodb instance should live. I know that using DynamoDB it can be fairly intuitive to set up to work with that, but since I am not, my question is this: Where and how should mongo be set up to work with my app? Should it be on the same ec2 instance with my app, and if so, how does that work with new instances starting and being terminated? Should I set up an instance dedicated only for mongo? In addition, to that question, how do I create snapshots and backups of my data?

Upvotes: 2

Views: 5312

Answers (3)

Ayush Aryan
Ayush Aryan

Reputation: 221

You can easily install MongoDB in AWS Cloud 9 by using the below process

First create Cloud 9 environment in AWS then at the terminal

ubuntu:~/environment $ At the terminal you’ll see this.

* Now run the following in your terminal:

sudo mv mongodb-org-3.6.repo /etc/yum.repos.d
sudo yum install -y mongodb-org

If the second code does not work try:

sudo apt install mongodb-clients
  • Close the mongodb-org-3.6.repo file and press Close tab when prompted
  • Change directories back into root ~ by entering cd into the terminal then enter the following commands:

  • ubuntu:~ $ “ - Terminal should look like this.

    sudo mkdir -p /data/db echo 'mongod --dbpath=data --nojournal' > mongod chmod a+x mongod

  • Now test mongod with ./mongod

  • Remember, you must first enter cd to change directories into root ~ before running ./mongod
  • Don't forget to shut down ./mongod with ctrl + c each time you're done working

-if this error pops up while using command mongod

exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db, terminating

Then use the code:

sudo chmod -R go+w /data/db

Reference

Upvotes: 1

Mark B
Mark B

Reputation: 200607

This is a good document for installing MongoDB on EC2, and managing backups: https://docs.mongodb.org/ecosystem/platforms/amazon-ec2/

If you aren't comfortable doing all this yourself you might want to also look into MongoLab which is a MongoDB as a Service that can run on AWS.

Upvotes: 1

Eytan Avisror
Eytan Avisror

Reputation: 2970

Your database should definitely be in a separate instance than your app, from all aspects. A very basic tier based application should comprise of the app server cluster in a scaling group behind a load balancer - in a public subnet, and a separate cluster (recommended in a different subnet which is not publicly accessible), which your app cluster will speak to. whether to use an ELB for Mongo or not actually depends on your mongo config (replica set). In regards to snapshots (assume this will only be relevant for your DB), have a look at this.

Upvotes: 1

Related Questions