Grafana is a free and open-source data visualization and monitoring tool used for monitoring and visualizing metrics from remote machines. It can be used with Prometheus, InfluxDB, Graphite, and ElasticSearch to gather metrics and display them on the user-friendly dashboard. Grafana allows you to share the generated graphs as snapshots with other users. You can also write your own plugins from scratch to integrate several different data sources.
In this post, we will show you how to install Grafana on Oracle Linux 8.
Step 1 – Add a Grafana Repo
By default, the Grafana package is not included in the Oracle Linux default repo, so you will need to create a new one for Grafana. You can create it with the following command:
nano /etc/yum.repos.d/grafana.repo
Add the following lines:
[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 the file, then verify the added repo using the following command:
dnf repolist
You should see the following output:
repo id repo name grafana grafana ol8_UEKR6 Latest Unbreakable Enterprise Kernel Release 6 for Oracle Linux 8 (x86_64) ol8_appstream Oracle Linux 8 Application Stream (x86_64) ol8_baseos_latest Oracle Linux 8 BaseOS Latest (x86_64)
Next, verify the Grafana package information using the following command:
dnf info grafana -y
You should see the following output:
Name : grafana Version : 9.0.2 Release : 1 Architecture : aarch64 Size : 72 M Source : grafana-9.0.2-1.src.rpm Repository : grafana Summary : Grafana URL : https://grafana.com License : AGPLv3 Description : Grafana
Step 2 – Install Grafana
Now, run the following command to install the Grafana package on your server.
dnf install grafana -y
Once the Grafana is installed, start the Grafana service and enable it to start at system reboot:
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 should see the following output:
● grafana-server.service - Grafana instance Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; disabled; vendor preset: disabled) Active: active (running) since Wed 2022-06-29 11:36:18 EDT; 2s ago Docs: http://docs.grafana.org Main PID: 7063 (grafana-server) Tasks: 9 (limit: 11409) Memory: 40.0M CGroup: /system.slice/grafana-server.service └─7063 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/var/run/grafana/grafana-server.pid --packaging=rpm cf> Jun 29 11:36:18 oraclelinux8 grafana-server[7063]: logger=secrets t=2022-06-29T11:36:18.063037318-04:00 level=info msg="Envelope encryption s> Jun 29 11:36:18 oraclelinux8 grafana-server[7063]: logger=query_data t=2022-06-29T11:36:18.073652671-04:00 level=info msg="Query Service init> Jun 29 11:36:18 oraclelinux8 grafana-server[7063]: logger=live.push_http t=2022-06-29T11:36:18.092321266-04:00 level=info msg="Live Push Gate> Jun 29 11:36:18 oraclelinux8 grafana-server[7063]: logger=infra.usagestats.collector t=2022-06-29T11:36:18.384731818-04:00 level=info msg="re> Jun 29 11:36:18 oraclelinux8 grafana-server[7063]: logger=server t=2022-06-29T11:36:18.385337145-04:00 level=info msg="Writing PID file" path> Jun 29 11:36:18 oraclelinux8 systemd[1]: Started Grafana instance. Jun 29 11:36:18 oraclelinux8 grafana-server[7063]: logger=http.server t=2022-06-29T11:36:18.405279335-04:00 level=info msg="HTTP Server Liste> Jun 29 11:36:18 oraclelinux8 grafana-server[7063]: logger=ngalert t=2022-06-29T11:36:18.407968692-04:00 level=info msg="warming cache for sta> Jun 29 11:36:18 oraclelinux8 grafana-server[7063]: logger=grafanaStorageLogger t=2022-06-29T11:36:18.42281796-04:00 level=info msg="storage s> Jun 29 11:36:18 oraclelinux8 grafana-server[7063]: logger=ngalert.multiorg.alertmanager t=2022-06-29T11:36:18.424110181-04:00 level=info msg=>
By default, Grafana listens on port 3000. You can check it with the following command:
ss -antpl | grep 3000
You should see the following output:
LISTEN 0 128 *:3000 *:* users:(("grafana-server",pid=7063,fd=9))
Step 3 – Configure Nginx as a Reverse Proxy for Grafana
It is recommended to configure Nginx as a reverse proxy so you can access the Grafana without specifying port 3000.
First, install the Nginx server with the following command:
dnf install nginx -y
Once the Nginx package is installed, create an Nginx virtual host configuration file for Grafana:
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, then edit the Nginx main configuration file:
nano /etc/nginx/nginx.conf
Add the following line below http {:
server_names_hash_bucket_size 64;
Save and close the file, then verify the Nginx configuration file:
nginx -t
If your configuration is correct, you will see the message output ‘syntax is ok’ as below.
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Finally, start and enable the Nginx service:
systemctl start nginx systemctl enable nginx
You can also check the Nginx status using the following command:
systemctl status nginx
You will get the following output:
● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: active (running) since Wed 2022-06-29 11:38:43 EDT; 5s ago Process: 26015 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS) Process: 26014 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Process: 26012 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) Main PID: 26017 (nginx) Tasks: 2 (limit: 11409) Memory: 3.7M CGroup: /system.slice/nginx.service ├─26017 nginx: master process /usr/sbin/nginx └─26018 nginx: worker process Jun 29 11:38:43 oraclelinux8 systemd[1]: Starting The nginx HTTP and reverse proxy server... Jun 29 11:38:43 oraclelinux8 nginx[26014]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok Jun 29 11:38:43 oraclelinux8 nginx[26014]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Step 4 – Access Grafana Dashboard
At this point, Grafana is installed and running. You can now access the Grafana dashboard using the URL http://grafana.example.com. You should see the Grafana login page:
Provide the default username and password as admin then click on the Log in button. You should see the change password screen:
Change your default admin password and click on the Change Password button. You should see the Grafana dashboard on the following page:
Conclusion
In this post, we explained how to install Grafana with Nginx as a reverse proxy on Oracle Linux 8. You can now add external data sources to Grafana and start monitoring them from the web-based interface. For more information, visit the Grafana documentation page. Give it a try on your dedicated server from Atlantic.Net!