Guides

How to Deploy a Telegraf, InfluxDB and Grafana Stack on Debian VPS

Follow this guide to learn how to deploy a telegraf, influxdb and grafana stack on debian vps!

This article provides a guide demonstrating how to deploy a Telegraf, InfluxDB and Grafana stack on Debian VPS server. Commonly known as TIG, Telegraf, InfluxDB and Grafana collectively make a powerful monitoring stack on your Debian 12 VPS server.

With InfluxDB for data storage, Telegraf for data collection, and Grafana for data visualization, this setup will help you monitor your systems and infrastructure efficiently and securely.

Deploying a Telegraf, InfluxDB and Grafana stack on a Debian 12 VPS involves several steps, from initial server setup to configuring the software. This guide will provide you with a detailed, step-by-step approach to get a Telegraf, InfluxDB and Grafana stack up and running on your Debian system.

Prerequisites

  • A Debian 12 VPS Server
  • Root or sudo privileges
  • Basic familiarity with Linux command line

Step 1: Update Your System

Before installing any new software, it’s best practice to update your system packages to the latest versions. This can help avoid conflicts and ensure compatibility.

sudo apt update && sudo apt upgrade -y

Step 2: Install InfluxDB

InfluxDB is a time-series database, ideal for storing and analyzing large amounts of timestamped data.

2.1 Add the InfluxData Repository

To install the latest version of InfluxDB, you need to add the official InfluxData repository.

wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -
echo "deb https://repos.influxdata.com/debian stable main" | sudo tee /etc/apt/sources.list.d/influxdb.list

2.2 Install InfluxDB

Now that the repository is added, update your package list and install InfluxDB:

sudo apt update
sudo apt install influxdb

2.3 Start and Enable InfluxDB

To ensure InfluxDB starts automatically at boot:

sudo systemctl start influxdb
sudo systemctl enable influxdb

2.4 (Optional) Configure InfluxDB

You can edit the InfluxDB configuration file to set up things like data retention policies and authentication.

sudo nano /etc/influxdb/influxdb.conf

Make the necessary changes according to your needs and then restart InfluxDB to apply these changes:

sudo systemctl restart influxdb

2.5 Install Telegraf

Install Telegraf to collect and send data and metrics to InfluxDB:

curl -s https://repos.influxdata.com/influxdata-archive_compat.key > influxdata-archive_compat.key
echo '393e8779c89ac8d958f81f942f9ad7fb82a25e133faddaf92e15b16e6ac9ce4c influxdata-archive_compat.key' | sha256sum -c && cat influxdata-archive_compat.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg > /dev/null
echo 'deb [signed-by=/etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg] https://repos.influxdata.com/debian stable main' | sudo tee /etc/apt/sources.list.d/influxdata.list
sudo apt-get update && sudo apt-get install telegraf

2.6 Configure Telegraf

  1. Configure Telegraf: Telegraf configurations can be adjusted according to what metrics you want to collect.
    sudo nano /etc/telegraf/telegraf.conf
    
    • Find the [[outputs.influxdb]] section and set the URLs to point to your InfluxDB instance, typically urls = ["http://127.0.0.1:8086"].
    • Set the database name that Telegraf should write to. For example, database = "telegraf" (you might need to create this database in InfluxDB).

    Here is a sample configuration snippet:

    # Configuration for sending metrics to InfluxDB
    [[outputs.influxdb]]
      urls = ["http://localhost:8086"]
      database = "telegraf"
      timeout = "5s"
      username = "telegraf"
      password = "metricsmetrics"
    
  2. Start and Enable Telegraf:
    sudo systemctl start telegraf
    sudo systemctl enable telegraf
    

Step 3: Install Grafana

Grafana is an open-source platform for monitoring and observability, and it pairs well with InfluxDB for visualizing data.

3.1 Add Grafana Repository

Add the Grafana APT repository:

Related Post
sudo apt install -y software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list

3.2 Install Grafana

Update your package list and install Grafana:

sudo apt update
sudo apt install grafana

3.3 Start and Enable Grafana

Enable and start Grafana:

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

Step 4: Configure Grafana to Connect to InfluxDB

4.1 Access Grafana Web Interface

  • Grafana is now accessible via your web browser. Open http://:3000/
  • The default login is admin for both username and password.

4.2 Add InfluxDB as a Data Source

  • Once logged in, click on “Configuration” (gear icon on the left panel), then “Data Sources.”
  • Click “Add data source,” select “InfluxDB” as the type.
  • Configure the data source:
    • URL: http://localhost:8086
    • Database: The name of your InfluxDB database
    • User & Password: Credentials if you’ve set them in InfluxDB

4.3 Save and Test

  • Click “Save & Test” to ensure Grafana can connect to InfluxDB successfully.

Step 5: Create Dashboards

Now that Grafana is set up and connected to InfluxDB, you can create dashboards:

  • Click “+” on the left panel and select “Dashboard.”
  • Add panels and select the InfluxDB data source to start visualizing your data.

Step 6: Secure Your Setup

6.1 Configure Firewall

Restrict access to your VPS:

sudo apt install ufw
sudo ufw enable
sudo ufw allow ssh
sudo ufw allow 3000/tcp
sudo ufw allow 8086/tcp
sudo ufw reload

Step 6.2: Set Up HTTPS for Grafana

Before proceeding, ensure you have a domain name pointing to the IP address of your VPS, as Let’s Encrypt requires a valid domain for certificate issuance.

Step 6.2.1: Install Certbot

Certbot is a tool that simplifies the process of obtaining and renewing Let’s Encrypt certificates.

  1. Install Certbot:
    sudo apt install certbot
    
  2. Install the Python Certbot plugin for Nginx (if using Nginx as a reverse proxy):
    sudo apt install python3-certbot-nginx
    

    Alternatively, if you prefer using Apache as your reverse proxy, use:

    sudo apt install python3-certbot-apache
    

Step 6.2.2: Obtain an SSL/TLS Certificate

  1. For Nginx: Assuming you are using Nginx as a reverse proxy, replace your_domain.com with your domain name.
    sudo certbot --nginx -d your_domain.com
    

    Certbot will modify the Nginx configuration to serve Grafana over HTTPS automatically. Follow the prompts to configure your HTTPS settings, including the redirection of HTTP traffic to HTTPS.

  2. For Apache: If using Apache as a reverse proxy, use:
    sudo certbot --apache -d your_domain.com
    

    Similar to Nginx, Certbot will handle the modifications required to serve Grafana via HTTPS.

Step 6.2.3: Configure Grafana to Serve over HTTPS

If you are not using a web server like Nginx or Apache as a reverse proxy, you can configure Grafana itself to serve HTTPS:

  1. Open Grafana’s Configuration File:
    sudo nano /etc/grafana/grafana.ini
    
  2. Modify the Protocol, Cert File Paths: Find the [server] section in the configuration file, and make the following changes (uncomment lines by removing ; at the beginning):
    [server]
    protocol = https
    http_port = 3000
    domain = your_domain.com
    cert_file = /etc/letsencrypt/live/your_domain.com/fullchain.pem
    cert_key = /etc/letsencrypt/live/your_domain.com/privkey.pem
    
  3. Restart Grafana: To apply the changes, restart Grafana:
    sudo systemctl restart grafana-server
    

Step 6.2.4: Verify HTTPS Setup

  1. Open your browser and navigate to your domain:
    https://your_domain.com:3000
    

    You should see the Grafana login page served over HTTPS with a secure connection indicated by a padlock icon in the address bar of your browser.

Step 6.2.5: Set Up Automatic Renewal

Let’s Encrypt certificates are valid for 90 days. To automate the renewal process:

  1. Edit the crontab:
    sudo crontab -e
    
  2. Add a line to run certbot renew twice a day:
    0 */12 * * * certbot renew --quiet
    

This cron job will check if the certificate is due for renewal every twelve hours and renew it if necessary.

Conclusion

Your Debian 12 VPS now has InfluxDB and Grafana installed and configured. This setup is ideal for monitoring applications and systems using time-series data. Secure access and regular updates are recommended to maintain the integrity and performance of your monitoring system.

Editorial Staff

Rad Web Hosting is a leading provider of web hosting, Cloud VPS, and Dedicated Servers in Dallas, TX and Phoenix, AZ.

Recent Posts

4 Quick Steps to Install Hestia Control Panel on Cloud VPS

This article provides a guide for how to install Hestia Control Panel on Rad Web Hosting cloud VPS server. What… Read More

2 hours ago

How to Choose the Best Dedicated Server Hosting Services

This guide will show you how to choose the best dedicated server hosting services for your business or project requirements… Read More

2 hours ago

7 Quick Steps for Managing Docker Containers on Debian VPS Servers

Docker has revolutionized the software development industry by making it possible to package applications into containers. This guide provides 7… Read More

2 hours ago

How to Link Your Reseller Server to WHMCS for Automated Provisioning

Resellers require access to WHM (Web Host Manager) in order to create and administer cPanel accounts and hosting packages. To… Read More

4 hours ago

Mastering LVM Management on Ubuntu VPS: A Comprehensive Guide

This article provides a comprehensive guide to mastering LVM management on Ubuntu VPS servers. Introduction Logical Volume Management (LVM) is… Read More

4 hours ago

What are the Benefits of Reseller Hosting?

This article provides an overview of the benefits of reseller hosting. Reseller hosting offers numerous benefits. What are the Benefits… Read More

4 hours ago