Skip to content

naistangz/NodeJSAWS_Deploy_Code

Repository files navigation

Running a Node JS Application on AWS EC2 Server 🌮 test jenkins # 23

Navigate here for additional information on AWS
Creating an Instance
Adding Security Groups
What are Node Modules?
Extended documentation here

  1. Git clone this repository:
$ git clone git@github.com:naistangz/NodeJSAWS_Deploy_Code.git
  1. Navigate to NodeJSAWS_Deploy_Code folder:
$ cd NodeJSAWS_Deploy_code
  1. Run the file alias run='./setup.sh
$ run
  1. You will see a response like the following:
The authenticity of host 'ec2-198-51-100-1.compute-1.amazonaws.com (198-51-100-1)' can't be established.
ECDSA key fingerprint is l4UB/neBad9tvkgJf1QZWxheQmR59WgrgzEimCG6kZY.
Are you sure you want to continue connecting (yes/no)?
  1. Enter yes
    Which returns the following:
Warning: Permanently added 'ec2-198-51-100-1.compute-1.amazonaws.com' (ECDSA) to the list of known hosts.

Setting up MongoDB Server

  1. Create DB directory
  2. In DB directory, create mongod.service and mongo.conf files
  3. Create provision.sh script to install MongoDB
#!/bin/bash

# be careful of these keys, they will go out of date
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv D68FA50FEA312927
echo "deb https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

sudo apt-get update -y
sudo apt-get upgrade -y

# sudo apt-get install mongodb-org=3.2.20 -y
sudo apt-get install -y mongodb-org=3.2.20 mongodb-org-server=3.2.20 mongodb-org-shell=3.2.20 mongodb-org-mongos=3.2.20 mongodb-org-tools=3.2.20

# remove the default .conf and replace with our configuration

# Here we have changed the path of mongod.conf because ino ur VM there is no environments folder, only a db folder
sudo rm /etc/mongod.conf
sudo ln -s /home/ubuntu/db/mongod.conf /etc/mongod.conf

# if mongo is is set up correctly these will be successful
sudo systemctl restart mongod
sudo systemctl enable mongod
  1. Create an EC2 Instance for MongoDB Server.
  2. Create a security group in order to allow inbound rules from the app server (instance).
  3. In bash, manually run the DB server using the following command:
ssh -i ~/.ssh/DevOpsStudents.pem ubuntu@34.250.34.22 -i ./environment/db/provision.sh
  1. Run the provision.sh script when the DB server is up
  2. To check mongodb is installed, run the following command:
sudo systemctl status mongod
  1. Access the app vm in a new terminal window by running the following command:
ssh -i ~/.ssh/DevOpsStudents.pem ubuntu@3.250.30.246 -i ./environment/app/provision.sh
  1. Type env to export IP address then type the following (this can be automated by adding to provision.sh)
export DB_HOST=mongodb://34.250.34.22:27017/posts
  1. Navigate to cd /app folder and run npm install
npm install
  1. Run provision.sh file
  2. Navigate to cd app/ folder and run app with the following command:
pm2 start app.js -f
  1. Enter app IP address into browser to check if /posts is working

🌮

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published