How to install Grafana on Ubuntu

How To Install Grafana On Ubuntu 20.04 LTS

On this article, we will discuss how to install Grafana (Open Source Edition) on Ubuntu 20.04 LTS, and configuring itu by using the Prometheus as datasources.

Introduction

When we manage so much infrastructure in our premises: servers, storage, switches, routers, etc. then we need a tool that can help us to monitor our devices in detail and give alerts if an anomaly occurs in our system. We need tools that are truly reliable and responsive. Grafana is an open source application that can fulfill our needs to be able to monitor the system efficiently. Grafana is a multi-platform open source analytics and interactive visualization web based application. Grafana provides charts, graphs, and alerts, ussually when it is connected to supported data sources (Graphite, Elasticsearch, OpenTSDB, Prometheus, and InfluxDB).

On this article source, we will use the Grafana version 7.1.5 (the latest version when this article is being written) which was released on August 25, 2020.

Grafana 7.1.5 Whats new

The Grafana version 7.1.5 has several new features :

  • Flux and InfluxDB 2.x support in the Influx Datasource
  • Query history search
  • Unification of Explore modes
  • Elasticsearch- link to another data source from Explore
  • Merge on time transform for the new table panel
  • Stat panel text mode
  • Time range picker update
  • Provisioning of apps
  • Azure Monitor Datasource
  • Deep linking for Google Cloud Monitoring (formerly named Google Stackdriver) datasource
  • Grafana Enterprise features
    • Secret management with HashiCorp Vault
    • Monthly schedules in reports

Grafana Installation on Ubuntu 20.04 LTS

The Grafana installation on Ubuntu 20.04 LTS will take several steps and there is prerequisite to be fulfilled first. We will use the Ubuntu official APT repository as our Grafana package source. The installation processes will be divided into several steps below :

  1. Prerequisite
  2. Install Grafana on Ubuntu 20.04
  3. Open Port on Firewall (Optional)
  4. Access Grafana Dashboard on Ubuntu

Prerequistie

Before continuing Grafana installation, we have to prepare our Ubuntu 20.04 (Focal Fossa) environment first. Grafana installation has requirement as follow :

  • user with sudo either as root privileges,
  • sufficient space (Grafanan requires about 170 MB dsik space)
  • good internet connection for downloading required package
  • the last update system, this step could be acvhieved by submitting command line sudo apt update

Install Grafana on Ubuntu 20.04

  1. Add Grafana Repository

Add Grafana gpg key to the system, this step will enable us to install signed packages.

ramans@otodiginet:~$ sudo apt-get install -y gnupg2 curl software-properties-common
ramans@otodiginet:~$ curl https://packages.grafana.com/gpg.key | sudo apt-key add -
ramans@otodiginet:~$ sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"

2. Installing Grafana

After Grafana repository was added, then we update the Ubuntu system again to ensure if the new package was updated. After that, we submit the installation.

ramans@otodiginet:~$ sudo apt-get update
ramans@otodiginet:~$ sudo apt-get -y install grafana

The output will be as follow :

The following NEW packages will be installed:
grafana
0 upgraded, 1 newly installed, 0 to remove and 262 not upgraded.
Need to get 52.7 MB of archives.
After this operation, 170 MB of additional disk space will be used.
Get:1 https://packages.grafana.com/oss/deb stable/main amd64 grafana amd64 7.1.5 [52.7 MB]
Fetched 9,938 kB in 56s (177 kB/s)
Selecting previously unselected package grafana.
(Reading database … 258648 files and directories currently installed.)
Preparing to unpack …/grafana_7.1.5_amd64.deb …
Unpacking grafana (7.1.5) …
Setting up grafana (7.1.5) …
Adding system user grafana' (UID 128) ... Adding new usergrafana' (UID 128) with group grafana' ... Not creating home directory/usr/share/grafana'.
NOT starting on installation, please execute the following statements to configure grafana to start automatically using systemd
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable grafana-server
You can start grafana-server by executing
sudo /bin/systemctl start grafana-server

3. Enable Grafana Service

After installation was completed done, then we enable and reload the Grafana service. These steps are to ensure if the Grafana services was running properly and can be accessed.

ramans@otodiginet:~$ sudo /bin/systemctl daemon-reload
ramans@otodiginet:~$ sudo /bin/systemctl enable grafana-server
ramans@otodiginet:~$ sudo systemctl enable --now grafana-server
Grafana services reload and enable

After all services are looks OK, than we verifty if the Grafana services is running well by submitting command line below :

ramans@otodiginet:~$ sudo systemctl status grafana-server
ramans@otodiginet:~$ sudo systemctl status grafana-server
● grafana-server.service - Grafana instance
Loaded: loaded (/lib/systemd/system/grafana-server.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-09-10 08:53:55 PDT; 14s ago
Docs: http://docs.grafana.org
Main PID: 12749 (grafana-server)
Tasks: 11 (limit: 4624)
Memory: 18.8M
CGroup: /system.slice/grafana-server.service
└─12749 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/var/run/gr>
Sep 10 08:53:56 otodiginet grafana-server[12749]: t=2020-09-10T08:53:56-0700 lvl=info msg="Executing >
Sep 10 08:53:56 otodiginet grafana-server[12749]: t=2020-09-10T08:53:56-0700 lvl=info msg="Executing >
Sep 10 08:53:56 otodiginet grafana-server[12749]: t=2020-09-10T08:53:56-0700 lvl=info msg="Executing >
Sep 10 08:53:56 otodiginet grafana-server[12749]: t=2020-09-10T08:53:56-0700 lvl=info msg="Executing >
Sep 10 08:53:56 otodiginet grafana-server[12749]: t=2020-09-10T08:53:56-0700 lvl=info msg="Executing >
Sep 10 08:53:56 otodiginet grafana-server[12749]: t=2020-09-10T08:53:56-0700 lvl=info msg="Created de>
Sep 10 08:53:56 otodiginet grafana-server[12749]: t=2020-09-10T08:53:56-0700 lvl=info msg="Starting p>
Sep 10 08:53:56 otodiginet grafana-server[12749]: t=2020-09-10T08:53:56-0700 lvl=info msg="Registerin>
Sep 10 08:53:56 otodiginet grafana-server[12749]: t=2020-09-10T08:53:56-0700 lvl=info msg="External p>
Sep 10 08:53:56 otodiginet grafana-server[12749]: t=2020-09-10T08:53:56-0700 lvl=info msg="HTTP Serve>
Grafana serices status

4. Verifying Grafana version

We also could verify the Grafana version that is running on our system by submitting command line below :

ramans@otodiginet:~$ grafana-server -v
Version 7.1.5 (commit: 9893b8c53d, branch: HEAD)
Grafana version 7.1.5 installed
Grafana version 7.1.5

Open Port on Firewall

Grafana uses default http port on port 3000, we have to allow this port for enabling the access from external IP segment. For this purpose we can use the Ubuntu ufw firewall command line.

ramans@otodiginet:~$ sudo ufw enable
Firewall is active and enabled on system startup
ramans@otodiginet:~$ sudo ufw allow ssh
Rule added
Rule added (v6)
ramans@otodiginet:~$ sudo ufw allow 3000/tcp
Rule added
Rule added (v6)
Enable port 3000 for Grafana

So far, we have configured all necessary steps for Grafana installation. The next step is testing if the installation was quite succesfsully completed. We will hit the Grafana dashboad web for the first time.

Accessing Grafana

We will access the Grafana dasboard by using its IP Address. The format is as follow http://ip_address:3000.

Grafana dasboard
Grafana dasboard for the first time

For the firstime, we use the username : admin and passord : admin, then Grafana force us to immediately change the password.

Using Prometheus Data source

We have installed the Prometheus on the system, and we will try to use the Prometheus as datasource of our new fresh Grafana.

We used Pometheus datasource on port 9090 as Grafana data source. Then we can see on the dasboard if the data coming from Prometheus was already there, so easy to configure.

Conclussion

On this article we have disucessd how to install Grafana on Ubuntu 20.04 LTS and then we configure the Prometheus data source and showing it on the dashboard. Please drop your comment or your though about this article. Have a nice day.

Share this article via :

Leave a Reply

Your email address will not be published. Required fields are marked *