(Last Updated On: June 4, 2018)

This is a guide on How to Install Grafana on Ubuntu 18.04 and Debian 9. Earlier on our infrastructure and systems monitoring series, we covered Installation of Grafana on CentOS 7 server. Then later demonstrated how to monitor Linux systems with Grafana, telegraf, and InfluxDB.

A good infrastructure/systems monitoring can help you avoid a 3 am call by preventing issues from arising.  There are different monitoring tools available, and choosing the right one can be challenging. Also look at How to Install Zabbix Server on Ubuntu 18.04.

What is Grafana?

Grafana is an open source, feature rich metrics dashboard and graph editor for Graphite, Elasticsearch, OpenTSDB, Prometheus, and InfluxDB. As an example, when using InfluxDB as your data source, data stored on InfluxDB will be visualized using Grafana Graphs.

How to Install Grafana on Ubuntu 18.04

There are two common ways to Install Grafana on Ubuntu 18.04:

  • Using the official APT repository
  • Installing from .deb package

The preferred method is using apt repository since you can easily upgrade to the latest release using the apt package manager for Debian and Ubuntu.

Method 1: Installing Grafana on Ubuntu 18.04 / Debian 9 using APT repository

Add the following line to /etc/apt/sources.list.d/grafana.list

$ cat /etc/apt/sources.list.d/grafana.list
deb https://packagecloud.io/grafana/stable/debian/ stretch main

Then add the Package Cloud key. This allows you to install signed packages.

$ sudo curl https://packagecloud.io/gpg.key | sudo apt-key add -
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3889 100 3889 0 0 5446 0 --:--:-- --:--:-- --:--:-- 5439
OK

Update apt index and install grafana

# apt-get update
Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:2 http://mirrors.digitalocean.com/ubuntu bionic InRelease 
Get:3 http://mirrors.digitalocean.com/ubuntu bionic-updates InRelease [83.2 kB] 
Get:4 http://mirrors.digitalocean.com/ubuntu bionic-backports InRelease [74.6 kB] 
Get:5 http://mirrors.digitalocean.com/ubuntu bionic-updates/universe Sources [26.1 kB]
Get:6 http://mirrors.digitalocean.com/ubuntu bionic-updates/main Sources [42.0 kB] 
Hit:7 http://mirror.zol.co.zw/mariadb/repo/10.3/ubuntu bionic InRelease 
Get:8 http://mirrors.digitalocean.com/ubuntu bionic-updates/main amd64 Packages [113 kB]
Get:9 http://mirrors.digitalocean.com/ubuntu bionic-updates/main Translation-en [43.6 kB]
Get:10 http://mirrors.digitalocean.com/ubuntu bionic-updates/universe amd64 Packages [68.0 kB]
Get:11 http://mirrors.digitalocean.com/ubuntu bionic-updates/universe Translation-en [30.4 kB]
Get:12 https://packagecloud.io/grafana/stable/debian stretch InRelease [23.2 kB] 
Get:13 https://packagecloud.io/grafana/stable/debian stretch/main amd64 Packages [3418 B]
Fetched 507 kB in 3s (185 kB/s)
Reading package lists... Done

Install Grafana on Ubuntu 18.04 / Debian 9:

Run the command below to install Grafana on Ubuntu 18.04:

$ sudo apt-get install grafana
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  grub-pc-bin
Use 'apt autoremove' to remove it.
The following NEW packages will be installed:
  grafana
0 upgraded, 1 newly installed, 0 to remove and 26 not upgraded.
Need to get 52.6 MB of archives.
After this operation, 159 MB of additional disk space will be used.
Get:1 https://packagecloud.io/grafana/stable/debian stretch/main amd64 grafana amd64 5.1.3 [52.6 MB]
Fetched 52.6 MB in 2s (26.6 MB/s)  
Selecting previously unselected package grafana.
(Reading database ... 64405 files and directories currently installed.)
Preparing to unpack .../grafana_5.1.3_amd64.deb ...
Unpacking grafana (5.1.3) ...
Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for systemd (237-3ubuntu10) ...
Setting up grafana (5.1.3) ...
Adding system user `grafana' (UID 114) ...
Adding new user `grafana' (UID 114) 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
Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for systemd (237-3ubuntu10) ...

Start and enable grafana-server service to start on boot:

$ sudo systemctl start grafana-server

Enable it to start on boot:

# systemctl enable  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
Created symlink /etc/systemd/system/multi-user.target.wants/grafana-server.service → /usr/lib/systemd/system/grafana-server.service.

Check status to confirm that it is running:

# systemctl status grafana-server
● grafana-server.service - Grafana instance
   Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-06-04 11:41:27 UTC; 1min 2s ago
     Docs: http://docs.grafana.org
 Main PID: 14540 (grafana-server)
    Tasks: 10 (limit: 4704)
   CGroup: /system.slice/grafana-server.service
           └─14540 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/var/run/grafana/grafana-server.pid cfg:default.paths.logs=/var/log/grafana cfg:de

Jun 04 11:41:28 ubuntu18.04.computingforgeeks.com grafana-server[14540]: t=2018-06-04T11:41:28+0000 lvl=info msg="Executing migration" logger=migrator id="create user aut
Jun 04 11:41:28 ubuntu18.04.computingforgeeks.com grafana-server[14540]: t=2018-06-04T11:41:28+0000 lvl=info msg="Executing migration" logger=migrator id="create index ID
Jun 04 11:41:28 ubuntu18.04.computingforgeeks.com grafana-server[14540]: t=2018-06-04T11:41:28+0000 lvl=info msg="Executing migration" logger=migrator id="alter user_auth
Jun 04 11:41:28 ubuntu18.04.computingforgeeks.com grafana-server[14540]: t=2018-06-04T11:41:28+0000 lvl=info msg="Created default admin user: admin"
Jun 04 11:41:28 ubuntu18.04.computingforgeeks.com grafana-server[14540]: t=2018-06-04T11:41:28+0000 lvl=info msg="Starting plugin search" logger=plugins
Jun 04 11:41:28 ubuntu18.04.computingforgeeks.com grafana-server[14540]: t=2018-06-04T11:41:28+0000 lvl=info msg="Plugin dir created" logger=plugins dir=/var/lib/grafana/
Jun 04 11:41:28 ubuntu18.04.computingforgeeks.com grafana-server[14540]: t=2018-06-04T11:41:28+0000 lvl=info msg="Initializing Alerting" logger=alerting.engine
Jun 04 11:41:28 ubuntu18.04.computingforgeeks.com grafana-server[14540]: t=2018-06-04T11:41:28+0000 lvl=info msg="Initializing CleanUpService" logger=cleanup
Jun 04 11:41:28 ubuntu18.04.computingforgeeks.com grafana-server[14540]: t=2018-06-04T11:41:28+0000 lvl=info msg="Initializing Stream Manager"
Jun 04 11:41:28 ubuntu18.04.computingforgeeks.com grafana-server[14540]: t=2018-06-04T11:41:28+0000 lvl=info msg="Initializing HTTP Server" logger=http.server address=0.0

Method 2: Installing Grafana on Ubuntu 18.04 / Debian 9 using .deb package

As of this writing, the latest release of Grafana server is v5.1.3. Download it with your favorite downloader, wget or curl works fine.

# wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_5.1.3_amd64.deb
--2018-06-04 11:46:33--  https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_5.1.3_amd64.deb
Resolving s3-us-west-2.amazonaws.com (s3-us-west-2.amazonaws.com)... 52.218.193.16
Connecting to s3-us-west-2.amazonaws.com (s3-us-west-2.amazonaws.com)|52.218.193.16|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 52632986 (50M) [application/x-debian-package]
Saving to: ‘grafana_5.1.3_amd64.deb’

grafana_5.1.3_amd64. 100%[======================>]  50.19M  11.7MB/s    in 8.3s    

2018-06-04 11:46:42 (6.08 MB/s) - ‘grafana_5.1.3_amd64.deb’ saved [52632986/52632986]

Then install the package with dpkg

$ sudo apt-get install -y adduser libfontconfig
$ sudo dpkg -i grafana_5.1.3_amd64.deb
(Reading database ... 65752 files and directories currently installed.)
Preparing to unpack grafana_5.1.3_amd64.deb ...
Unpacking grafana (5.1.3) over (5.1.3) ...
Setting up grafana (5.1.3) ...
Restarting grafana-server service... OK
Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for systemd (237-3ubuntu10) ...

Open Port on Firewall

Grafana default http port is 3000, you’ll need to allow access to this port on the firewall. Ubuntu comes with ufw firewall. For Debian, you can install it using:

$ sudo apt-get install ufw

Then enable the firewall service:

$ sudo ufw enable

Open the port on the firewall:

$ sudo ufw allow 3000/tcp 
Rule added
Rule added (v6)

To allow access only from a specific subnet, use:

$ sudo ufw allow from 192.168.50.0/24 to any port 3000

Accessing Grafana Dashboard

Access Grafana Dashboard using the server IP address or hostname and port 3000.

Default logins are:

Username: admin
Password: admin

Change Admin Password

Remember to change admin password from default admin. Login and navigate to:

Preferences > Change Password

Grafana Package details:

  • Installs binary to /usr/sbin/grafana-server
  • Installs Init.d script to /etc/init.d/grafana-server
  • Creates default file (environment vars) to /etc/default/grafana-server
  • Installs configuration file to /etc/grafana/grafana.ini
  • Installs systemd service (if systemd is available) name grafana-server.service
  • The default configuration sets the log file at /var/log/grafana/grafana.log
  • The default configuration specifies a sqlite3 db at /var/lib/grafana/grafana.db
  • Installs HTML/JS/CSS and other Grafana files at /usr/share/grafana

The systemd service file and init.d script both use environment vars on the file located at /etc/default/grafana-server.

Next steps include looking at Adding data sources