DEV Community

Randika Madhushan Perera
Randika Madhushan Perera

Posted on

Guide to Installing and Configuring Grafana on AWS EC2 with MySQL Database Integration

Section 01: Setting Ip AWS EC2 Instances

  1. Login to AWS Management Console: Navigate to the EC2 dashboard.
  2. Launch Instance: Click on "Launch Instance" and choose an AMI (Amazon Machine Image) based on your preferred OS.
  3. Instance Type: Select an appropriate instance type (e.g., t2.micro for testing).
  4. Configure Instance Details: Set network and subnet. Ensure Auto-assign Public IP is enabled.
  5. Add Storage: Default settings are usually sufficient for Grafana.
  6. Add Tags: Optional, for resource identification.
  7. Configure Security Group: Open ports for HTTP (80) and SSH (22) from your IP address.
  8. Review and Launch: Review settings and launch the instance.
  9. Key Pair: Create a new key pair, download it, and keep it secure.

Section 02: Configuring Security Groups in AWS

  1. Edit Inbound Rules: You will need to set inbound rules when creating a connection between the Grafana server and the MySQL server.

Grafana Server Details:
Public IP: 54.67.123.98
Private IP: 172.10.8.1

MySQL Server Details:
Public IP: 54.128.34.56
Private IP: 172.10.8.2

  1. Add below rules:

HTTP 80 172.0.0.0/8
HTTPS 443 172.0.0.0/8
Custom TCP 3000 172.0.0.0/8
MySQL 3306 172.0.0.0/8

Section 03: Installing Grafana Cloud on the EC2 Server

Here I’m using the Amazon Linux 2023 server and I’m going to install Grafana OSS.

  1. Install Grafana from the RPM repository.

To install Grafana from the RPM repository, complete the following steps

1.1 Import the GPD key:

# wget -q -O gpg.key https://rpm.grafana.com/gpg.key
# sudo rpm --import gpg.key
Enter fullscreen mode Exit fullscreen mode

1.2 Create /etc/yum.repos.d/grafana.repo with the following content

[grafana]
name=grafana
baseurl=https://rpm.grafana.com
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://rpm.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
Enter fullscreen mode Exit fullscreen mode

1.3 To prevent beta versions from being installed, add the following exclude line to your .repo file

exclude=*beta*
Enter fullscreen mode Exit fullscreen mode

1.4 To install Grafana OSS, run the following command

# sudo dnf install Grafana
Enter fullscreen mode Exit fullscreen mode
  1. Start the Grafana Server

2.1 Start the Grafana server with systemd

# sudo systemctl daemon-reload
# sudo systemctl start grafana-server
# sudo systemctl status grafana-server
Enter fullscreen mode Exit fullscreen mode

2.2 To verify the service is running, run the following command

# sudo systemctl status grafana-server
Enter fullscreen mode Exit fullscreen mode
  1. Sign in to Grafana

To sign in to Grafana for the first time, follow the steps:

3.1 Open your web browser and go to http://your_public_ip:3000
3.2 On the sign-in page use ‘admin’ for the username and password
3.3 Click sign in and change the password.

Section 04: Create a Connection Between Grafana Server and MySQL Server

Here I have an AWS EC2 RedHat server that installed MySQL.

  1. Create a user called “grafana”
mysql> create user ‘grafana’@Grafana_server_private_IP’ identified by 'password';
Enter fullscreen mode Exit fullscreen mode
  1. Grant privileges
mysql> grant all privileges on database_name.* to ‘grafana’@Grafana_server_private_IP’;
Enter fullscreen mode Exit fullscreen mode
mysql> flush privileges;
Enter fullscreen mode Exit fullscreen mode

Section 05: Create a Data source in Grafana

Top comments (0)