How to Install Grafana on Redhat 9 Based Linux

If you’re running a Redhat 9-based Linux distribution like CentOS, Fedora, or Rocky Linux, and you’re looking to set up Grafana, you’re in the right place. Grafana is a popular open-source monitoring and dashboarding tool that allows you to visualize data from various sources. In this guide, we will walk you through the installation of Grafana, configuring it, and setting up Nginx as a reverse proxy for secure access.

Why Choose Rocky Linux

Before we dive into the installation process, it’s worth mentioning why we recommend Rocky Linux as your go-to distribution if you’re looking for a Red Hat-like experience. Rocky Linux is an open-source enterprise operating system designed to be 100% bug-for-bug compatible with Red Hat Enterprise Linux (RHEL). It offers stability, regular updates, and a 10-year support lifecycle—all at no cost. With CentOS being discontinued and replaced by CentOS Stream, Rocky Linux fills the gap and ensures a stable and supported platform for your needs.

Key Differences Between Rocky Linux and CentOS

Here are some key differences between Rocky Linux and CentOS:

  1. Development: Rocky Linux was created by Gregory Kurtzer, one of the original creators of CentOS, in response to Red Hat’s announcement that CentOS would be discontinued. On the other hand, CentOS was developed by the CentOS project community using the source code of RHEL.
  2. Stability: Rocky Linux is a downstream distribution that gets all the features of RHEL after they are tested and adopted in RHEL. This feature makes it an ideal option for production servers as it guarantees stability and performance. CentOS was also stable but is now discontinued.
  3. Support: Rocky Linux offers a lifecycle of ten years for each release. CentOS had long-term support but has been discontinued.

Now that you have some background information, let’s proceed with the installation of Grafana.

Install Grafana on Redhat 9-Based Linux

Step 1: Install Grafana

You can use DNF to install Grafana on your Redhat 9-based Linux distribution. Open your terminal and run the following command:

sudo dnf install grafana -y

Step 2: Start Grafana Service

After installing Grafana, you’ll want to start the service and ensure it starts at boot. Run the following commands:

sudo systemctl enable --now grafana-server

Step 3: Configuring Grafana

By default, Grafana runs on the public IP address with port 3000. To set up Grafana with Nginx reverse proxy, follow these steps:

  1. Edit the Grafana configuration using your preferred text editor. In this example, we use nano:
sudo nano /etc/grafana/grafana.ini
  1. Change the following options in the configuration file:
[server]
http_addr = localhost
http_port = 3000 
domain = grafana.example.io

Save the configuration and exit your text editor.

  1. Restart the Grafana service to apply the new configuration:
sudo systemctl restart grafana-server

Now, Grafana is configured to run on localhost with the default port 3000 and the domain name grafana.example.io.

Step 4: Set Up Nginx as a Reverse Proxy for Grafana

To access Grafana securely over HTTPS and use Nginx as a reverse proxy, follow these steps:

  1. Install Nginx by running the following command:
sudo dnf install nginx -y
  1. Create a new server block for Grafana in Nginx’s configuration:
sudo nano /etc/nginx/conf.d/grafana.conf
  1. Copy and paste the following Nginx configuration, making sure to replace the domain name and SSL path with your own:
# this is required to proxy Grafana Live WebSocket connections.
map $http_upgrade $connection_upgrade {
  default upgrade;
  '' close;
}

server {
    listen      80;
    server_name grafana.example.io;
    rewrite     ^   https://$server_name$request_uri? permanent;
}

server {
  listen      443 ssl http2;
  server_name grafana.example.io;

  root /usr/share/nginx/html;
  index index.html index.htm;

  ssl_certificate /etc/letsencrypt/live/grafana.example.io/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/grafana.example.io/privkey.pem;

  access_log /var/log/nginx/grafana-access.log;
  error_log /var/log/nginx/grafana-error.log;

  location / {
    proxy_pass http://localhost:3000/;
  }

  # Proxy Grafana Live WebSocket connections.
  location /api/live {
    rewrite  ^/(.*)  /$1 break;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Host $http_host;
    proxy_pass http://localhost:3000/;
  }
}
  1. Save the configuration and exit your text editor.
  2. Verify the Nginx configuration to ensure there are no errors:
sudo nginx -t

If your configuration is correct, you will see the message output: syntax is ok.

  1. Start and enable the Nginx service:
sudo systemctl enable --now nginx
  1. Verify that the Nginx service is active and running:
sudo systemctl status nginx

Verify Grafana Installation

You’ve successfully installed Grafana and set up Nginx as a reverse proxy for secure access. To access Grafana, open your web browser and type the Grafana domain name in the address bar:

Log in using the default user ‘admin’ and password ‘admin’.

Now you have a robust Grafana installation on your Redhat 9-based Linux distribution, and you can start creating dashboards to monitor your systems effectively. Enjoy the power of Grafana for visualization and monitoring!

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *