How to Install Grafana Linux Monitoring Software on Ubuntu 22.04
This tutorial exists for these OS versions
- Ubuntu 24.04 (Noble Numbat)
- Ubuntu 22.04 (Jammy Jellyfish)
- Ubuntu 20.04 (Focal Fossa)
- Ubuntu 18.04 (Bionic Beaver)
On this page
Grafana is a free, open-source, and feature-rich metrics dashboard and data visualizing tool. It is designed for Graphite, Elasticsearch, OpenTSDB, Prometheus, and InfluxDB to monitor metrics from a web-based interface. It is a multi-platform and has over 100 plugins for data collection, storage, visualization, and sharing. It allows you to create alerts and notifications for your data and make collaboration with your teammates easier via sharing features.
This tutorial will explain how to install Grafana 8 on Ubuntu 22.04.
Prerequisites
- A server running Ubuntu 22.04.
- A valid domain name pointed with your server IP.
- A root password is configured on the server.
Getting Started
Before starting, updating your system to the updated version is recommended. You can update all the packages using the following command:
apt-get update -y
apt-get upgrade -y
Once all the packages are upgraded, install other required dependencies using the following command:
apt-get install gnupg2 curl wget git software-properties-common -y
Once all the packages are installed, you can proceed to the next step.
Install Grafana 8 on Ubuntu 22.04
By default, Grafana is not included in the Ubuntu 22.04 default repository. So you will need to add the Grafana repository to the APT. You can add it using the following command:
curl https://packages.grafana.com/gpg.key | apt-key add -
add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
Once the repository is added, update the repository cache and install the Grafana using the following command:
apt-get update -y
apt-get install grafana -y
Once Grafana is installed, start and enable the Grafana service using the following command:
systemctl start grafana-server
systemctl enable grafana-server
You can also check the status of the Grafana service 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 Sat 2022-08-06 09:33:06 UTC; 7s ago Docs: http://docs.grafana.org Main PID: 69737 (grafana-server) Tasks: 9 (limit: 2242) Memory: 37.1M CPU: 1.580s CGroup: /system.slice/grafana-server.service ??69737 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/run/grafana/grafana-server.pid --packaging=deb cfg> Aug 06 09:33:08 ubuntu2204 grafana-server[69737]: logger=secrets t=2022-08-06T09:33:08.517381147Z level=info msg="Envelope encryption state" > Aug 06 09:33:08 ubuntu2204 grafana-server[69737]: logger=query_data t=2022-08-06T09:33:08.527197639Z level=info msg="Query Service initializa> Aug 06 09:33:08 ubuntu2204 grafana-server[69737]: logger=live.push_http t=2022-08-06T09:33:08.544920469Z level=info msg="Live Push Gateway in> Aug 06 09:33:13 ubuntu2204 grafana-server[69737]: logger=ngalert t=2022-08-06T09:33:13.723313517Z level=warn msg="failed to delete old am con> Aug 06 09:33:13 ubuntu2204 grafana-server[69737]: logger=infra.usagestats.collector t=2022-08-06T09:33:13.885398731Z level=info msg="register> Aug 06 09:33:13 ubuntu2204 grafana-server[69737]: logger=server t=2022-08-06T09:33:13.886028388Z level=info msg="Writing PID file" path=/run/> Aug 06 09:33:13 ubuntu2204 grafana-server[69737]: logger=http.server t=2022-08-06T09:33:13.900761945Z level=info msg="HTTP Server Listen" add> Aug 06 09:33:13 ubuntu2204 grafana-server[69737]: logger=ngalert t=2022-08-06T09:33:13.901994976Z level=info msg="warming cache for startup" Aug 06 09:33:13 ubuntu2204 grafana-server[69737]: logger=ngalert.multiorg.alertmanager t=2022-08-06T09:33:13.902506414Z level=info msg="start> Aug 06 09:33:13 ubuntu2204 grafana-server[69737]: logger=grafanaStorageLogger t=2022-08-06T09:33:13.926571246Z level=info msg="storage starti>
By default, Grafana listens on port 3000. You can check it with the following command:
ss -antpl | grep 3000
You will get the following output:
LISTEN 0 4096 *:3000 *:* users:(("grafana-server",pid=69737,fd=8))
Install Nginx as a Reverse Proxy for Grafana
By default, Grafana can be accessed via port 3000. So, you will need to install and configure the Nginx as a reverse proxy for Grafana to access it via port 80. First, install the Nginx using the following command:
apt-get install nginx -y
Once the Nginx is installed, create an Nginx virtual host configuration file with the following command:
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 when you are finished. Then, verify the Nginx for any syntax error with the following command:
nginx -t
If everything is fine, 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
Next, restart the Nginx to apply the configuration changes.
systemctl restart nginx
You can also check the Nginx status with the following command:
systemctl status nginx
You will get 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 Sat 2022-08-06 09:35:32 UTC; 4s ago Docs: man:nginx(8) Process: 70326 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 70327 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Main PID: 70328 (nginx) Tasks: 2 (limit: 2242) Memory: 2.6M CPU: 42ms CGroup: /system.slice/nginx.service ??70328 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;" ??70329 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" Aug 06 09:35:32 ubuntu2204 systemd[1]: Starting A high performance web server and a reverse proxy server... Aug 06 09:35:32 ubuntu2204 systemd[1]: Started A high performance web server and a reverse proxy server.
At this point, Nginx is installed and configured as a reverse proxy for Grafana. You can now proceed to the next step.
Access Grafana Dashboard
Now, open your web browser and access the Grafana web interface using the URL http://grafana.example.com. You will be redirected to the Grafana login page:
Provide default admin username, password as admin/admin and click on the Log in button. You should see the Grafana password reset screen:
Set your new password and click on the Submit button. You should see the Grafana dashboard on the following screen:
Secure Grafana with Let's Encrypt
Next, you will need to install the Certbot client package to install and manage the Let's Encrypt SSL.
First, install the Certbot with the following command:
apt-get install certbot python3-certbot-nginx -y
Once the installation is finished, run the following command to install the Let's Encrypt SSL on your website:
certbot --nginx -d grafana.example.com
You will be asked to provide a valid email address and accept the term of service as shown below:
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator nginx, Installer nginx Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): [email protected] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (A)gree/(C)ancel: A - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y Obtaining a new certificate Performing the following challenges: http-01 challenge for grafana.example.com Waiting for verification... Cleaning up challenges Deploying Certificate to VirtualHost /etc/nginx/conf.d/grafana.conf
Next, choose whether or not to redirect HTTP traffic to HTTPS as shown below:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Type 2 and hit Enter to finish the installation. You should see the following output:
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/grafana.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://grafana.example.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=grafana.example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/grafana.example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/grafana.example.com/privkey.pem Your cert will expire on 2022-05-07. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot renew" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le - We were unable to subscribe you the EFF mailing list because your e-mail address appears to be invalid. You can try again later by visiting https://act.eff.org.
Conclusion
Congratulations! you have successfully installed Grafana 8 with Nginx as a reverse proxy and Let's Encrypt SSL on Ubuntu 22.04. You can now add your external data sources to Grafana and start monitoring them from the Grafana dashboard. Feel free to ask me if you have any questions.