Install Grafana

Installation

To install Grafana you can follow the Grafana official documents.

  1. First Identify which Linux OS are you using. To know this, You can hit this command on the terminal cat /etc/*release or cat /etc/os-release

    In my case its RHEL or Fedora, So I am using this install link. https://grafana.com/docs/grafana/latest/setup-grafana/installation/redhat-rhel-fedora/

  2. Import the GPG key.

     sudo wget -q -O gpg.key https://rpm.grafana.com/gpg.key
     sudo rpm --import gpg.key
    
  3. Create sudo vi /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
    
  4. Install the Grafana package sudo dnf install grafana

  5. Now that Grafana is successfully installed its time to start the Grafana service. To do this run these commands.

     sudo systemctl daemon-reload
     sudo systemctl start grafana-server
    
  6. Check if the service is running or not.

     sudo systemctl status grafana-server
    
  7. Configure the Grafana server to start at boot using systems. To configure the Grafana server to start at boot, run the following command:

     sudo systemctl enable grafana-server.service
    

    Sign in to Grafana

    1. To sign in to Grafana use this endpoint http://localhost:3000, So open any browser and enter this URL. Grafana uses 3000 port by default. You can change it from the config file if you want.

    2. On the sign-in page, enter admin for both the username and password.

    3. Click Sign in.

      If successful, you’ll see a prompt to change the password.

    4. Click Submit on the prompt and change your password.

Note

strongly recommended that you change the default administrator password.

After successfully logging in you’ll see something like this

Add DataSource

  1. To Add a data source, under Connections, you can choose either of the options, Add New connection or Data Sources

  2. Choose the appropriate data source. I had installed Prometheus on my local machine so chose, Prometheus.

  3. Now, After choosing the appropriate data source and adding a connection, it’s time to add the proper details of the data source.

    For now, enter the details as shown in the screenshot and click on save test the button. We can add more advanced details but for he understanding this much is enough

  4. We have successfully added data source grafana. To view it navigate to the data source and view the detail

Create Dashboard:

To be created…..

Issues Faced:

Problem: After the installation of Grafana on my Virtual machine, I was not able to access it on my host machine.

Solution: This was due to the firewall rules, I added port 3000 to allow outbound traffic to my host.

sudo firewall-cmd --add-port=3000/tcp --permanent
sudo firewall-cmd --reload

After adding this port, I was able to access the grafana on my host machine.

Knowledge

firewall-cmd Command Cheat Sheet

ActionCommandExample
Check if firewalld is runningfirewall-cmd --statefirewall-cmd --state
List active zonesfirewall-cmd --get-active-zonesfirewall-cmd --get-active-zones
List all open portsfirewall-cmd --list-portsfirewall-cmd --list-ports
List all rules for a zonefirewall-cmd --zone=<zone> --list-allfirewall-cmd --zone=public --list-all
Add a port temporarilyfirewall-cmd --add-port=<port>/<protocol>firewall-cmd --add-port=3000/tcp
Add a port permanentlyfirewall-cmd --add-port=<port>/<protocol> --permanentfirewall-cmd --add-port=3000/tcp --permanent
Remove a port temporarilyfirewall-cmd --remove-port=<port>/<protocol>firewall-cmd --remove-port=3000/tcp
Remove a port permanentlyfirewall-cmd --remove-port=<port>/<protocol> --permanentfirewall-cmd --remove-port=3000/tcp --permanent
Reload firewall rulesfirewall-cmd --reloadfirewall-cmd --reload
List all servicesfirewall-cmd --get-servicesfirewall-cmd --get-services
Allow a service temporarilyfirewall-cmd --add-service=<service>firewall-cmd --add-service=http
Allow a service permanentlyfirewall-cmd --add-service=<service> --permanentfirewall-cmd --add-service=http --permanent
Remove a service temporarilyfirewall-cmd --remove-service=<service>firewall-cmd --remove-service=http
Remove a service permanentlyfirewall-cmd --remove-service=<service> --permanentfirewall-cmd --remove-service=http --permanent
Set a default zonefirewall-cmd --set-default-zone=<zone>firewall-cmd --set-default-zone=public
Add a source IP to a zonefirewall-cmd --zone=<zone> --add-source=<source>firewall-cmd --zone=public --add-source=192.168.1.0/24
Remove a source IP from a zonefirewall-cmd --zone=<zone> --remove-source=<source>firewall-cmd --zone=public --remove-source=192.168.1.0/24
Enable masquerading (NAT)firewall-cmd --zone=<zone> --add-masqueradefirewall-cmd --zone=public --add-masquerade
Disable masqueradingfirewall-cmd --zone=<zone> --remove-masqueradefirewall-cmd --zone=public --remove-masquerade
Rich rule: Add rulefirewall-cmd --zone=<zone> --add-rich-rule='<rule>'firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.1" accept'
Rich rule: Remove rulefirewall-cmd --zone=<zone> --remove-rich-rule='<rule>'firewall-cmd --zone=public --remove-rich-rule='rule family="ipv4" source address="192.168.1.1" accept'
Enable logging for a zonefirewall-cmd --zone=<zone> --set-log-denied=allfirewall-cmd --zone=public --set-log-denied=all
Disable logging for a zonefirewall-cmd --zone=<zone> --set-log-denied=offfirewall-cmd --zone=public --set-log-denied=off