how to install grafana on ubuntu 20.04

How to Install Grafana on Ubuntu 20.04

Spread the love

Grafana is a free, open-source, and composable observability and data visualization platform. It is used for monitoring, analysis, and visualization of real-time system data. Its frontend is written in Typescript while the backend is written in Go. It can be used with time series databases such as InfluxDB, Prometheus, and Elasticsearch. It provides a beautiful dashboard that allows users to create and edit both log and data graphs and create metrics.

In this post, we will explain how to install Grafana on Ubuntu 20.04.

Prerequisites

  • A Ubuntu 20.04 VPS with root access enabled or a user with sudo privileges.

Log in via SSH and Update your System

First, you will need to log in to your Ubuntu 20.04 VPS via SSH as the root user:

ssh [email protected]_ADDRESS -p PORT_NUMBER
Next, run the following commands to upgrade all installed packages on your VPS:

apt-get update -y

Once all the packages are updated, restart your system to apply the changes.

Add Grafana Repository

By default, the Grafana package is not included in the Ubuntu 20.04 default repository. So you will need to add the Grafana official repository to your system.

First, install all required dependencies using the following command:

apt-get install wget curl gnupg2 apt-transport-https software-properties-common -y

Next, download and add the Grafana GPG key with the following command:

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

Next, add the Grafana repository to APT using the following command:

echo "deb https://packages.grafana.com/oss/deb stable main" | tee -a /etc/apt/sources.list.d/grafana.list

Once the repository is added to your system, you can update it with the following command:

apt-get update -y

Install Grafana

Now, you can install the Grafana by running the following command:

apt-get install grafana -y

Once the Grafana package is installed, verify the Grafana version with the following command:

grafana-server -v

You will get the following output:

Version 8.4.5 (commit: 4cafe613e1, branch: HEAD)

Now, start the Grafana service and enable it to start at system reboot:

systemctl start grafana-server
systemctl enable grafana-server

You can now check the status of the Grafana with the following command:

systemctl status grafana-server

You will get the following output:

● grafana-server.service - Grafana instance
     Loaded: loaded (/lib/systemd/system/grafana-server.service; disabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-04-06 14:39:27 UTC; 5s ago
       Docs: http://docs.grafana.org
   Main PID: 2761 (grafana-server)
      Tasks: 9 (limit: 2348)
     Memory: 32.2M
     CGroup: /system.slice/grafana-server.service
             └─2761 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/run/grafana/grafana-server.pid --packaging=deb cfg:>

Apr 06 14:39:29 ubuntu2004 grafana-server[2761]: logger=sqlstore t=2022-04-06T14:39:29.83+0000 lvl=info msg="Created default admin" user=admin
Apr 06 14:39:29 ubuntu2004 grafana-server[2761]: logger=sqlstore t=2022-04-06T14:39:29.83+0000 lvl=info msg="Created default organization"
Apr 06 14:39:29 ubuntu2004 grafana-server[2761]: logger=plugin.manager t=2022-04-06T14:39:29.89+0000 lvl=info msg="Plugin registered" pluginI>
Apr 06 14:39:29 ubuntu2004 grafana-server[2761]: logger=plugin.finder t=2022-04-06T14:39:29.9+0000 lvl=warn msg="Skipping finding plugins as >
Apr 06 14:39:29 ubuntu2004 grafana-server[2761]: logger=query_data t=2022-04-06T14:39:29.9+0000 lvl=info msg="Query Service initialization"
Apr 06 14:39:29 ubuntu2004 grafana-server[2761]: logger=live.push_http t=2022-04-06T14:39:29.91+0000 lvl=info msg="Live Push Gateway initiali>
Apr 06 14:39:30 ubuntu2004 grafana-server[2761]: logger=server t=2022-04-06T14:39:30.11+0000 lvl=info msg="Writing PID file" path=/run/grafan>
Apr 06 14:39:30 ubuntu2004 grafana-server[2761]: logger=http.server t=2022-04-06T14:39:30.12+0000 lvl=info msg="HTTP Server Listen" address=[>
Apr 06 14:39:30 ubuntu2004 grafana-server[2761]: logger=ngalert t=2022-04-06T14:39:30.13+0000 lvl=info msg="warming cache for startup"
Apr 06 14:39:30 ubuntu2004 grafana-server[2761]: logger=ngalert.multiorg.alertmanager t=2022-04-06T14:39:30.13+0000 lvl=info msg="starting Mu>

At this point, Grafana is started and listens on port 3000. You can check it with the following command:

ss -antpl | grep 3000

You should see the following output:

LISTEN    0         4096                     *:3000                   *:*        users:(("grafana-server",pid=2761,fd=8))                                       

Configure Nginx as a Reverse Proxy for Grafana

Next, you will need to install the Nginx as a reverse proxy for Grafana. First, install the Nginx package using the following command:

apt-get install nginx -y

Once the Nginx is installed, create an Nginx virtual host configuration file:

nano /etc/nginx/conf.d/grafana.conf

Add the following lines:

Server {
        server_name grafana.example.com;
        listen 80 ;
        access_log /var/log/nginx/grafana.log;

    location / {
                proxy_pass http://localhost:3000;
        proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-Host $host:$server_port;
                proxy_set_header X-Forwarded-Server $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

Save and close the file then verify the Nginx configuration file using the following command:

nginx -t

You will get the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Finally, restart the Nginx service to apply the changes:

systemctl restart nginx

Access Grafana Dashboard

Now, open your web browser and access the Grafana dashboard using the URL http://grafana.example.com. You will be redirected to the Grafana login page:

Provide default admin username and password as admin/admin and click on the Log in button. You should see the Grafana password change screen:

Change your default password and click on the Submit button. You should see the Grafana dashboard on the following screen:

Of course, if you are one of our Ubuntu Hosting customers, you don’t have to install Grafana on your Ubuntu 20.04 VPS – simply ask our admins, sit back, and relax. Our admins will install Grafana on Ubuntu 20.04 for you immediately.

PS. If you liked this post about how to install Grafana on Ubuntu 20.04 VPS, please share it with your friends on the social networks using the buttons below, or simply leave a comment in the comments section. Thanks.

6 thoughts on “How to Install Grafana on Ubuntu 20.04

  1. Hello,
    I tryed to follow the tutorial, I use a vagrant machine with bento/ubuntu-20.04 box, all is ok but I have a error message with nginx when I taped the command: sudo nginx -t
    the result is:
    vagrant nginx[16597]: nginx: [emerg] unknown directive “Server” in /etc/nginx/conf.d/grafana.conf:1
    vagrant nginx[16597]: nginx: configuration file /etc/nginx/nginx.conf test failed

    Thank you for your help 🙂

    1. You can try to change the capital letter “S” to small letter or much better if you can provide us with the Nginx config.

  2. Getting ” Job for nginx.service failed because the control process exited with error code.” after restarting the service. Any advice?

    1. Please check the error log file at /var/log/nginx/error.log to learn more about the issue and why the Nginx service failed to start.

Leave a Reply

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