How to Install Grafana Server on Ubuntu 20.04 Open Source Monitoring

How to Install Grafana Server on Ubuntu 20.04 Open Source Monitoring

What is Grafana

Grafana is a free, open source and multi platform analytics and interactive visualization web application. It allows you to query, visualize and alert for the web when connected to supported data sources. Grafana supports many data sources such as Graphite, Prometheus, Influx DB, ElasticSearch, MySQL, PostgreSQL, etc. It also allows you to write plugins from scratch for integration with several different data sources.

 

It provides a cool and customizable dashboard that helps you track the user behavior, application behavior and frequency of errors popping up in production. The dashboard provides several different individual panels on the grid and visualization options such as geo maps, heat maps, histograms, charts and graphs.

Grafana alternatives to consider are Prometheus, Zabbix or Nagios Core monitoring tools. What we like about  Nagios monitoring tool is that it offers alerting for servers, switches, applications and services. Nagios is a host and service as well as network monitoring program written in C.

Grafana Features

  • Free and open source framework.
  • Built in support for Graphite, Influx DB, Prometheus, ElasticSearch and CloudWatch.
  • Either host it on prem or any cloud platform of your choice.
  • Integrated alerting system to warn you of problems as they occur.
  • Provides custom plugins to extend Grafana’s functionality.
  • Notify via email, PagerDuty, Slack or texts.
  • Supports LDAP and OAuth and other authentication .

Follow this tutorial and we will explain how to how to Install Grafana Server on Ubuntu 20.04 Open Source Monitoring.

Getting Started

Before starting, it is always a good idea to update all installed packages to the latest version. You can do them by running the following command:

				
					apt-get update -y
apt-get upgrade -y
				
			

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

Install Grafana Server on Ubuntu 20.04

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

First, you will need to install some required dependencies on your server. You can install all required dependencies by running the following command:

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

Once all the dependencies are installed, 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 sources.list file with the following command:

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

Once the repository is added, update the repository cache with the following command:

				
					apt-get update -y
				
			

Please install the Grafana server package by running the following command:

				
					apt-get install grafana -y
				
			

Once the Grafana server is installed, you can proceed to the next step.

Manage Grafana Service

By default, the Grafana service is managed by systemd. You will need to start and enable it so that it will start automatically after the system reboot:

				
					systemctl start grafana-server
systemctl enable grafana-server
				
			

You will get the following output:

				
					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.

				
			

To check the status of the Grafana service, run 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; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-04-15 06:55:13 UTC; 17s ago
       Docs: http://docs.grafana.org
   Main PID: 11340 (grafana-server)
      Tasks: 10 (limit: 4686)
     Memory: 32.7M
     CGroup: /system.slice/grafana-server.service
             └─11340 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/run/grafana/grafana-server.pid --packaging=deb cfg>

Apr 15 06:55:16 ubuntu2004 grafana-server[11340]: logger=plugin.finder t=2022-04-15T06:55:16.03+0000 lvl=warn msg="Skipping finding plugins a>
Apr 15 06:55:16 ubuntu2004 grafana-server[11340]: logger=query_data t=2022-04-15T06:55:16.03+0000 lvl=info msg="Query Service initialization"
Apr 15 06:55:16 ubuntu2004 grafana-server[11340]: logger=live.push_http t=2022-04-15T06:55:16.04+0000 lvl=info msg="Live Push Gateway initial>
Apr 15 06:55:16 ubuntu2004 grafana-server[11340]: logger=server t=2022-04-15T06:55:16.21+0000 lvl=info msg="Writing PID file" path=/run/grafa>
Apr 15 06:55:16 ubuntu2004 grafana-server[11340]: logger=http.server t=2022-04-15T06:55:16.22+0000 lvl=info msg="HTTP Server Listen" address=>
Apr 15 06:55:16 ubuntu2004 grafana-server[11340]: logger=ngalert t=2022-04-15T06:55:16.22+0000 lvl=info msg="warming cache for startup"
Apr 15 06:55:16 ubuntu2004 grafana-server[11340]: logger=ngalert.multiorg.alertmanager t=2022-04-15T06:55:16.23+0000 lvl=info msg="starting M>

				
			

Now, Grafana server is started and listens on port 3000. You can verify the listening port using the following command:

				
					ss -antpl | grep grafana
				
			

You will get the listening port in the following output:

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

Configure Nginx as a Reverse Proxy for Grafana

Without Nginx, you will need to access the Grafana server by specifying the port 3000 at the end of the URL. So it is a good idea to install and configure Nginx as a reverse proxy to hide the Grafana port and access it via port 80.

First, install the Nginx web server package using the following command:

				
					apt-get install nginx -y
				
			

Once the Nginx package is installed, create an Nginx virtual host configuration file using the following command:

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

Add the following lines:

				
					server {
        server_name grafana.exampledomain.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 with the following command:

				
					nginx -t
				
			

If everything is fine, you should see 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 configuration changes:

				
					systemctl restart nginx
				
			

Verify the status of the Nginx service with the following command:

				
					systemctl status nginx
				
			

You should see the following output:

				
					● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-04-15 06:57:16 UTC; 5s ago
       Docs: man:nginx(8)
    Process: 11473 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 11494 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 11496 (nginx)
      Tasks: 3 (limit: 4686)
     Memory: 4.1M
     CGroup: /system.slice/nginx.service
             ├─11496 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ├─11497 nginx: worker process
             └─11498 nginx: worker process

Apr 15 06:57:16 ubuntu2004 systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 15 06:57:16 ubuntu2004 systemd[1]: Started A high performance web server and a reverse proxy server.

				
			

Configure UFW Firewall

If the UFW firewall is installed and enabled on your server then you will need to allow ports 22 and 80 through the UFW. You can allow all of them by running the following command:

				
					ufw allow 80/tcp
ufw allow 22/tcp
ufw enable
				
			

You can now check the status of the UFW firewall using the following command:

				
					ufw status
				
			

You will get the following output:

				
					Status: active

To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
80/tcp ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
80/tcp (v6) ALLOW Anywhere (v6)

				
			

Access Grafana Web UI

Now, open your web browser and access the Grafana server using the URL http://grafana.exampledomain.com. You should see the Grafana login screen:

Provide default admin username as admin, password as admin, and click on the Login button. Once you are logged in, you will see the password reset screen:

Set your new admin password and click on the Submit button. You should see the Grafana server dashboard on the following screen:

Great job! You have read and followed all the steps to Install Grafana Server on Ubuntu 20.04 Open Source Monitoring.

How to Install Grafana Server on Ubuntu 20.04 Conclusion

In this guide, you learned how to install the Grafana server on Ubuntu 20.04. You also learned how to use Nginx as a reverse proxy to hide the Grafana port. You can now connect the external data source to the Grafana server and start monitoring them from the central place.

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x