In this guide, we are going to learn how to install and set up Grafana in Rocky Linux/Alma Linux/Centos 8. This guide will also work on other RHEL 8 based derivatives.
Grafana is a multi-platform open source analytics and interactive visualization web application. It provides charts, graphs, and alerts for the web when connected to supported data sources.
Related Content
- Installing and setting up Grafana in linux
- Monitor Multiple Servers With Grafana, Influxdb & Telegraf
Table of Content
- Esuring the server is up to date
- Installing Grafana
- Starting and enabling Grafana Service
- Open Grafana Service port on Firewall
- Optional: Configure Nginx to proxy traffic to Grafana
1. Esuring the server is up to date
Before proceeding let us ensure that our server packages are updated. Use this command to achieve this
sudo dnf -y update
2. Installing Grafana
Grafana is not available in the default Rocky Linux repos. To add the Grafana OSS Repo,add a new file to your YUM repo using the method of your choice. Open the repo file using your text editor, I am using vim.
sudo vim /etc/yum.repos.d/grafana.repo
Then add this content to enable Grafana OSS release.
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
Save and close then Install Grafana with this command:
sudo dnf -y install grafana
Once the installation is installed, confirm it with this command:
$ rpm -qi grafana
Name : grafana
Version : 8.2.5
Release : 1
Architecture: x86_64
Install Date: Wed 01 Dec 2021 09:23:37 AM EAT
Group : default
Size : 225396854
License : "Apache 2.0"
Signature : RSA/SHA256, Thu 18 Nov 2021 01:14:51 PM EAT, Key ID 8c8c34c524098cb6
Source RPM : grafana-8.2.5-1.src.rpm
Build Date : Thu 18 Nov 2021 01:14:22 PM EAT
Build Host : 7b5640630d31
Relocations : /
Packager : contact@grafana.com
Vendor : Grafana
URL : https://grafana.com
Summary : Grafana
Description :
Grafana
Grafana OSS is now installed in the system.
3. Starting and enabling the Grafana Service
Once the installation is done, we need to start the service. In RHEL based systems, the service is not started by default. Start it using this command:
sudo systemctl start grafana-server
Confirm that the service was started successfully using this command:
$ sudo systemctl status grafana-server
● grafana-server.service - Grafana instance
Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2021-12-01 09:26:33 EAT; 17s ago
Docs: http://docs.grafana.org
Main PID: 128173 (grafana-server)
Tasks: 9 (limit: 23168)
Memory: 62.6M
CGroup: /system.slice/grafana-server.service
└─128173 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/var/run/grafana/grafana-server.pid --packaging=rpm cfg:default.paths.logs=/var/log/grafana cfg:default>
Dec 01 09:26:32 cloudsrv.citizix.com grafana-server[128173]: t=2021-12-01T09:26:32+0300 lvl=info msg="migrations completed" logger=migrator performed=346 skipped=0 duration=1.366753561s
Dec 01 09:26:32 cloudsrv.citizix.com grafana-server[128173]: t=2021-12-01T09:26:32+0300 lvl=info msg="Created default admin" logger=sqlstore user=admin
Dec 01 09:26:32 cloudsrv.citizix.com grafana-server[128173]: t=2021-12-01T09:26:32+0300 lvl=info msg="Created default organization" logger=sqlstore
Dec 01 09:26:32 cloudsrv.citizix.com grafana-server[128173]: t=2021-12-01T09:26:32+0300 lvl=info msg="Starting plugin search" logger=plugins
Dec 01 09:26:32 cloudsrv.citizix.com grafana-server[128173]: t=2021-12-01T09:26:32+0300 lvl=info msg="Registering plugin" logger=plugins id=input
Dec 01 09:26:32 cloudsrv.citizix.com grafana-server[128173]: t=2021-12-01T09:26:32+0300 lvl=info msg="External plugins directory created" logger=plugins directory=/var/lib/grafana/plugins
Dec 01 09:26:32 cloudsrv.citizix.com grafana-server[128173]: t=2021-12-01T09:26:32+0300 lvl=info msg="Live Push Gateway initialization" logger=live.push_http
Dec 01 09:26:33 cloudsrv.citizix.com grafana-server[128173]: t=2021-12-01T09:26:33+0300 lvl=info msg="Writing PID file" logger=server path=/var/run/grafana/grafana-server.pid pid=128173
Dec 01 09:26:33 cloudsrv.citizix.com systemd[1]: Started Grafana instance.
Dec 01 09:26:33 cloudsrv.citizix.com grafana-server[128173]: t=2021-12-01T09:26:33+0300 lvl=info msg="HTTP Server Listen" logger=http.server address=[::]:3000 protocol=http subUrl= socket=
The
Active: active (running)
in the output confirms that the service was started successfully.
To enable the service to start on boot, use this command:
<meta charset="utf-8">sudo systemctl enable grafana-server
4. Open Grafana Service Port on the firewall
With the service started, open the port on the firewall so you can access the server from the network. This will be neccessary if you are accessing the service using the port. This is only needed if you enforce firewall rules and you have firewalld installed.
sudo firewall-cmd --add-port=3000/tcp --permanent
sudo firewall-cmd --reload
5. Accessing the service using IP and port
Once the service starts and the port is opened, we can access the service on the server ip port 3000. If Grafana is installed on a local system, use the address http://127.0.0.1:3000 otherwise use the server public ip instead of 127.0.0.1, i.e. http://[server_ip]:3000.
Once you access the URL you should see the Grafana login page.
The initial username and password is admin and admin. You will be asked to change the password the first time you access Grafana.
6. Optional: Configure Nginx to proxy traffic to Grafana Service
To configure Nginx, we first need to install it. For Nginx to work, we need a registered domain with its record mapped to the Server IP.
Install Nginx using this command:
sudo dnf -y install nginx
Then add nginx proxy. Open the nginx conf file where the config will exist using this command:
sudo vim /etc/nginx/conf.d/grafana.conf
Then add this content:
server {
listen 80;
server_name grafana.citizix.com;
proxy_set_header X-Real-IP $remote_addr;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_pass http://127.0.0.1:3000;
}
}
Confirm that the nginx configuration we added is valid using this command:
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
We can now start and enable nginx service
sudo systemctl start nginx
sudo systemctl enable nginx
You can now access the service in the url you set up in your nginx script – http://grafana.citizix.com in my case.
Conclusion
We managed to install and configured Grafana OSS in this guide. We went an extra step of adding nginx to proxy request to our service.