How to Install and Connect Grafana and InfluxDB: A Step-by-Step Guide

This guide will show you how to easily set up InfluxDB to store your data and connect it to Grafana to create beautiful, real-time dashboards.

grafana

Understanding the Tools

Linux

What are Grafana and InfluxDB?

InfluxDB is a special type of database made specifically for handling time-series data. This means it is very good at storing information that changes over time, like the temperature of a room every minute or the CPU usage of a computer every second. Instead of keeping data in traditional tables, InfluxDB organizes it by time so you can quickly search and find trends from the past.

Grafana is an open-source tool used to create visual dashboards and graphs. While InfluxDB is great at storing the data behind the scenes, it does not give you an easy way to look at it. Grafana acts as the display layer, taking the raw numbers from InfluxDB and turning them into colorful charts, gauges, and alerts that anyone can understand at a glance.

Together, these two tools create a powerful monitoring system. InfluxDB collects and safely stores all the continuous streams of data coming from your servers, apps, or sensors. Then, Grafana connects directly to InfluxDB to read that data and display it in real-time, helping you monitor system health and spot problems quickly.

Prerequisites

  • A computer, server, or virtual machine running Debian or Ubuntu Linux.
  • Command-line access to the system with sudo (administrator) privileges.
  • A stable internet connection to download the required software packages.
  • Network access to ports 8086 (InfluxDB) and 3000 (Grafana) on your machine.

Step-by-Step Installation

1

Install Prerequisites and InfluxDB v2

First, we need to ensure your system has the tools to download external keys, then add the official InfluxData repository using the modern, secure keyring path and install the database.
BASH
# 1. Install prerequisites required for downloading keys and adding repositories
sudo apt-get update
sudo apt-get install -y apt-transport-https software-properties-common wget gnupg

# 2. Download the current InfluxData GPG key to the modern keyrings directory
sudo mkdir -p /etc/apt/keyrings
wget -q -O - https://repos.influxdata.com/influxdata-archive.key | gpg --dearmor | sudo tee /etc/apt/keyrings/influxdata-archive.gpg > /dev/null

# 3. Add the InfluxData repository using the new keyring path
echo 'deb [signed-by=/etc/apt/keyrings/influxdata-archive.gpg] https://repos.influxdata.com/debian stable main' | sudo tee /etc/apt/sources.list.d/influxdata.list

# 4. Update your package manager and install InfluxDB v2
sudo apt-get update
sudo apt-get install -y influxdb2

# 5. Start the service and enable it to run on boot
sudo systemctl enable --now influxdb
2

Initialize InfluxDB and Generate a Token

Before installing Grafana, you need to set up your InfluxDB admin account and generate an API token so Grafana has permission to read your data.
  1. Open your web browser and navigate to http://<your-server-ip>:8086 (use http://localhost:8086 if installing locally).
  2. Click Get Started.
  3. Enter a Username, Password, Initial Organization Name (e.g., my-org), and an Initial Bucket Name (e.g., system-metrics).
  4. Click Continue, then click Configure Later.
  5. In the left-hand sidebar, navigate to the up-arrow icon (Load Data) > API Tokens.
  6. Click Generate API Token and select All Access API Token (or a Custom token strictly for your specific bucket).
  7. Copy this token and paste it into a safe notepad; you will need it in Step 4.
3

Install Grafana OSS

Because we already installed the prerequisites in Step 1, we can jump straight to downloading the Grafana keys and installing the open-source edition.
BASH
# 1. Download the Grafana GPG key
sudo mkdir -p /etc/apt/keyrings
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null

# 2. Add the Grafana stable repository
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list

# 3. Update your package manager and install Grafana
sudo apt-get update
sudo apt-get install -y grafana

# 4. Start the service and enable it to run on boot
sudo systemctl enable --now grafana-server
4

Connect Grafana to InfluxDB

Now we link the two platforms so Grafana can query the data stored inside InfluxDB.
  1. Open your web browser and navigate to http://<your-server-ip>:3000 (use http://localhost:3000 if installing locally).
  2. Log in using the default credentials: Username: admin / Password: admin (you will be prompted to change this).
  3. In the left-hand menu, go to Connections (or the gear icon) > Data sources.
  4. Click Add data source and select InfluxDB.
  5. Configure the connection exactly as follows:
    • Query Language: Change this from InfluxQL to Flux (critical for v2).
    • URL: http://localhost:8086 (or your server's IP if hosted elsewhere).
    • Basic Auth: Leave this turned off.
    • Organization: Enter the exact Organization name you created in Step 2.
    • Token: Paste the API token you generated in Step 2.
    • Default Bucket: Enter the exact Bucket name you created in Step 2.
  6. Scroll to the bottom and click Save & test. You should see a green checkmark saying "Data source is working" or "3 buckets found".

Discover CTCservers Dedicated Server Locations

CTCservers servers are available around the world, providing diverse options for hosting websites. Each region offers unique advantages, making it easier to choose a location that best suits your specific hosting needs.