10x Developer
  • Introduction
  • HTML
    • HTML DOM Jquery
    • HTML: Form
    • CSS
    • CSS Layout
    • CSS Flexbox
    • CSS Grid
    • SASS/LESS
    • CSS/LESS/SASS Cookbook
    • Bootstrap
  • JavaScript
    • JavaScript
    • ES6
    • TypeScript
    • JavaScript Testing
    • JavaScript Event Loop
    • DOM
    • Web APIs
    • JSON
    • RegEx
    • Functional Programming
    • JavaScript Lib
    • CoffeeScript
    • CoffeeScript to ES6 cheatsheet
  • Angular.js
    • Angular
    • Angular Cookbook
    • Angular Mistakes I Made
    • Angular 1.x
  • React.js
    • React.js
  • Node
    • Node.js
    • CLI command line tool
    • Electron / Atom
    • NW.js (node-webkit)
  • Serverless
    • AWS Lambda
    • Google Cloud Function
    • Actions on Google / Google Assistant
  • Full Stack Development
    • HTTP
    • Meteor
    • MongoDB
    • Digital Ocean
    • UI
    • Sketch
    • Web Dev Resources
  • Lang
    • Ruby
  • Know Your Tools
    • Chrome DevTools
    • Editor: VS Code
    • Editor: Vim
    • Editor: Sublime
    • Editor: Atom
    • Windows
    • Git
    • Linux / Bash
    • Mac
  • Cheatsheets
Powered by GitBook
On this page
  • Droplet Setup (Ubuntu) for Node.js App (Meteor etc)
  • MongoDB
  • SSL
  • How to check?
  • (LATEST 2021) With Mup you don't need to do manual setup SSL anymore
  • Setup SSL using mupx and Let’s Encrypt
  1. Full Stack Development

Digital Ocean

PreviousMongoDBNextUI

Last updated 4 years ago

Use this to register Digital Ocean with $10 credit.

Droplet Setup (Ubuntu) for Node.js App (Meteor etc)

  • follow

  • Follow mup guide:

    And you also need to add NOPASSWD to your sudoers file. Open it with:
    
      sudo visudo
      Then, replace the line that says %sudo ALL=(ALL) ALL with
    
      %sudo ALL=(ALL) NOPASSWD:ALL
  • Add Public Key to New Remote User, by follow

    • disable root access, change port(using the same guide by editing '/etc/ssh/sshd_config')

  • follow

  • add fail2ban by:

  • Don't need to add swap when using SSD

  • Use to only do security updates (Otherwise when you do apt-get upgrade it'll update your version to Non-LTS version!)

Optional:

change editor to use vi sudo update-alternatives --config editor

References:

If you want nginx support:

MongoDB

automatic backup

#!/bin/bash

MONGO_DATABASE="USE_YOUR_APP_NAME"
APP_NAME="USE_YOUR_APP_NAME"

MONGO_HOST="127.0.0.1"
MONGO_PORT="27017"
TIMESTAMP=`date +%F-%H%M`
MONGODUMP_PATH="/usr/local/bin/mongodump"
BACKUPS_DIR="./backups/$APP_NAME"
BACKUP_NAME="$APP_NAME-$TIMESTAMP"

# mongo admin --eval "printjson(db.fsyncLock())"
# $MONGODUMP_PATH -h $MONGO_HOST:$MONGO_PORT -d $MONGO_DATABASE
$MONGODUMP_PATH -d $MONGO_DATABASE
# mongo admin --eval "printjson(db.fsyncUnlock())"

mkdir -p $BACKUPS_DIR
mv dump $BACKUP_NAME
tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tgz $BACKUP_NAME
rm -rf $BACKUP_NAME

crontab:

# run every day at 12am
00 00 * * * path/backup_mongodb.sh

How to manually backup or restore

mongodump -d dbname 
#or 
mongodump --port 3001 --username meteor 
mongorestore --port 3001 -d meteor FOLDER_THAT_HAS_BSON_FILES

Oplog

How to enable oplog if the db is already in use?

ref:

SSL

How to check?

sudo ssl-cert-check -c /etc/letsencrypt/live/yourdomain.tld/cert.pem

Steps

Make sure A record is already updated for your domain first

SSH to server:

  # ssh to your server
  git clone https://github.com/letsencrypt/letsencrypt
  ./letsencrypt-auto certonly --standalone --agree-tos --email YOUR_EMAIL -d YOURDOMAIN.COM -d www.YOURDOMAIN.COM

The following 4 files will be generated in the archive folder: /etc/letsencrypt/archive/YOURDOMAIN.COM (Note the ones in /etc/letsencrypt/live/YOURDOMAIN.COM is symlinked to archive folder)

  • cert1.pem

  • chain1.pem

  • fullchain1.pem

  • privkey1.pem

Now we want to copy those files to your local machine:

  # compress them on server first
  sudo tar -cvvf letsencrypt_YYYY_MM_DD.tar /etc/letsencrypt/archive/YOURDOMAIN.COM
  # then on your local terminal, use scp to get the above file, copy to home folder
  scp -P 22 USER@IP:/home/USER/letsencrypt_YYYY_MM_DD.tar ~
  # or

Put the downloaded two files (fullchain.pem and privkey.pem) in your local folder where mup can access (see mup.json)

Update mup.json

   “ROOT_URL”: “https://yourdomain.com",
   ...
   "ssl": {
    "certificate": "PATH_TO/fullchain.pem", // this is a bundle of certificates
    "key": "PATH_TO/privkey.pem", // this is the private key of the certificate
    "port": 443 // 443 is the default value and it's the standard HTTPS port
  },

Don't forget to add force-ssl package: meteor add force-ssl

Renew automatically

NOTE this will NOT work because the server has to be stopped

Let’s Encrypt expires 90 days, so we create cron job to automatically update:

  30 2 * * 1 /home/USER/letsencrypt/letsencrypt-auto renew >> /var/log/le-renew.log

To renew manually

  # on dev machine, stop server:
  mupx stop
  # on server
  /home/USER/letsencrypt/letsencrypt-auto renew
  # above command will generate new files (cert2.pem etc), get the files to local machine
  # by doing the same steps above: 'sudo tar -cvvf ...' (see above)
  mupx setup
  mupx deploy

Key points:

  • You need to stop server before running renew.

  • if cert is expired, you need to run mpux setup again

  • if you run letsencrypt renew, new files will be generated (such as cert2.pem)

    • cert.pem: Your domain's certificate

    • chain.pem: The Let's Encrypt chain certificate

    • fullchain.pem: cert.pem and chain.pem combined

    • privkey.pem: Your certificate's private key

Reference:

  • )

Additional:

(which automatically use nginx, you don't need to setup anything)

More security setup from this :

(outdated: it's using mongodb 2.4)

Online tool:

Or use ssl-cert-check on server ():

(LATEST 2021) With you don't need to do manual setup SSL anymore

Setup SSL using and

maybe try this?

first read this [guide](

link
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-14-04
https://gist.github.com/jamiewilson/4e1d28f9a200cb34ad59#set-up-ssl
https://www.digitalocean.com/community/questions/what-is-the-effect-of-permitrootlogin-no
https://www.digitalocean.com/community/tutorials/additional-recommended-steps-for-new-ubuntu-14-04-servers
https://www.digitalocean.com/community/tutorials/how-to-protect-ssh-with-fail2ban-on-ubuntu-14-04
unattended-upgrades
http://julian.io/how-do-i-host-multiple-meteor-apps-on-one-digitalocean-droplet/
https://gist.github.com/jamiewilson/4e1d28f9a200cb34ad59#add-some-swap-space
mup doc
digital ocean guide
linux workstation checklist
Make sure root mail is forwarded to an account you check
http://stackoverflow.com/questions/11024888/is-there-a-simple-way-to-export-the-data-from-a-meteor-deployed-app/16380978#16380978
https://github.com/meteor/meteor/wiki/Oplog-Observe-Driver
https://gentlenode.com/journal/meteor-10-set-up-oplog-tailing-on-ubuntu/17
https://www.digitalocean.com/community/tutorials/how-to-implement-replication-sets-in-mongodb-on-an-ubuntu-vps
https://www.sslshopper.com/ssl-checker.html
reference
Mup
mupx
Let’s Encrypt
https://cuonic.com/posts/automating-lets-encrypt-certificate-renewal
https://medium.com/@getdrizzle/deploying-meteor-app-with-free-ssl-certificate-mupx-letsencrypt-digital-ocean-7c85d90cc731#.ty1lahoh9
https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-14-04
https://forums.meteor.com/t/setting-up-ssl-with-letsencrypt-and-meteorup/14457
How to create a self-signed SSL Certificate