This is a guide on How to Install Grafana on Ubuntu 22.04|20.04|18.04. Earlier on our infrastructure and systems monitoring series, we covered Installation of Grafana on CentOS 7 server. Then later demonstrated how to monitor Linux systems with Grafana, telegraf, and InfluxDB.
A good infrastructure/systems monitoring can help you avoid a 3 am call by preventing issues from arising. There are different monitoring tools available, and choosing the right one can be challenging. Also look at How to Install Zabbix Server on Ubuntu.
Grafana is an open source, feature rich metrics dashboard and graph editor for Graphite, Elasticsearch, OpenTSDB, Prometheus, and InfluxDB. As an example, when using InfluxDB as your data source, data stored on InfluxDB will be visualized using Grafana Graphs.
Install Grafana on Ubuntu 22.04|20.04|18.04
There are two common ways to Install Grafana on Ubuntu 22.04|20.04|18.04:
- Using the official APT repository
- Installing from .deb package
The preferred method is using apt repository since you can easily upgrade to the latest release using the apt package manager for Debian and Ubuntu.
Step 1: Update system
Ensure your Ubuntu system is up to date.
sudo apt update
Step 2: Add Grafana APT repository
Add Grafana gpg key which allows you to install signed packages.
sudo apt install -y gnupg2 curl software-properties-common
curl -fsSL https://packages.grafana.com/gpg.key|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/grafana.gpg
Then install Grafana APT repository:
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
If your system is missing , check How to Install add-apt-repository on Debian / Ubuntu
Step 3: Install Grafana on Ubuntu
Once the repository is added, proceed to update your Apt repositories and install Grafana
sudo apt update
sudo apt -y install grafana
Start Grafana service.
sudo systemctl enable --now grafana-server
The service should now be running.
$ systemctl status grafana-server.service
● grafana-server.service - Grafana instance
Loaded: loaded (/lib/systemd/system/grafana-server.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-10-14 16:26:13 EAT; 4s ago
Docs: http://docs.grafana.org
Main PID: 5541 (grafana-server)
Tasks: 7 (limit: 9460)
Memory: 41.7M
CPU: 784ms
CGroup: /system.slice/grafana-server.service
└─5541 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/run/grafana/grafana-server.pid --packaging=deb cfg:default.paths.logs=/var/log/grafana cfg:default.paths.da>
Oct 14 16:26:15 jammy grafana-server[5541]: logger=live.push_http t=2022-10-14T16:26:15.390848521+03:00 level=info msg="Live Push Gateway initialization"
Oct 14 16:26:15 jammy grafana-server[5541]: logger=infra.usagestats.collector t=2022-10-14T16:26:15.666309404+03:00 level=info msg="registering usage stat providers" usageStatsProvidersLen=2
Oct 14 16:26:15 jammy grafana-server[5541]: logger=server t=2022-10-14T16:26:15.669532612+03:00 level=info msg="Writing PID file" path=/run/grafana/grafana-server.pid pid=5541
Oct 14 16:26:15 jammy grafana-server[5541]: logger=provisioning.alerting t=2022-10-14T16:26:15.670221114+03:00 level=info msg="starting to provision alerting"
Oct 14 16:26:15 jammy grafana-server[5541]: logger=provisioning.alerting t=2022-10-14T16:26:15.670379505+03:00 level=info msg="finished to provision alerting"
Oct 14 16:26:15 jammy grafana-server[5541]: logger=http.server t=2022-10-14T16:26:15.683158306+03:00 level=info msg="HTTP Server Listen" address=[::]:3000 protocol=http subUrl= socket=
Oct 14 16:26:15 jammy grafana-server[5541]: logger=ngalert t=2022-10-14T16:26:15.683496864+03:00 level=info msg="warming cache for startup"
Oct 14 16:26:15 jammy grafana-server[5541]: logger=ticker t=2022-10-14T16:26:15.683796068+03:00 level=info msg=starting first_tick=2022-10-14T16:26:20+03:00
Oct 14 16:26:15 jammy grafana-server[5541]: logger=grafanaStorageLogger t=2022-10-14T16:26:15.692317758+03:00 level=info msg="storage starting"
Oct 14 16:26:15 jammy grafana-server[5541]: logger=ngalert.multiorg.alertmanager t=2022-10-14T16:26:15.692975064+03:00 level=info msg="starting MultiOrg Alertmanager"
Step 4: Open Port on Firewall (Optional)
Grafana default http port is 3000, you’ll need to allow access to this port on the firewall. Ubuntu comes with ufw firewall. For Debian, you can install it using:
sudo apt -y install ufw
Then enable the firewall service:
sudo ufw enable
Open the port on the firewall:
sudo ufw allow ssh
sudo ufw allow 3000/tcp
To allow access only from a specific subnet, use:
sudo ufw allow from 192.168.50.0/24 to any port 3000
Step 5: Access Grafana Dashboard
Access Grafana Dashboard using the server IP address or hostname and port 3000.
Default logins are:
Username: admin
Password: admin
Change Admin Password
Remember to change admin password from default admin. Login and navigate to:
Preferences > Change Password
Grafana Package details:
- Installs binary to
/usr/sbin/grafana-server
- Installs Init.d script to
/etc/init.d/grafana-server
- Creates default file (environment vars) to
/etc/default/grafana-server
- Installs configuration file to
/etc/grafana/grafana.ini
- Installs systemd service (if systemd is available) name
grafana-server.service
- The default configuration sets the log file at
/var/log/grafana/grafana.log
- The default configuration specifies a sqlite3 db at
/var/lib/grafana/grafana.db
- Installs HTML/JS/CSS and other Grafana files at
/usr/share/grafana
The systemd service file and init.d script both use environment vars on the file located at /etc/default/grafana-server.
Next steps include looking at Adding data sources
Other monitoring guides:
- Monitoring Ceph Cluster with Prometheus and Grafana
- Monitor Redis Server with Prometheus and Grafana in 5 minutes
- Monitor Linux Server Performance with Prometheus and Grafana in 5 minutes
- How to Monitor BIND DNS server with Prometheus and Grafana
- Monitoring MySQL / MariaDB with Prometheus in five minutes
- Monitor Apache Web Server with Prometheus and Grafana in 5 minutes