Navigate here for additional information on AWS
Creating an Instance
Adding Security Groups
What are Node Modules?
Extended documentation here
- Git clone this repository:
$ git clone git@github.com:naistangz/NodeJSAWS_Deploy_Code.git
- Navigate to
NodeJSAWS_Deploy_Code
folder:
$ cd NodeJSAWS_Deploy_code
- Run the file
alias run='./setup.sh
$ run
- 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)?
- 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.
- Create
DB
directory - In
DB
directory, createmongod.service
andmongo.conf
files - 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
- Create an EC2 Instance for MongoDB Server.
- Create a security group in order to allow inbound rules from the app server (instance).
- 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
- Run the
provision.sh
script when the DB server is up - To check
mongodb
is installed, run the following command:
sudo systemctl status mongod
- 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
- Type
env
to export IP address then type the following (this can be automated by adding toprovision.sh
)
export DB_HOST=mongodb://34.250.34.22:27017/posts
- Navigate to
cd /app
folder and runnpm install
npm install
- Run
provision.sh
file - Navigate to
cd app/
folder and run app with the following command:
pm2 start app.js -f
- Enter app IP address into browser to check if
/posts
is working
🌮