I've recently deployed my Meteor app to a Digital Ocean droplet running Ubuntu 14.04 x32. I used Meteor Up with this mup.json
file:
{
// Server authentication info
"servers": [
{
"host": "mycorrecthostname",
"username": "root",
"password": "mycorrectpassword"
}
],
// Install MongoDB in the server, does not destroy local MongoDB on future setup
"setupMongo": true,
// WARNING: Node.js is required! Only skip if you already have Node.js installed on server.
"setupNode": true,
// WARNING: If nodeVersion omitted will setup 0.10.25 by default. Do not use v, only version number.
"nodeVersion": "0.10.28",
// Install PhantomJS in the server
"setupPhantom": true,
// Application name (No spaces)
"appName": "meteor",
// Location of app (local directory)
"app": "/my/correct/path/to/app",
// Configure environment
"env": {
"ROOT_URL": "http://mycorrecturl.com"
},
// Meteor Up checks if the app comes online just after the deployment
// before mup checks that, it will wait for no. of seconds configured below
"deployCheckWaitTime": 15
}
Everything works great. I have tested the website, and everything works just the way it should. I've also set up my ssh
keys with the server, and can ssh
to it without a password.
Now though, I need to access my server database remotely. I have some local data in a python shelf
file that I need to seed my database with. I understand how to connect to a remote database with pymongo
, but I'm trying to get a connection URI with meteor mongo --url http://mycorrecturl.com/
and it just returns this error:
Couldn't open a mongo connection: Site does not exist
What?? What is going wrong here? I would expect it to ask for authentication, but just not existing? Officially confused.
Your help is appreciated in advance!
Update
I've been hunting around in my server directories, trying to successfully run meteor mongo
there, but despite the fact that I've installed meteor with curl https://install.meteor.com | /bin/sh
, it simply always says that I'm not in a meteor project directory. Even the hidden .meteor
directory apparently wasn't a project directory.
Update
I've looked more closely at the Meteor Up docs, and it says this:
You can't access the MongoDB from the outside of the server. To access the MongoDB shell you need to log into your server by SSH first and then run the following command.
mongo appName
I tried that out and it works, but that's not good enough. I need to be able to access the database remotely. Is it simply impossible with a Meteor Up deployment?
One of the answers below seems to be suggesting that by setting the MONGO_URL
in my env
object, that I will basically be manually telling the database what url to respond to. Is that accurate?
Update
The Meteor Up docs say the following:
<appName> is the name of the database
So, on the advice of one of the answers, I edited my mup.json
to include this:
// Configure environment
"env": {
"ROOT_URL": "http://localhost/",
"MONGO_URL": "mongodb://root:mypassword@127.0.0.1:27017/meteor"
// My appName is "meteor", so that is the name of the database as well.
}
When I execute mup deploy
with those variables, the deployment fails. Here's the first part of the error (if you'd like to see the rest let me know):
/usr/lib/node_modules/wait-for-mongo/bin/wait-for-mongo:14
throw err;
When I use mup reconfigure
, it doesn't fail, but then the website simply cannot be found at it's url. It seems to me that the MONGO_URL
isn't a control mechanism, but merely a pointer to an outside database such as mongohq.
I'm thinking I'll have no choice but to resort to the mongo appName
convention and an ssh python library, but I'd love to find a way to directly access my database remotely and still keep using Meteor Up.
It is impossible to remotely access the database, if Meteor Up installed and set it up for you. From the Meteor Up docs:
You can't access the MongoDB from the outside of the server. To access the MongoDB shell you need to log into your server by SSH first and then run the following command.
mongo appName
It can however be accessed in other ways than that mongo appName
interface, if those programs are running on the server.
Digital Ocean Ubuntu droplets come equipped with Python 2.7, so using pymongo is possible. This command will connect you:
from pymongo import MongoClient
client = MongoClient()
That will automatically connect at mongodb://localhost:27017/
pymongo
isn't a default package, so install pip
, and then use pip
to install pymongo
.
apt-get install python-pip python-dev build-essential
pip install pymongo
It's because you did not set the MONGO_URL in the "env" object.
// Configure environment
"env": {
"PORT": 58090, # Your application port
"ROOT_URL": "http://localhost/",
"MONGO_URL": "mongodb://username:password@127.0.0.1:27017/myDatabase",
"METEOR_ENV": "production" # If you need to separate your local environment from production
},
Then, just run mup deploy
.
It took me a while to figure this out. It is not possible to access the mongodb server from outside your hosting server. Therefore, you have to ssh
into your server first and work from there. To connect to your db with pymongo, use the following:
client = MongoClient('mongodb://localhost/APPNAME')
posts = client.APPNAME.posts
APPNAME should be specified in your mup.json
file and replace posts
with whatever collection you must update.
I think I found a solution for accessing the DB with mupx on a digitalocean ubuntu 14.04 server.
After deployment of your app with mupx, do the following:
Login with ssh into your server, then install mongo: apt-get install mongodb
Then run the mongo
command on your server. Try checking if your DB exists by running show dbs
. If it is, then use yourdbname
. It should hold all the data from your running app!
Let me know if it works. Good luck.
You can change the mongod.conf, to allow access from outside (a bit dangerous of course ;)
nano /etc/mongod.conf
# Listen to local interface only. Comment out to listen on all interfaces.
# bind_ip = 127.0.0.1
then restart the server
service mongod stop
service mongod start
and you can access it from outside (using ssh-forwarding in robo-mongo)
All I did was add the IP of my Digital ocean droplet server, instead of localhost, and it worked:
env: {
ROOT_URL: 'http://yourdomain.com',
MONGO_URL: 'mongodb://104.236.24.66:27017/meteor',
PORT: 3002,
},
Using this mongo instance in docker for 2 meteor apps currently.
EDIT: This depends on how your firewall is setup. Check with "ufw status". Also depends on how your mongo is deployed (which ports forwarded to where; ex) 0.0.0.0:27017->27017 ).
来源:https://stackoverflow.com/questions/23786647/meteor-up-deployment-cant-use-meteor-mongo-url