7
Í METEOR (HTTPS://BLOG.DESIGNVELOPER.COM/CATEGORY/METEOR/) Û Í

How to deploy and scale your meteor apps

Embed Size (px)

Citation preview

Page 1: How to deploy and scale your meteor apps

Í

M E T E O R ( H T T P S : / / B L O G . D E S I G N V E L O P E R . C O M / C A T E G O R Y / M E T E O R / )Û

Í

Page 2: How to deploy and scale your meteor apps

How To Deploy And Scale Your Meteor Apps

FYI:

This is one of two topics of our 2nd Meteor Meetup on July 9th, 2016. The author is Tai Nguyen, a young talent member of Designveloper.

I believe that you already had a good preparation after digesting our previous blog What To Consider Before Deploying A Meteor App

(https://blog.designveloper.com/2016/07/25/what-to-consider-before-deploying-a-meteor-app/), right? Now, it’s time to get your hands dirty. Ready? I’m

going to show you how to bring your app into practice.

S t e p 1 : C r e a t e S e r v e r s

To begin with, I create 4 servers in AWS (Amazon Web Service) with 4 different IP addresses:

I have chosen the domain which is www.ami.com (http://www.ami.com) for the app. I use MongoDB because it is the default database of Meteor. There we’ve

got:

MONGODB: 54.174.9.184, 54.174.9.185, 54.174.9.186, 54.174.9.187.

METEOR APP: 54.174.9.188 (sever-1.ami.com), 54.174.9.189 (server-2.ami.com), 54.174.9.190 (server-3.ami.com), 54.174.9.191 (server-4.ami.com)

S t e p 2 : I n s t a l l M o n g g o D B R e p l i c a t i o n

Replication sets provide redundancy and increase data availability on different database servers. Hence, I apply replication to increase the performance of

reading operations.

B y V a n D o ( h t t p s : // b l o g . d e s i g n v e l o p e r . c o m / a u t h o r / v a n d o / ) o n A u g u s t 2 , 2 0 1 6

Í

Page 3: How to deploy and scale your meteor apps

MongoDB Replication

At �rst, I create an admin user following precise instructions on https://docs.mongodb.com/v2.6/tutorial/add-user-administrator/

(https://docs.mongodb.com/v2.6/tutorial/add-user-administrator/) and generate a key-�le by doing exactly guides on

https://docs.mongodb.com/v2.6/tutorial/generate-key-�le/ (https://docs.mongodb.com/v2.6/tutorial/generate-key-�le/)

Next, I apply SSH (Secure Shell) to all of 4 servers and run these following commands

>cd ~/ > mkdir mongodb/ > screen -S mongodb > mongod --dbpath mongodb/ --replSet Ami --auth --keyFile mongo-keyfile

To close terminal session, I use the hotkeys “CTRL + a + d”.

Then I turn 54.174.9.184 into primary MongoDB by running these following commands:

Í

Page 4: How to deploy and scale your meteor apps

> mongo > use admin > db.auth(‘admin’, ‘password’) > rs.initiate() > rs.add(‘54.174.9.185:27017’) > rs.add(‘54.174.9.186:27017’) > rs.add(‘54.174.9.187:27017’)

S t e p 3 : S e t u p y o u r a p p l i c a t i o nIn order to set up the app, the �rst thing I need to do is to install meteor up by using npm. Below is the command line to use:

> npm install -g mup

Setting up is a must. To do this, use the cd path command to go to the folder which contains settings �le of the application:

> cd path/to/settings > mup init

This is how I scale the app. In this �le, I edit mup.json �le by:

Adding servers

Í

Page 5: How to deploy and scale your meteor apps

{

"host": "server-1.ami.com",

"username": "ubuntu",

"pem": "./ssh.pem",

"env": {

"CLUSTER_ENDPOINT_URL": "https://server-1.ami.com",

"CLUSTER_BALANCER_URL": "https://server-1.ami.com"

}

},

{

"host": "server-2.ami.com",

"username": "ubuntu",

"pem": "./ssh.pem",

"env": {

"CLUSTER_ENDPOINT_URL": "https://server-2.ami.com",

"CLUSTER_BALANCER_URL": "https://server-2.ami.com"

}

},

{

"host": "server-3.ami.com",

"username": "ubuntu",

"pem": "./ssh.pem",

"env": {

"CLUSTER_ENDPOINT_URL": "https://server-3.ami.com",

"CLUSTER_BALANCER_URL": "https://server-3.ami.com"

}

},

{

"host": "server-4.ami.com",

"username": "ubuntu",

"pem": "./ssh.pem",

"env": {

"CLUSTER_ENDPOINT_URL": "https://server-4.ami.com",

"CLUSTER_BALANCER_URL": "https://server-4.ami.com"

}

},

}

Adding MONGO_URL

Í

Page 6: How to deploy and scale your meteor apps

MONGO_URL is one of environment variables in Meteor (https://www.meteor.com/), which is used for connecting to Mongo in production environment. To add

MONGO_URL, I run the following command:

Enable OPLOG

Oplog or operation log is a special collection that records all the write operations as they are applied to the database (you can �nd more helpful information at:

https://github.com/meteor/docs/blob/version-NEXT/long-form/oplog-observe-driver.md (https://github.com/meteor/docs/blob/version-NEXT/long-

form/oplog-observe-driver.md))

The command used to enable Oplog is as followed:

S t e p 4 : D e p l o yAre you done all of these above steps? Let’s move to deploy our app. Firstly, I go to settings folder of the app.

Setup servers when using MUP for the �rst time

> mup setup

Bundle your project and deploy to servers

> mup deploy

So far, I have deployed my app successful. MUP also support other useful commands to maintain your production app. After you’ve edited environmental

variables of settings.json , you can recon�gure the app without deploying again:

> mup reconfig

Check out other useful commands:

{

“MONGO_URL" : "mongodb://lumin:[email protected]:27017, 54.174.9.185:27017, 54.174.9.186:27017, 54.174.9.187:27017/Ami?replicaSet=Ami"

}

{ MONGO_OPLOG_URL: ‘mongodb://lumin:[email protected]:27017, 54.174.9.185:27017, 54.174.9.186:27017, 54.174.9.187:27017/ local?authSource=admin

}

Í

Page 7: How to deploy and scale your meteor apps

> mup stop # stop all servers > mup start # start all servers > mup restart # stop all running servers and start it again

Congratulation! Your Meteor app is now ready to dance to your tune. Keep an eye out for our further blog on Meteor tutorials and you will �nd out more helpful

information. I would love to know whether you deploy your app successfully or not in the comments below.

Í