Hi!!! This blog post is to narrate my experience and insights with my first task as an HNG intern. The task is quite simple and straight-forward, however, the lessons learned are invaluable.Ready????? Let's get to it.
What you will learn:
In this article, you will learn how to:
Provision a server and install a Linux distribution of your choice on a cloud platform (AWS)
Set up a web server (Nginx) to serve web content.
Deploy a simple HTML page.
Configure networking to allow HTTP traffic.
Let's get started!
Provisioning a server and installing a Linux distribution
- First, go to the AWS website (https://aws.amazon.com/) and log in to your AWS account. If you don't have an account, you'll need to create one. Once logged in, you'll see the AWS Management Console. In the search bar at the top, type "EC2" and select the "EC2" service.
- On the EC2 dashboard, click the launch Instances button. This starts the instance launch wizard.
2.Choose an Amazon Machine Image (AMI)
.
An AMI is a template that contains the operating system and software configuration for your server.
Choose your preferred Linux distribution; let's use Ubuntu.
4.Choose an Instance Type
: The instance type determines the hardware resources allocated to your server (CPU, memory, storage).
- For testing and simple web prototypes, the
t2.micro
instance type is often sufficient and eligible for the AWS Free Tier (if you're eligible). Selectt2.micro
or another instance type that meets your needs.
5.Select or Create a Key Pair
A key pair is used to securely connect to your instance via SSH.
If you don't have one, create a new key pair.
Give it a name (eg.
hng.pem
).Download the
.pem
file. This is extremely important. Store this file in a secure location. You will need it to connect to your instance.
6.Configure your instance details
Number of instances: Set this to
1
for this exercise.Subnet: Select a subnet within your VPC. If you're using the default VPC, choose a
public subnet
.Auto-assign Public IP: Make sure this is enabled. This will give your instance a public IP address so you can access it from the internet.
Leave other settings at their defaults unless you have specific requirements.
7.Configure Security Group
A
security group
acts as a virtual firewall for your instance, controlling inbound and outbound traffic.Create a new security group or select an existing one.
Add the following inbound rules:
Type:
SSH
, Port Range:22
, Source:My IP
(This is the most secure option. It allows SSH access only from your current IP address. If you need to access from other locations, you can specify a wider IP range or0.0.0.0/0
(less secure, allows access from any IP address).Type:
HTTP
, Port Range:80
, Source:0.0.0.0/0
(This allows HTTP traffic from any IP address, making your website publicly accessible).
9.Connect to Your Instance
After launching the instance, you'll be taken to the EC2 Instances dashboard. It might take a few minutes for the instance to start.
Select your instance and copy its Public IPv4 address.
Open a terminal or SSH client (like PuTTY on Windows, or the built-in terminal on macOS/Linux). We will use our Linux terminal.
Use the following command:
ssh -i /path/to/your/key.pem ubuntu@[your_instance_public_ip]
For example:
ssh -i ~/Downloads/hng.pem ubuntu@54.172.49.241
Congratulations! You have now provisioned a server on AWS. You should be connected to your Ubuntu instance via SSH.
Set up a web server
We will use Apache in this instance. To install Nginx, we first need to update our packages. Input this command:
sudo apt update
Then install Nginx:
sudo apt install nginx -y
Congratulations! You have set up your web server.
To ensure your nginx is enabled, input the following comands:
sudo systemctl start nginx
sudo systemctl enable nginx
Input the public ip address of your ec2 instance and paste it in any browser of your choice. The Nginx page should be displayed.
Deploy a simple HTML page
To deploy our html page, we can create one on our terminal using this command:
sudo nano/var/www/html/index.html
This command takes you to an html page already on Nginx, you just have to format the template to your taste and save it. Type ctrl+o
to save your html content. Hit ctrl+x
to exit.
Refresh your browser where you pasted the public ip address of your ec2 instance.
Challenges
This task has helped me sharpen deployment skills as a DevOps newbie.
My main challenge was trying to connect to my ec2 instance, as I made errors writing the appropriate command. In the end, I figured it out.
In addition, this project has put me in the right path to start my journey as a Cloud/DevOps engineer.
Thanks for reading, watch this space for more articles and projects.
Top comments (0)