How To Install Grafana on AlmaLinux 9 — HostnExtra

HostnExtra Technologies
4 min readOct 10, 2022
How To Install Grafana on AlmaLinux 9 — HostnExtra
Install Grafana on AlmaLinux 9 — HostnExtra

In this tutorial, we shall show you how to install Grafana on AlmaLinux 9. We shall install Grafana Enterprise and Open Source CLI version 9.1.7–1 with PostgreSQL.

Grafana is open source visualization and analytics software. It allows you to query, visualize, alert on, and explore your metrics no matter where they are stored. In plain English, it provides you with tools to turn your time-series database (TSDB) data into beautiful graphs and visualizations.

Prerequisites

By default, Grafana installs with and uses SQLite, which is an embedded database stored in the Grafana installation location. In this tutorial we are going to install PostgreSQL and configure it.

Let’s get started with the installation process.

Install Grafana on AlmaLinux 9

Step 1 — Keep the server up to date

# dnf update -y

Step 2 — Install PostgreSQL database

Before you install PostgreSQL, check the current version here and download.

Install the repository RPM:

# dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Disable the built-in PostgreSQL module:

# dnf -qy module disable postgresql

Install PostgreSQL database using following command:

# dnf install -y postgresql14-server

Initialize, start, and enable PostgreSQL service:

# sudo /usr/pgsql-14/bin/postgresql-14-setup initdb

# systemctl start postgresql-14

# systemctl enable postgresql-14

Next, we need to create a database for Grafana and assign it a username and password for authentication.

# sudo -u postgres psql

postgres=# CREATE DATABASE grafana;

CREATE DATABASE

postgres=# CREATE USER grafana WITH PASSWORD ‘grafana’;

CREATE ROLE

postgres=# GRANT ALL PRIVILEGES ON DATABASE grafana TO grafana;

GRANT

postgres=#\c grafana

You are now connected to database “grafana” as user “postgres”.

postgres=#CREATE TABLE session ( key CHAR(16) NOT NULL, data bytea, expiry INT NOT NULL, PRIMARY KEY (key));

CREATE TABLE

postgres=# \q

Note:

  • Use your own database name as well as username and set strong password.

Step 3 — Create repository file

# vi /etc/yum.repos.d/grafana.repo

Add following lines:

For Enterprise releases:

[grafana]
name=grafana
baseurl=https://packages.grafana.com/enterprise/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

For OSS releases:

[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

Step 4 — Install Grafana

Before you install Grafana, there is a one change we need to make. From RHEL 9 SHA-1 is deprecated and Grafana uses SHA-1 to GPG key. It will fail by default but if we update default crypto policies to SHA-1, it will not fail and get install successfully. Run following command to update it:

# update-crypto-policies — set DEFAULT:SHA1

Now we can install Grafana.

# dnf install grafana-enterprise -y

# or

# dnf install grafana -y

Add port 3000 in the firewall.

If you are using firewalld:

# firewall-cmd — add-port=3000/tcp — permanent

# firewall-cmd — reload

If you are using IPTables:

# iptables -A INPUT -p tcp — dport 3000 -j ACCEPT

# iptables-save

Step 5: Configure PostgreSQL:

First edit pg_hba.conf file.

# vi /var/lib/pgsql/14/data/pg_hba.conf

Add following lines:

host all grafana 0.0.0.0/0 trust
local all grafana trust

Save and exit.

Finally, modify default database configuration and set to PostgreSQL database configuration.

# vi /etc/grafana/grafana.ini

[database]
# You can configure the database connection by specifying type, host, name, user and password
# as separate properties or as on string using the url properties.

# Either “mysql”, “postgres” or “sqlite3”, it’s your choice
type = postgres
host = 127.0.0.1:5432
name = grafana
user = grafana
password = grafana

Note:

  • Change the name, user, and password as your configurations.

Save and exit.

To start and enable the service and verify that the service has started: grafana-server.service.

# systemctl start grafana-server.service
# systemctl enable grafana-server.service
# systemctl enable grafana-server.service

Package details

  • Default file (environment vars) to /etc/sysconfig/grafana-server
  • Configuration file to /etc/grafana/grafana.ini
  • systemd service (if systemd is available) name grafana-server.service
  • The default configuration uses a log file at /var/log/grafana/grafana.log
  • The default configuration specifies an sqlite3 database at /var/lib/grafana/grafana.db

The installation is completed successfully.

In this tutorial, you have learnt how to install Grafana on AlmaLinux 9.

--

--

HostnExtra Technologies

HostnExtra was founded in 2016. All of our servers are located in the continental United States and United Kingdom. View more details https://www.hostnextra.com