This walkthrough will skip how to launch an EC2 instance. There's plenty of resources and tutorial on how to do that. In this case we are launching a EC2 instance with t2.micro.
After EC2 instance has successfully spinned up, SSH into EC2 instance.
-
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
-
. ~/.nvm/nvm.sh
-
nvm install --lts
npm install yarn -g
Follow instruction: https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-amazon/
-
sudo nano /etc/yum.repos.d/mongodb-org-6.0.repo
- Copy paste the following into the file you just created above:
Ctrl+X to exit, press Y to save the file.[mongodb-org-6.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/amazon/2/mongodb-org/6.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc
-
sudo yum install -y mongodb-org
-
sudo systemctl start mongod
-
sudo systemctl status mongod
-
sudo systemctl enable mongod
sudo yum install git -y
npm install pm2 -g
Two ways to setup:
-
npm install -g outerbridge
-
npx outerbridge start
- App is now ready on port 3000.
- To view the app, create 2 new inbound rules on the EC2 instance. Custom TCP Port 3000 that allows anywhere to access.
- You can then view the app: "Your Public IPv4 DNS":3000. Example: http://ec2-18-222-246-22.eu-west-1.compute.amazonaws.com:3000
-
git clone https://github.com/Outerbridgeio/Outerbridge.git
-
cd Outerbridge
-
yarn setup
-
Depending on your RAM size, for t2.micro this could take a while.yarn bootstrap
-
yarn build
-
yarn start
- App is now ready on port 3000.
- To view the app, create 2 new inbound rules on the EC2 instance. Custom TCP Port 3000 that allows anywhere to access.
- You can then view the app: "Your Public IPv4 DNS":3000. Example: http://ec2-18-222-246-22.eu-west-1.compute.amazonaws.com:3000
In cases where t2.micro is taking forever on yarn bootstrap
, here is the workaround:
- Install the dependencies of each package independently.
cd
into each package:ui
,components
andserver
and doyarn install
for each of them. - Back to the Outerbridge root path, do
yarn bootstrap
. Because the dependencies have been installed, the operation could be faster.
Most of the time, it is stuck at building the ui
folder. As a temporary workaround:
- Back to your EC2 home path (/home/ec2-user/) and do
git clone https://github.com/Outerbridgeio/OuterbridgeUIBuild.git
- Copy the build folder to Outerbridge ui folder:
cp -r OuterbridgeUIBuild/build/ Outerbridge/packages/ui/
-
cd Outerbridge
- Build
server
andcomponents
independently.cd
into package:components
andserver
and doyarn build
for each of them. - Back to the Outerbridge root path, do
yarn start
to see if app can be started.
If you want to get rid of the :3000 on the url and have a custom domain, you can use NGINX to reverse proxy port 80 to 3000. So user will be able to open the app using your domain. Example: http://yourdomain.com
-
Create 2 new inbound rules on the EC2 instance. Custom HTTP Port 80 and HTTPS Port 443 that allows anywhere IVP4 to access. You can proceed to delete the 2 Custom port 3000 TCP inbound rules created earlier.
-
sudo amazon-linux-extras install -y nginx1
-
nginx -v
-
sudo systemctl start nginx
-
sudo nano /etc/nginx/conf.d/outerbridge.conf
-
Copy paste the following and change to your domain:
server { listen 80; listen [::]:80; server_name yourdomain.com; #Example: demo.outerbridge.io location / { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_cache_bypass $http_upgrade; } }
-
sudo systemctl restart nginx
-
Go to your DNS provider, and add a new A record with IP address using Public IPv4 address from EC2 instance.
-
You should now be able to open the app: http://yourdomain.com
If you like your app to have https://yourdomain.com. Here is how:
-
sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
-
sudo yum-config-manager --enable epel
-
sudo yum install certbot python2-certbot-nginx
certbot --version
-
sudo certbot --nginx
- If cert expired, simply renew:
sudo certbot renew --dry-run
- You can now open the app: https://yourdomain.com
You can backup MongoDB database into S3 bucket. Here is the article that can be followed:
-
sudo yum --enablerepo epel install s3cmd
-
s3cmd --configure
-
sudo nano mongo_backup.sh
- Copy paste and replace values:
#!/bin/bash #Force file syncronization and lock writes mongo admin --eval "printjson(db.fsyncLock())" MONGODUMP_PATH="/usr/bin/mongodump" MONGO_DATABASE="dbname_here" #replace with your database name TIMESTAMP=`date +%F-%H%M` S3_BUCKET_NAME="bucketname_here" #replace with your bucket name on Amazon S3 S3_BUCKET_PATH="mongodb-backups" # Create backup $MONGODUMP_PATH -d $MONGO_DATABASE # Add timestamp to backup mv dump mongodb-$HOSTNAME-$TIMESTAMP tar cf mongodb-$HOSTNAME-$TIMESTAMP.tar mongodb-$HOSTNAME-$TIMESTAMP # Upload to S3 s3cmd put mongodb-$HOSTNAME-$TIMESTAMP.tar s3://$S3_BUCKET_NAME/$S3_BUCKET_PATH/mongodb-$HOSTNAME-$TIMESTAMP.tar #Unlock database writes mongo admin --eval "printjson(db.fsyncUnlock())" #Delete local files rm -rf mongodb-*
-
bash mongo_backup.sh
- Go to S3 bucket, you should see a tar file.
- Setup cron
crontab -e
- Copy paste:
#1st of every month at 9 am 00 09 1 * * /bin/bash /home/ec2-user/mongo_backup.sh
- To get the backup:
s3cmd get <s3://link>
- Unzip it:
tar xvf <file.tar>
- Restore it:
mongorestore -d <dbname> -c <collectionname> <dir/file.bson>