As a good full stack platform as it is, meteor doesn’t have explicitly documentation for customization of the environment underneath.
I’m about to start coding a web application with an idea of starting with a core user API first, and slowly work on developing a series of extensions around the user API. This means I’ll have a single database queried and maintained by multiple meteor apps. In addition, all of the meteor apps will be set up in a single VPS to save money for my body’s digestive system.
I disregarded the meteor self-contained databases and install a mongodb of my own.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
In the shell:
mongo
use [database]
db.createUser({ user: "<name>",
pwd: "<cleartext password>",
roles: [
{ role: "<role>", db: "<database>" } | "<role>",
...
]
})
to create a new database and a new user.
I use mup for deploying multiple Meteor app on the server. Mup is installed on the local machine through npm. In the same Meteor project folder on the local machine:
mup init
then add the environment variable in mup.json:
"PORT": 300X
"MONGO_URL": "mongodb://[username]:[password]@localhost:27017/[database]"
and change “setupMongo” to false.
This way, meteor will run in separate ports connect to the database set by the environment instead of its own.
After that, create A records for subdomains in the domain zone file, and point them all to the server’s IP address.
Install nginx to take meteor’s place of dealing with http requests. In /etc/nginx/site-avaliable/, make new sites and put proxy_pass configurations in:
server {
listen 80;
server_name subdomain.doamin.com;
root /home/user/meteorapp;
location / {
proxy_pass http://domain.com:300X;
}
}
Finally,
nginx -s reload
and starting all the Meteor instances to see multiple Meteors running in harmony.
EDIT: specify “setupMongo: true” will automatically have multiple Meteor instances share the same mongodb.