Grafana is a tool for monitoring, analyzing and visualizing real-time system data. From a series of collected data we get a graphical panorama of the situation of a company or organization. It generates graphics and dashboards from a time series database (Graphite, InfluxDB or OpenTSDB). You can also share them with other users as snapshots.
In this tutorial we will learn how to install Grafana 8 on Ubuntu 20.04.
requirements
- An Ubuntu 20.04 server
- A user with sudo permissions
- At least 255 MB of RAM
- At least 01 CPU
- A supported database (MySQL, PostgreSQL, SQLite)
- A compatible browser with Javascript enabled
- Port 3000 open (if you are not using a reverse proxy)
Step
1: Install Grafana on Ubuntu
Grafana is not present in Ubuntu’s standard repositories. We’re going to add Grafana’s official repository for installation. This will ensure that you have the latest version.
Run the following commands to add the Grafana repository:
$ sudo wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
Install the other required packages
$ sudo apt install -y apt-transport-https software-properties-common wget
Update the cache of the repositories
$ sudo apt update
Now you can install Grafana using the APT command
$ sudo apt install grafana
You can check the installed version for more information
$ grafana-server -v
Version 8.2.3 (commit: fb85ed6912, branch: HEAD)
The output shows that Grafana version 8.2 is installed.
Now activate the service at startup so that the server will also start automatically when you restart
$ sudo 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 → /lib/systemd/system/grafana-server.service.
You need to start the service for Grafana to work properly
$ sudo systemctl start grafana-server
Step 2: Nginx Reverse Proxy for Grafana
Since we want to access it via a domain name (or a subdomain), we use a reverse proxy that redirects communication to Grafana on the server. So we’re going to install Nginx and add the certificate to handle all external requests for Grafana.
Grafana usually runs on port 3000. This means that you have to open the port on the firewall and access it via the IP address and port.
In our configuration we use Nginx as a reverse proxy to listen to the request on port 80/443
$ sudo apt install nginx
Since we have to secure the communication, we copy the certificate
$ sudo cp grafana.domain.com.crt /etc/nginx/certs/grafana.domain.com.crt
Then copy the key of the certificate
$ sudo cp grafana.domain.com.key /etc/nginx/certs/grafana.domain.com.key
Since this is our first configuration, we need to disable the default configuration to avoid possible conflicts
$ sudo rm /etc/nginx/sites-enabled/default
It’s time to set the configuration file for Grafana. You need to correctly specify where your certificate and key files are located. In addition, by default, Nginx redirects all traffic on port 80 to the secure channel on port 443
$ sudo vim /etc/nginx/sites-available/jenkins.conf
Server { server_name grafana.websitefortesting.com; listen 80 ; access_log /var/log/nginx/grafana.log; return 301 https://$host$request_uri; } server { server_name grafana.websitefortesting.com; listen 443 ssl http2 ; access_log /var/log/nginx/grafana.log; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES"; ssl_prefer_server_ciphers on; ssl_session_timeout 5m; ssl_certificate /etc/nginx/certs/grafana.websitefortesting.com.crt; ssl_certificate_key /etc/nginx/certs/grafana.websitefortesting.com.key; add_header Strict-Transport-Security "max-age=31536000"; location / { proxy_pass http://localhost:3000; 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; } }
Now we need to activate the configuration by creating a soft link of the configuration file in the / etc / nginx / site-enabled folder.
$ sudo ln -s /etc/nginx/sites-available/grafana.conf /etc/nginx/sites-enabled/grafana.conf
You can check if the configuration of Nginx is good
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Then we need to restart the Nginx service to reflect any changes
$ sudo systemctl restart nginx
Step 3: Access to Grafana
Now that the Grafana installation and configuration is complete, we can access it. To do this, you have to open your browser and enter the URL of your Grafana server http://grafana.domain.com. input
The default username and password are admin. After that, you will be asked to change the default password.
This gives you direct access to your dashboard
Now you can start working on your Grafana and set everything up. Can you look at the official documentation if you need some guidance for your configuration.
diploma
In this tutorial we learned how to install Grafana on Ubuntu 20.04. Thanks for reading, please leave your feedback and suggestions in the comment section.
Discover more from Ubuntu-Server.com
Subscribe to get the latest posts sent to your email.