UbuntuUbuntu Based

How To Install Grafana on Ubuntu 24.04 LTS

Install Grafana on Ubuntu 24.04

Grafana has become an indispensable tool for data visualization and monitoring in modern IT infrastructures. This powerful open-source platform allows users to query, visualize, and understand their metrics, regardless of where they’re stored. For system administrators and DevOps professionals using Ubuntu 24.04 LTS, installing Grafana is a crucial step towards enhancing their monitoring capabilities. This guide will walk you through the process of installing Grafana on Ubuntu 24.04 LTS, ensuring you have a robust monitoring solution at your fingertips.

Prerequisites

Before diving into the installation process, it’s essential to ensure your system meets the necessary requirements. Grafana is relatively lightweight, but having adequate resources will ensure smooth operation. Here’s what you’ll need:

  • A server running Ubuntu 24.04 LTS
  • At least 2GB of RAM (4GB recommended for optimal performance)
  • Minimum 10GB of free disk space
  • A user account with sudo privileges
  • Basic familiarity with the Linux command line

Additionally, ensure you have the following software dependencies installed:

  • wget
  • curl
  • apt-transport-https

These utilities are typically pre-installed on Ubuntu systems, but it’s worth double-checking. You can install them using the following command if needed:

sudo apt install wget curl apt-transport-https

Step 1: Update System Packages

Before installing any new software, it’s crucial to ensure your system is up-to-date. This step helps prevent potential conflicts and ensures you’re working with the latest security patches. Open your terminal and run the following commands:

sudo apt update
sudo apt upgrade -y

The first command updates the package lists, while the second upgrades all installed packages to their latest versions. The ‘-y’ flag automatically answers “yes” to any prompts, streamlining the process.

Step 2: Add Grafana APT Repository

Grafana isn’t available in the default Ubuntu repositories, so we need to add the official Grafana repository. This ensures we get the latest version and can easily update Grafana in the future. Follow these steps:

1. First, import the Grafana GPG key:

wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -

This command downloads the GPG key and adds it to your system’s trusted keys, ensuring the authenticity of the Grafana packages.

2. Next, add the Grafana repository to your system’s sources list:

echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list

This command creates a new file in the ‘/etc/apt/sources.list.d/’ directory, telling APT where to find Grafana packages.

Step 3: Install Grafana

With the repository added, we can now install Grafana. Run the following commands:

sudo apt update
sudo apt install grafana

The first command updates the package lists to include the newly added Grafana repository. The second command installs Grafana and its dependencies.

To verify the installation was successful, you can check the Grafana version:

grafana-server -v

This should display the installed version of Grafana, confirming a successful installation.

Step 4: Start and Enable Grafana Service

After installation, Grafana needs to be started and enabled to run at system boot. Use the following commands:

sudo systemctl start grafana-server
sudo systemctl enable grafana-server

The first command starts the Grafana service immediately. The second command enables Grafana to start automatically whenever your system boots up.

To verify that Grafana is running correctly, check its status:

sudo systemctl status grafana-server

You should see output indicating that the service is “active (running)”.

Step 5: Configure Firewall

By default, Grafana runs on port 3000. If you have a firewall enabled (which is recommended for security), you’ll need to allow traffic on this port. For systems using UFW (Uncomplicated Firewall), use the following command:

sudo ufw allow 3000/tcp

This command opens port 3000 for TCP traffic, allowing you to access the Grafana web interface.

If you’re using a different firewall, consult its documentation for the equivalent command to open port 3000.

Step 6: Accessing Grafana Web Interface

With Grafana installed and running, you can now access its web interface. Open a web browser and navigate to:

http://your_server_ip:3000

Replace ‘your_server_ip’ with your server’s actual IP address or domain name. You should see the Grafana login page.

The default login credentials are:

  • Username: admin
  • Password: admin

Upon your first login, Grafana will prompt you to change the default password. It’s crucial to choose a strong, unique password to secure your Grafana installation.

Install Grafana on Ubuntu 24.04

Step 7: Secure Grafana with SSL

For production environments, it’s essential to secure Grafana with SSL to encrypt data transmission. While Grafana doesn’t natively support SSL, you can use a reverse proxy like Nginx to handle SSL termination. Here’s a basic outline of the process:

1. Install Nginx:

sudo apt install nginx

2. Obtain an SSL certificate (you can use Let’s Encrypt for free certificates).

3. Configure Nginx as a reverse proxy for Grafana. Create a new Nginx server block configuration file:

sudo nano /etc/nginx/sites-available/grafana

Add the following configuration, adjusting the server_name and SSL certificate paths as needed:

server {
    listen 80;
    server_name grafana.yourdomain.com;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name grafana.yourdomain.com;

    ssl_certificate /path/to/your/certificate.crt;
    ssl_certificate_key /path/to/your/certificate.key;

    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $http_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-Proto $scheme;
    }
}

4. Enable the new configuration and restart Nginx:

sudo ln -s /etc/nginx/sites-available/grafana /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Now you can access Grafana securely via HTTPS.

Step 8: Basic Configuration and Setup

After logging into Grafana, you’ll want to perform some basic configuration:

  1. Add Data Sources: Click on the gear icon (⚙️) in the sidebar, then select “Data Sources”. Click “Add data source” and choose from the available options (e.g., Prometheus, InfluxDB, MySQL).
  2. Create Dashboards: Click the “+” icon in the sidebar and select “Dashboard”. You can either import pre-made dashboards or create your own using Grafana’s intuitive interface.
  3. Set Up Alerts: Navigate to Alerting in the sidebar to configure alert rules based on your data sources and metrics.
  4. User Management: For team environments, set up additional users and configure their permissions under the “Server Admin” section.

Troubleshooting Tips

If you encounter issues during or after installation, try these troubleshooting steps:

  • Check Logs: Grafana logs are typically located at ‘/var/log/grafana/grafana.log’. Review these for error messages.
  • Verify Permissions: Ensure the Grafana process has the necessary permissions to read its configuration files and write to its data directory.
  • Restart the Service: Sometimes, a simple restart can resolve issues: sudo systemctl restart grafana-server
  • Check Port Availability: Ensure no other service is using port 3000: sudo lsof -i :3000

Congratulations! You have successfully installed Grafana. Thanks for using this tutorial for installing the Grafana monitoring and visualization software on Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official Grafana website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button