Sanchit Dilip Jain/How to deploy Grafana on Amazon Ec2? ๐Ÿš€

Created Sun, 14 Feb 2021 12:00:00 +0000 Modified Mon, 12 Aug 2024 09:03:58 +0000
440 Words 2 min

Deploy Grafana

Introduction Grafana is open-source software famous for creating graphs and visualizations for end-users to articulate the time-series data. In this tutorial, we will focus on the following steps and it will carry out on an EC2 Instance with Amazon Linux 2 as the operating system

  • Provisioning Ec2 server
  • Installation of Grafana
  • Testing the setup
  • Adding Data Source in the Grafana
  • Testing CloudWatch as a Data Source

Step 1 - Provisioning Ec2 server

  • Launch an Amazon Linux 2 AMI EC2 Instance with the below configuration

    • AWS AMI for Ec2

    image

    • Security Group for Ec2

    image2

    Note: Avoid opening port to anywhere i.e. 0.0.0.0/0

    • IAM policy for Ec2

    image11

    • Storage & Tags for Ec2

    image3

    • Let’s verify if Ec2 is deployed successfully

    image4

Step 2 - Installation of Grafana

  • SSH into your Ec2 instance
ssh -i "<pemfile_name>" ec2-user@publicdns_of_ec2

image5

  • Now let’s update all installed packages in the Ec2 instance
sudo yum update -y
  • Now we will add a new entry in the YUM repository to download Grafana
sudo vi /etc/yum.repos.d/grafana.repo
  • Copy the below lines and paste them as is in the grafana.repo
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
  • Finally, we are ready to install Grafana
sudo yum install grafana -y
  • Reload the systemd to load the new settings. Start Grafana Server, then check for its status
sudo systemctl daemon-reload
  • Start the Grafana Server
sudo systemctl start grafana-server
  • Check the status of Grafana Server
sudo systemctl status grafana-server

![image6](/images/deploy-grafana-ec2/image6.png)
  • Run the command below to make sure that Grafana will start upon booting our Amazon Linux 2 instance
sudo systemctl enable grafana-server.service

Step 3 - Testing the setup

  • Enter the Public DNS of Ec2 instance with port 3000 in the browser and it will redirect you to the login screen of Grafana

image7

  • Default username & password will be admin and on the first login, Grafana will require to change the admin password

image8

  • Now you will move to the default Welcome Grafana page and here we can add Data Sources, Dashboards, Users or Explore plugins and many more

image9

  • We have now successfully installed Grafana on EC2 Instance running in Amazon Linux 2

image10

Step 4 - Adding Data Source in the Grafana

  • Click on Configuration » Data Sources

image12

  • Click on Add data source.

image13

  • Search for CloudWatch and click Select

image14

  • Under CloudWatch settings, add Name and Default Region. Then click Save & Test.

image15

Note: You can also use the following Auth Provider to access CloudWatch via IAM Role.

image16

Step 5 - Testing CloudWatch as a Data Source

  • Let’s create a new dashboard with Cloudwatch as a source

image17

  • Green spike on the Graph means Grafana Server can successfully access CloudWatch via the attached IAM Role of the EC2 Instance.