1778 words
9 minutes

Install Grafana on Ubuntu Server

This article is for those looking for a detailed and straightforward guide on installing Grafana on Ubuntu Server.

Grafana is an open-source platform for data visualization, monitoring, and analysis.

IMPORTANT

OpenSSH must be installed on the server, and port 22 must be open in order to be able to connect to the server using the SSH protocol.

To install OpenSSH on a server, you can use the command:

Terminal window
sudo apt install openssh-server
NOTE

To connect to the server from a Windows system, you can use tools like PuTTY or MobaXterm.

NOTE

This guide walks you through connecting to a server with the iTerm2 terminal emulator on macOS.

CAUTION

You will need to open the following TCP ports for access to the services:

  • TCP port 80 - to get a free cryptographic certificate through Let’s Encrypt CA.
  • TCP port 443 - to access the Grafana web interface.

We connect to the server on which you plan to install Grafana.

This tutorial walks you through obtaining a free cryptographic certificate through the Let’s Encrypt CA. To obtain and subsequently renew a free SSL certificate, we will use the Certbot software client, which is designed to make it as easy as possible to obtain and renew a certificate through the Let’s Encrypt certification authority.

Update the local package index to the latest changes in the repositories using the command:

Terminal window
sudo apt update

Install Grafana on Ubuntu Server - Step 1

Now let’s install the packages required for Grafana to work using the command:

Terminal window
sudo apt install -y apache2 apt-transport-https certbot python3-certbot-apache

Install Grafana on Ubuntu Server - Step 2

Let’s configure Apache for further work with Grafana.

We enable the Apache webserver module called “proxy_http” using the command:

Terminal window
sudo a2enmod proxy_http
NOTE

The “proxy_http” module acts like a proxy server for the HTTP and HTTPS protocols.

Install Grafana on Ubuntu Server - Step 3

We enable the Apache webserver module called “rewrite” using the command:

Terminal window
sudo a2enmod rewrite
NOTE

The “rewrite” module is one of the most commonly used modules in the Apache webserver and provides a flexible and powerful way to manipulate URLs.

Install Grafana on Ubuntu Server - Step 4

Now you need to create two virtual host files (called a block in Nginx), with which Grafana will work in the future.

Two virtual host files are required to provide access to Grafana over HTTPS, and to enable Grafana to be used at https://grafana.heyvaldemar.net, without specifying port 3000 in the browser address bar.

NOTE

In this tutorial, the grafana.heyvaldemar.net subdomain will be used to access Grafana from the Internet. You will need to specify your domain or subdomain by which your Grafana will be available from the Internet.

Let’s create the first virtual host file using a text editor using the command:

Terminal window
sudo vim /etc/apache2/sites-available/grafana.heyvaldemar.net.conf

Install Grafana on Ubuntu Server - Step 5

Hit the “i” button to go into edit mode, then insert the following configuration for the webserver to work.

NOTE

In this tutorial, the grafana.heyvaldemar.net subdomain will be used to access Grafana from the Internet. You will need to specify your domain or subdomain by which your Grafana will be available from the Internet.

Install Grafana on Ubuntu Server - Step 6

Now press the “Esc” button to exit edit mode, then type "" and press the “Enter” button to save your changes and exit the editor.

Install Grafana on Ubuntu Server - Step 7

Let’s create a second virtual host file using a text editor using the command:

Terminal window
sudo vim /etc/apache2/sites-available/grafana.heyvaldemar.net-ssl.conf

Install Grafana on Ubuntu Server - Step 8

Hit the “i” button to go into edit mode, then insert the following configuration for the webserver to work.

NOTE

In this tutorial, the grafana.heyvaldemar.net subdomain will be used to access Grafana from the Internet. You will need to specify your domain or subdomain by which your Grafana will be available from the Internet.

Install Grafana on Ubuntu Server - Step 9

Now press the “Esc” button to exit edit mode, then type "" and press the “Enter” button to save your changes and exit the editor.

Install Grafana on Ubuntu Server - Step 10

We activate the first virtual host using the command:

Terminal window
sudo a2ensite grafana.heyvaldemar.net.conf

Install Grafana on Ubuntu Server - Step 11

We activate the second virtual host using the command:

Terminal window
sudo a2ensite grafana.heyvaldemar.net-ssl.conf

Install Grafana on Ubuntu Server - Step 12

Deactivate the default virtual host using the command:

Terminal window
sudo a2dissite 000-default.conf

Install Grafana on Ubuntu Server - Step 13

Verify that there are no errors in the syntax of the new Apache config file using the command:

Terminal window
sudo apache2ctl configtest

Install Grafana on Ubuntu Server - Step 14

Restart Apache to apply the changes made using the command:

Terminal window
sudo systemctl restart apache2

Install Grafana on Ubuntu Server - Step 15

Let’s check that Apache has started successfully using the command:

Terminal window
sudo systemctl status apache2

Install Grafana on Ubuntu Server - Step 16

Now, in order to increase the security level of the webserver, you need to obtain a cryptographic certificate for the domain or subdomain, through which the Grafana control panel will be available from the Internet.

NOTE

To obtain and subsequently renew a free SSL certificate, we will use the Let’s Encrypt certification authority, as well as the Certbot software client, which is designed to make it as easy as possible to obtain and renew a certificate through the Let’s Encrypt certification authority.

NOTE

In this tutorial, the grafana.heyvaldemar.net subdomain will be used to access Grafana from the Internet. You will need to specify your domain or subdomain by which your Grafana will be available from the Internet.

Request a cryptographic certificate using the command:

Terminal window
sudo certbot --apache -d grafana.heyvaldemar.net

Install Grafana on Ubuntu Server - Step 17

Next, we indicate the email address to which Let’s Encrypt will send notifications about the expiration of the cryptographic certificate and press the “Enter” button.

Install Grafana on Ubuntu Server - Step 18

The next step is to read and accept the terms of use of the services provided.

Press the button “a”, then “Enter”, if you agree with the terms of use of the services provided.

Install Grafana on Ubuntu Server - Step 19

The next step is to choose whether you want to share the above email address with the Electronic Frontier Foundation in order to receive newsletters.

Press the “n” button, then “Enter”.

Install Grafana on Ubuntu Server - Step 20

At the next stage, you need to choose: do you want the parameters to be automatically added to the Apache configuration file for automatically redirecting HTTP traffic to HTTPS.

Press the button “2”, then “Enter”.

Install Grafana on Ubuntu Server - Step 21

NOTE

Cryptographic certificates obtained through Let’s Encrypt CA are valid for ninety days. Certbot automatically adds a script to renew the certificate to the task scheduler and the script runs twice a day, automatically renewing any cryptographic certificate that expires within thirty days.

You can check the functionality of the cryptographic certificate renewal process using the command:

Terminal window
sudo certbot renew --dry-run

Install Grafana on Ubuntu Server - Step 22

Now let’s add the official Grafana key using the command:

Terminal window
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -

Install Grafana on Ubuntu Server - Step 23

Next, we connect the Grafana repository using the command:

Terminal window
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"

Install Grafana on Ubuntu Server - Step 24

Now let’s install Grafana using the command:

Terminal window
sudo apt install -y grafana

Install Grafana on Ubuntu Server - Step 25

Restart “systemd” to search for changed or new units using the command:

Terminal window
sudo systemctl daemon-reload

Install Grafana on Ubuntu Server - Step 26

Launch Grafana using the command:

Terminal window
sudo systemctl start grafana-server

Install Grafana on Ubuntu Server - Step 27

Let’s check that Grafana has started successfully using the command:

Terminal window
sudo systemctl status grafana-server

Install Grafana on Ubuntu Server - Step 28

We enable the autostart of the Grafana service when the operating system starts using the command:

Terminal window
sudo systemctl enable grafana-server.service

Install Grafana on Ubuntu Server - Step 29

From the workstation, go to the link https://grafana.heyvaldemar.net, where grafana.heyvaldemar.net is the name of my subdomain to access the Grafana control panel. You will need to specify your domain or subdomain by which your Grafana control panel will be accessible from the Internet.

The default username and password for the Grafana administrator account is “admin”.

Specify the username and password of an account with Grafana administrator rights and click on the “Log in” button.

Install Grafana on Ubuntu Server - Step 30

Next, you need to change the password for the Grafana administrator account.

Specify a new password for the Grafana administrator account and click on the “Submit” button.

Install Grafana on Ubuntu Server - Step 31

Welcome to the Grafana dashboard.

Install Grafana on Ubuntu Server - Step 32

Now you need to make changes to the Grafana configuration file to disable the ability to register users without the knowledge of the Grafana administrator and to log in for anonymous users.

Open the Grafana configuration file in a text editor using the command:

Terminal window
sudo vim /etc/grafana/grafana.ini

Install Grafana on Ubuntu Server - Step 33

Hit the “i” button to switch to edit mode, in the “users” section, find the “allow_sign_up = false” parameter and uncomment it by removing the ”;” symbol.

Install Grafana on Ubuntu Server - Step 34

In the “auth.anonymous” section, find the “enabled = false” parameter and uncomment it by removing the ”;” symbol.

Install Grafana on Ubuntu Server - Step 35

Now press the “Esc” button to exit edit mode, then type "" and press the “Enter” button to save your changes and exit the editor.

Install Grafana on Ubuntu Server - Step 36

Restart Grafana to apply the changes made using the command:

Terminal window
sudo systemctl restart grafana-server

Install Grafana on Ubuntu Server - Step 37

Let’s check that Grafana has started successfully using the command:

Terminal window
sudo systemctl status grafana-server

Install Grafana on Ubuntu Server - Step 38

Everything is ready to use Grafana.

Install Grafana on Ubuntu Server - Step 39


Social Channels#


Community of IT Experts#


Is this content AI-generated?

No. Every article on this blog is written by me personally, drawing on decades of hands-on IT experience and a genuine passion for technology.

I use AI tools exclusively to help polish grammar and ensure my technical guidance is as clear as possible. However, the core ideas, strategic insights, and step-by-step solutions are entirely my own, born from real-world work.

Because of this human-and-AI partnership, some detection tools might flag this content. You can be confident, though, that the expertise is authentic. My goal is to share road-tested knowledge you can trust.

Install Grafana on Ubuntu Server
https://www.heyvaldemar.com/install-grafana-on-ubuntu-server/
Author
Vladimir Mikhalev
Published at
2020-04-21
License
CC BY-NC-SA 4.0