Manually Installing Mongo on EC2

After getting help from @chenroth on the topic of deploying my application to EC2, I found out I need to manually install the Mongo database on an EC2 instance.

Using mup to reference via URL the database a non local copy of Mongo is straight forward, but I need to manually install Mongo and configure the port (and I’m not sure, but I might have to manually setup the database too).

This is an example of the mup file, where the Meteor application will reference Mongo from a URL:

// mup1.json

"env": {
    "ROOT_URL": "https://great_domain.com",
    "MONGO_URL": "mongodb://databases.great_domain.com:1337" 
  }, 

My question is, on a EC2 instance, using Meteor 1.0.3.2, how I install Mongo, configure database server port at the database level and EC2 level for inbound and outbound traffic, possibly set up security and a database?

I would like my database to function just as if it was a local instance.

MUP configures a MongoDB as a local instance by default: https://github.com/arunoda/meteor-up#server-setup-details

As long as it is set in the mup.json file:

  // Install MongoDB on the server. Does not destroy the local MongoDB on future setups
  "setupMongo": true,

Thanks for that.

The environment MONGO_URL variable,

“MONGO_URL”: “mongodb://databases.great_domain.com:1337”

Along with the environment variable setupMongo set to false,

“setupMongo”: false

Should allow for our Meteor applications to access a ‘remote’ MongoDB correct?

In this case I’ll need to manually install MongoDB on this ‘remote’ database server, right?

I’m asking how to set up the remote database server on this EC2 instance in a way that allows for a Meteor application to access it at this "MONGO_URL": "mongodb://databases.great_domain.com:1337".

So in the end my my mup file would look like this:

// mup.json

{
  "servers": [
    {
      "host": "great_domain.com",
      "username": "ubuntu",
      "pem": "/pem_path/pem_file.pem"
    }
  ],
  // Install MongoDB in the server, does not destroy local MongoDB on future setup
  "setupMongo": false,
  "setupNode": true,
  "nodeVersion": "0.10.35",
  "setupPhantom": false,
  "appName": "tenant_application",
  "app": "/app_path/app_name",
  "env": {
    "ROOT_URL": "https://tenant_1.great_domain.com",
    "MONGO_URL": "mongodb://tenant_1_database.great_domain.com:1337"
  },
  "ssl": {
    "pem": "./ssl.pem"
  },
  "deployCheckWaitTime": 30
}

So you want to have a Meteor server and MongoDB running on the same EC2 instance, but with other Meteor servers connected to that same Mongo instance? Or is the mongo instance completely separate on it’s own EC2 instance?

Thanks.

The setup should look something like this:

EC2 (1) instance (application server 1)
-> client1.great_domain.com

EC2 (2) instance (application server 2)
-> client2.great_domain.com

EC2 (3) instance (database server 1)
-> url: client1_database.great_domain.com:1337 (database instances 1)
-> name: client1_application (databases 1)

EC2 (4) instance (database server 2)
-> url: client2_database.great_domain.com:1337 (database instances 1)
-> name: client2_application (databases 1)

In this case I’d need (2) mup deployment files:

// mup_client1.json

{
  "servers": [
    {
      "host": "client1.great_domain.com",
      "username": "ubuntu",
      "pem": "/pem_path/pem_file.pem"
    }
  ],
  "setupMongo": false,
  "setupNode": true,
  "nodeVersion": "0.10.35",
  "setupPhantom": false,
  "appName": "tenant_application",
  "app": "/app_path/app_name",
  "env": {
    "ROOT_URL": "https://client1.great_domain.com",
    "MONGO_URL": "mongodb://client1_database.great_domain.com:1337"
  },
  "ssl": {
    "pem": "./ssl.pem"
  },
  "deployCheckWaitTime": 30
}

// mu_client1.json

{
  "servers": [
    {
      "host": "client2.great_domain.com",
      "username": "ubuntu",
      "pem": "/pem_path/pem_file.pem"
    }
  ],
  "setupMongo": false,
  "setupNode": true,
  "nodeVersion": "0.10.35",
  "setupPhantom": false,
  "appName": "tenant_application",
  "app": "/app_path/app_name",
  "env": {
    "ROOT_URL": "https://client2.great_domain.com",
    "MONGO_URL": "mongodb://client2_database.great_domain.com:1337"
  },
  "ssl": {
    "pem": "./ssl.pem"
  },
  "deployCheckWaitTime": 30
}

And would need to install MongoDB on (2) EC2 servers:

EC2 (3) instance (database server 1)
-> MONGO_URL: client1_database.great_domain.com:1337 (database instances 1)
-> Database name: client1_application (databases 1)

EC2 (4) instance (database server 2)
-> MONGO_URL: client2_database.great_domain.com:1337 (database instances 1)
-> Database name: client2_application (databases 1)

I think the way it works is, the MONGO_URL environment variable tells Meteor where the MongoDB is located.

You’re definitely right in that respect, although my god that looks complicated! Have you looked at hosted solutions like Compose.io?

Thanks.

How would this mup setup work with Compose.io? Instead of installing MongoDB on an EC2 box, I would just use a Compose.io box, get the URL and port#, and in the mup.json file just point it in that direction?

So instead of this:

"env": {
    "MONGO_URL": "mongodb://ec2_database.great_domain.com:1337"
  }

It would be this:

"env": {
    "MONGO_URL": "mongodb://compose_io_database.great_domain.com:1337"
  }

Is this right?

Serious question, what’s so complicated about setting up/configuring MongoDB on a Ubuntu EC2 server?

I thought there would be a guide lying around somewhere that everyone uses. In fact, I thought it was frowned upon to deploy our Meteor applications running the local instance of MongoDB. I thought the ‘right’ way was to break out the MongoDB onto its own Database Server… is this not the case?

Nothing’s that complex about setting it up, but then you are responsible for everything OS updates, backups, load-balancing, scaling, etc.

Compose.io will just do this all for you straight out of the box, less hassle.

Compose.io looks too expense for my budget right now… I’ll look at it again later. Also, I don’t need everything right now (I’m just starting out). A EC2 instance I think will work for now.

If anyone can help me with getting a MongoDB install going on a EC2 instance, that would be great.

Also worth noting as a potential “gotcha!” is that to get the best performance out of Meteor it needs to use Oplog tailing when connecting to the MongoDB. This means that your database needs to be set up as a replica-set, with one database as the primary and others as secondaries.

Thanks for that tip.

But what about when one does just the basic mup install? Like this:
// mup.json

{
  "servers": [
    {
      "host": "super_domain.com",
      "username": "ubuntu",
      "pem": "/pem_path/pem_file.pem"
    }
  ],
  "setupMongo": true, <-- Install Mongo Locally!!
  "setupNode": true,
  "nodeVersion": "0.10.35",
  "setupPhantom": false,
  "appName": "tenant_application",
  "app": "/app_path/app_name",
  "env": {  <-- No MONGO_URL here!
    "ROOT_URL": "https://super_domain.com"
  },
  "ssl": {
    "pem": "./ssl.pem"
  },
  "deployCheckWaitTime": 30
}

What I mean is, this is the standard install. This install will not set up Oplog tailing and all the other performance ‘stuff’ right?

Well, MUP isn’t really designed for creating MongoDB hosts, it’s designed for uploading Meteor applications and (if needed) installing and running local DB instances for them to use. It isn’t designed for administrating an EC2 instance with nothing other than a MongoDB instance on it.

If you want to do that, you’re sort of attacking it from the wrong angle, it’s got nothing at all to do with Meteor at that point, and everything to do with hosting a MongoDB instance on EC2:

Thanks for the links, I’ll review what you posted.

Right now I use MongoChef and/or Robomongo to ssh into the EC2 server and ‘administer’ the MongoDB instance. This seems to be working for me at the moment – but I don’t think these tools are meant for tackling things like security, scaling and performance.

Do yourself a favor, try out MMS (free). They’ll deploy it on AWS for you
and take care of all the setup headache. If you decide to not use their
service, at the least you could learn how they setup AWS security wise

Mup’s MongoDB deployment is only for dev purpose. If you are looking for something serious try MongoDB MMS. Or with some tool like Ansible.

Thanks, I’ll check MMS out!