2
votes

I am reading about Deploying to EC2. The final step looks like this, where I put the bundle folder outside of my meteor project

PORT=80 MONGO_URL=mongodb://localhost:27017/sidebar
ROOT_URL=http://ec2-23-20-113-59.compute-1.amazonaws.com/
sudo node ../bundle/main.js

where I replace the ROOT_URL with the public DNS shown in my AWS console. I am not quite sure what to use for MONGO_URL, so I start the meteor via the command

meteor

to see what the mongodb address meteor uses, which turns out to be

mongodb://127.0.0.1:3002/meteor

But for the node app to be able to connect to mongodb, I have to keep the meteor app running. When it seems to be working, with the console showing

listening

I try to access the site using the public DNS, but it doesn't work. So I don't know what to do next.

1
Alternatively, you may want to try a different approach that runs in production as intended (via meteor bundle): github.com/matb33/meteor-ec2-installmatb33
In using that script, would MONGO_URL still be mongodb://127.0.0.1:3002/meteor?user2191332
Almost. Port 27017 instead of 3002.matb33
You may also find the Meteor-UP project useful: github.com/arunoda/meteor-up This article also has examples of setting up load balancing with HAProxy: meteorhacks.com/how-to-scale-meteor.htmlalanning
Thanks, I will look into it. I saw the command "mup deploy" somewhere before not knowing what it meant; now I know :)user2191332

1 Answers

5
votes

You need to start your own instance of mongodb. What you are seeing when running your project using the meteor command is just the in-place mongo db that meteor provides you with for development. In production you just start your own mongodb (install it via your linux package manager) and then set your MONGO_URL to that -- you can use the local IP for that.

On Ubuntu on AWS, for instance, if you installed mongodb using apt-get install mongodb, it will run on this URL: MONGO_URL='mongodb://localhost:27017/yourdbname'. If you use a separate AWS instance to run the db then you'll just replace localhost with the IP of that instance.

BTW: you should avoid running anything as root, incl. your bundled app. I'm assuming you are doing that only in order to be able to bind to port 80. A perhaps safer way of doing so is to allow your user to bind to that port also using the following command prior to invoking node:

sudo setcap 'cap_net_bind_service=+ep' /usr/bin/nodejs

Update: The easiest way to set these environment variables is to just use env:

sudo env PORT=80 MONGO_URL=mongodb://localhost:27017/sidebar ROOT_URL=http://ec2-23-20-113-59.compute-1.amazonaws.com/ node ../bundle/main.js