On this short tutorial, we will discuss how to install Grafana version 7.1.5 on Ubuntu 20.04 LTS and using it with Prometheus datasource.
Introduction
When we manage so much infrastructure on 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. Using Grafana to meet our monitoring needs will be able to answer all of our needs. Grafana is a multi-platform open source analytics and interactive visualization web application. On this tutorial, we will learn how to install Grafana on Ubuntu 20.04 LTS operating system.
Grafana Installation On Ubuntu 20.04 LTS
Grafana Installation will be described as following items.
- Update system
- Add Grafana APT repository
- Install Grafana on Ubuntu 20.04
- Open Port on Firewall (Optional)
- Access Grafana Dashboard on Ubuntu
1. Update System
By updating system repository, we will refresh our Ubuntu system to the latest package version, this task is performed by submitting command line :
$ sudo apt update
2. Add Grafana 6 APT repository
On this stage, we will add Grafana repository to the system, by using following command line :
$ sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
Output :
ramans@otodiginet:~$ sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
Hit:1 http://us.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease
Ign:4 http://download.webmin.com/download/repository sarge InRelease
Get:5 https://packages.grafana.com/oss/deb stable InRelease [12.1 kB]
3. Install Grafana on Ubuntu 20.04
3.1 Update system and Install Grafana
After Grafana repository was added to the system, then we will install Grafana by submitting command line :
$ sudo apt-get update $ sudo apt-get -y install grafana
Output :
ramans@otodiginet:~$ sudo apt-get -y install grafana Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream linux-headers-5.4.0-39 linux-headers-5.4.0-39-generic linux-image-5.4.0-39-generic linux-modules-5.4.0-39-generic linux-modules-extra-5.4.0-39-generic nginx-common nginx-core Use 'sudo apt autoremove' to remove them. 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 user `grafana' (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.2 Managing Grafana Service
By default, Grafana service will be running after installation was completed. On this stage, we will make Grafana service will be started automatically after system rebooted. We will performed several tasks as shown below :
$ sudo /bin/systemctl daemon-reload $ sudo /bin/systemctl enable grafana-server $ systemctl status grafana-server.service
Output :
ramans@otodiginet:~$ sudo /bin/systemctl daemon-reload ramans@otodiginet:~$ sudo systemctl enable --now grafana-server Synchronizing state of grafana-server.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable 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>
3.3 Verify Grafana Version
After all Grafana service is running properly, then we will check Grafana version by submitting command line :
$ grafana-server -v
Output :
ramans@otodiginet:~$ grafana-server -v Version 7.1.5 (commit: 9893b8c53d, branch: HEAD)
4. Open Port on Firewall
Grafana as monitoring tools must be accessed by any other entities outside localhost, so we have to allow Firewall where Grafana service port is binding to be opened. We will install UFW (uncomplicated firewall) service to ease this task.
To perform this task we will submit the following command line :
$ sudo apt -y install ufw $ sudo ufw enable $ sudo ufw allow ssh $ sudo ufw allow 3000/tcp
Output :
ramans@otodiginet:~$ sudo apt -y install ufw Reading package lists... Done Building dependency tree Reading state information... Done ufw is already the newest version (0.36-6). ufw set to manually installed. The following packages were automatically installed and are no longer required: libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream linux-headers-5.4.0-39 linux-headers-5.4.0-39-generic linux-image-5.4.0-39-generic linux-modules-5.4.0-39-generic linux-modules-extra-5.4.0-39-generic nginx-common nginx-core Use 'sudo apt autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 262 not upgraded.
ramans@otodiginet:~$ sudo ufw enable Firewall is active and enabled on system startup ramans@otodiginet:~$ sudo ufw allow ssh Rule added Rule added (v6)
By default Grafana service will be binding on port 3000, so we will make it open, by submit command line:
$ sudo ufw allow 3000/tcp
Output :
ramans@otodiginet:~$ sudo ufw allow 3000/tcp Rule added Rule added (v6)
5. Accessing Grafana Dashboard
After all are set, then we will access Grafana dasbhoard for the first time. Grafana web dashboard will be servicing on port 3000, to access it we will use web browser and hit the URL : http://<ip_address_or_server_name>:3000.
6. Testing (Using Prometheus Data Source)
Fortunately, we have installed Prometheus on our system. Please find How to install Prometheus on CentOS 8 article for Promotheus installation on CentOS 8. We will use its data to be displayed on our Grafana.
1. Configure Promotheus data source.
2. Load Grafana Dashboard base on Prometheus data
Conclusion
On this tutorial, we have learnt how to install Grafana version on Ubuntu 20.04 LTS operating system and use it to display Prometheus data. I hope this tutorial will be helpful.