Table of contents
Introduction
Grafana is a powerful open-source tool that helps you visualize and analyze data from various sources. It’s widely used in DevOps and IT to monitor systems and gain insights. In this guide, we’ll take you through the steps to set up Grafana on an AWS EC2 instance. Whether you’re new to Grafana or cloud computing, this easy-to-follow guide will help you get started.
Step 1 : Create an AWS Account
If you don’t already have an AWS account, you’ll need to create one. Here’s how:
Go to AWS’s website and click on “Create an AWS Account.”
Follow the instructions to set up your account. AWS offers a free tier for new users, which gives you limited free access to many AWS services for 12 months.
Step 2 : Launch an EC2 Instance
Amazon Elastic Compute Cloud (EC2) provides scalable computing capacity. To run Grafana, we need to launch an EC2 instance. Here’s how:
Log in to AWS Management Console:
- After logging in, find and click on “EC2” under the “Compute” section.
Launch Instance:
- Click on the “Launch Instance” button to start the setup process.
Choose an Amazon Machine Image (AMI):
- Select the Amazon Linux 2 AMI (Amazon Machine Image). This image is free-tier eligible and works well for our needs.
Choose an Instance Type:
- Select the “t2.micro” instance type. This is also free-tier eligible and sufficient for our setup.
Configure Instance Details:
- Click “Next: Configure Instance Details.” You can leave the default settings as they are.
Add Storage:
- Click “Next: Add Storage.” The default settings are usually fine, so you can proceed to the next step.
Add Tags:
- Tags are optional, but they can help you organize your resources. Click “Next: Add Tags” to continue.
Configure Security Group:
Security groups control the traffic to your instance. Create a new security group with the following rules:
Type: SSH, Protocol: TCP, Port Range: 22, Source: Anywhere
Type: HTTP, Protocol: TCP, Port Range: 80, Source: Anywhere
Type: HTTPS, Protocol: TCP, Port Range: 443, Source: Anywhere
Click “Review and Launch” to proceed.
Review and Launch:
- Review your settings and click “Launch.” You’ll be prompted to select an existing key pair or create a new one. This key pair is used to securely connect to your instance. Make sure to download and save the key pair file (.pem) as you will need it to connect to your instance.
Step 3 : Connect to Your EC2 Instance
Once your instance is running, you need to connect to it:
Find Your Instance:
- In the EC2 dashboard, select your instance and click “Connect.”
Connect via SSH:
Open your terminal (or use an SSH client) and run the provided SSH command. It will look something like this:
ssh -i "your-key-pair.pem" ec2-user@your-ec2-public-dns
Replace "your-key-pair.pem" with the path to your key pair file and "your-ec2-public-dns" with your instance’s public DNS.
Step 4 : Install Grafana
Now that you’re connected to your EC2 instance, it’s time to install Grafana:
Update Your System:
Run the following command to update your system packages:
sudo yum update -y
Add Grafana Repository:
Add the Grafana repository to your system:
sudo tee /etc/yum.repos.d/grafana.repo <<EOF [grafana] name=grafana baseurl=https://packages.grafana.com/oss/rpm repo_gpgcheck=1 enabled=1 gpgcheck=1 gpgkey=https://packages.grafana.com/gpg.key EOF
Install Grafana:
Install Grafana using the following command:
sudo yum install grafana -y
Start and Enable Grafana:
Start the Grafana service and enable it to start on boot:
sudo systemctl start grafana-server sudo systemctl enable grafana-server
Step 5 : Configure Firewall Rules
To ensure Grafana is accessible, you need to configure the firewall:
Allow Grafana Port:
By default, Grafana runs on port 3000. Allow this port through the firewall:
sudo firewall-cmd --zone=public --add-port=3000/tcp --permanent sudo firewall-cmd --reload
Step 6 : Access Grafana
With Grafana installed and running, you can now access it:
Open Grafana in Your Browser:
- Open your web browser and navigate to
http://your-ec2-public-dns:3000
. Replace "your-ec2-public-dns" with your instance’s public DNS.
- Open your web browser and navigate to
Login to Grafana:
- The default username is
admin
and the default password isadmin
. You’ll be prompted to change the password upon first login.
- The default username is
Step 7 : Set Up Your First Dashboard
Now that you’re logged into Grafana, you can set up your first dashboard:
Add a Data Source:
- Click on “Add your first data source” and select the type of data source you want to use (e.g., Prometheus, InfluxDB, etc.). Follow the prompts to configure your data source.
Create a Dashboard:
- After adding the data source, click on “Create your first dashboard.” You can add various panels to visualize data from your data source.
Customize Your Dashboard:
- Explore Grafana’s features to customize your dashboard. You can add multiple panels, set up alerts, and more.
Conclusion
Congratulations! You have successfully set up Grafana on an AWS EC2 instance. Grafana is a powerful tool for monitoring and visualizing data. With this setup, you can create custom dashboards to gain insights into your systems. Continue exploring Grafana’s features to make the most out of this versatile platform.