Grafana is a multi-platform open-source analytics and visualization platform to monitor computer systems. Grafana lets you create and share dashboards and has a thriving ecosystem of over 100 plugins for data collection, storage, visualization, and sharing.
In this article, we’re going to show you how to install Grafana on Ubuntu 20.04 so that you can get the most out of your data. So let’s get started with the setup!
In order to properly follow this tutorial, you will need the following:
An Ubuntu VPS instance. If you don’t already have an account, you can get one for free by signing up at DigitalOcean or Vultr. Once you’ve signed up, install Ubuntu on your server.
- A non-root user with sudo privileges. You can set that up by following the steps in this tutorial.
- System requirements: If you’re planning on using InfluxDB or Elasticsearch with Grafana, then your server will need to have at least 4GB of RAM. We’re going to install Grafana on a clean installation of Ubuntu 20.04. You can add more RAM to your server if you need to. We recommend adding a swap partition as well, so here’s how to do that.
Updating Ubuntu Repositories
Now that we have our prerequisites out of the way, it is time to update our /etc/apt /sources.list file and upgrade any installed packages on your VPS instance. Updating repositories improves the overall stability of an operating system by fixing bugs and vulnerabilities related to software packages. Repositories also let you update your server with the latest security patches and fixes for newly discovered vulnerabilities that affect Ubuntu or any of its software pieces.
sudo apt update && sudo apt upgrade -y
Installing Grafana on Ubuntu 20.04
Although the official Ubuntu 20.04 repository ship with Grafana, it is a bit old, so we’re going to install the latest version from the Grafana Labs repository.
The Grafana Labs repository contains the latest version of Grafana, as well as plugins and drivers for things like Graphite, Elasticsearch, InfluxDB, and MongoDB query. The Grafana Labs repository prevents you from having to install everything by hand.
Run the following command to add the GPG key. This command adds the GPG key for the Grafana Labs repository to your system so that your Ubuntu instance can authenticate packages made available by Grafana Labs. These packages are called Debian packages.
We will use the curl command to download the GPG key file that the Grafana Labs repository needs to install authenticated packages. We’ll then pass that file on to tcurl https://packages.grafana.com/gpg.key | sudo apt-key add -he apt-key command which will add it to your system.
curl https://packages.grafana.com/gpg.key | sudo apt-key add -
You will get an OK status message when the GPG key has been successfully added.
Now that we have a valid GPG key, let’s add the Grafana Labs repository to our source list file. This is the file that tells our system where to look for packages and their respective software pieces.
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
Rerun the update command to pick up the changes we just made to the /etc/apt/sources.list file.
sudo apt update -y
Run the apt-cache policy grafana command to check to see if the grafana package has been added to your system successfully.
sudo apt-cache policy grafana
The output you get should look something like this.
Finally, install Grafana on Ubuntu 20.04
sudo apt install grafana -y
After the installation process has been completed, you can start Grafana by running the following command.
sudo systemctl daemon-reload && sudo systemctl start grafana-server
At this point, your Grafana service should be up and running. You can check this by running:
sudo systemctl status grafana-server
You should see an output that tells you the current status of the server.
Configuring Your Firewall
Now that you have Grafana up and running, it’s time to configure your firewall.
A firewall is a software or hardware-based network security system that controls the incoming and outgoing network traffic based on predetermined security rules.
The most basic firewall configuration works by blocking all incoming traffic and allowing outgoing traffic, an approach known as a deny-all, allow-by-exception policy. A firewall includes rules that specify which incoming network packets are permitted to reach the computer’s operating system—and thus which outgoing connections are allowed through the firewall.
On Ubuntu, ufw provides a command-line interface to configure your firewall and is installed by default.
So if you put Grafana behind a firewall, you will have to open port 3000. Ports are essentially virtual tunnels between your server and other servers or clients that are used to transfer data back and forth. Each port is associated with a number.
Grafana uses port 3000 to send and receive data by default, so make sure that your server has that port open. If it doesn’t, even if you have Grafana installed properly, you will not be able to use it. You will have trouble loading and using the Grafana dashboard to
Let’s open up port 3000 in our firewall to make sure that we can get into Grafana after finishing the installation.
sudo ufw allow 3000/tcp
Now check the status of your firewall to make sure that the ufw command works and port 3000 is open.
sudo ufw status
You should see something like this.
Accessing Grafana Dashboard
Now that your firewall is configured, you can access the Grafana dashboard by going to your server’s IP address on port 3000. Your IP address might be different from what is listed in this guide, so make sure to substitute that in the commands below.
In your web browser, go to http://your_server_ip:3000. Where your_server_ip is the IP address of your Ubuntu server. This will bring up the default Grafana login screen where you can enter your username and password.
As this is the first time you installed Grafana. You will be using the default Grafana credentials, which is a Username of admin and Password of admin. Click on Log in.
On the next screen, there is an option for changing the password. To change the admin password, provide your new password in the input boxes provided. Remember, this is an important step! You should create a strong password, and if you are using this guide as part of a production system it may be smart to change the password periodically. Click on Submit.
Now that you’ve configured your Grafana instance, let’s take a look at some of the great dashboards that are already built-in.
In this tutorial, we showed you how to install Grafana on an Ubuntu 20.04 server, but this will work with other Linux distributions as long as the prerequisite software is available. You will need to make sure that you have a data source configured before you can use Grafana. But, other than that it’s all smooth sailing from here on out!
Now, go forth and create some awesome dashboards. You may also want to check the Grafana documentation for more information about how to configure your data sources or about other Grafana features.