A Step-by-Step Guide to Set Up InfluxDB Time Series Database on Your Raspberry Pi

Learn how to install and configure InfluxDB, a powerful time series database, on your Raspberry Pi. Follow along with this comprehensive guide for easy installation and setup. …


Updated September 10, 2023

Need help with your Raspberry Pi?
Contact Me!

Do you love silly Raspberry Pi Projects?
Check out my this YouTube Channel!


Learn how to install and configure InfluxDB, a powerful time series database, on your Raspberry Pi. Follow along with this comprehensive guide for easy installation and setup.

InfluxDB is an open-source time series database designed for fast, high-throughput storage and retrieval of metrics. It’s perfect for monitoring and analyzing IoT data, real-time application metrics, and more. In this article, we will go through the process of installing InfluxDB on your Raspberry Pi step by step.

Requirements

Before you begin, make sure you have the following:

  • A Raspberry Pi (any model) with Raspbian OS installed and updated
  • Access to the internet for downloading packages
  • Basic knowledge of Linux command line and terminal operations

Step 1: Update your system

First, ensure that your Raspberry Pi is up to date by running the following commands in a terminal window:

sudo apt update && sudo apt upgrade

This will download the latest package lists and install any available updates.

Step 2: Install Go language

InfluxDB is written in Go, so we need to install the Go programming language on our Raspberry Pi. Run the following commands to add the Go repository and install it:

sudo apt-get install golang-go

This will install the latest version of Go for your system.

Step 3: Install InfluxDB dependencies

InfluxDB depends on some libraries that need to be installed before we can build it from source. Run the following commands to install these dependencies:

sudo apt-get install git

This will install Git, which is used for version control and cloning repositories.

Step 4: Clone the InfluxDB repository

Next, clone the official InfluxDB repository from GitHub using the following command:

git clone https://github.com/influxdata/influxdb

This will download the latest version of the InfluxDB source code to your Raspberry Pi.

Step 5: Build and install InfluxDB

Navigate to the cloned directory and build the InfluxDB binary using the following commands:

cd influxdb
go build -o influxdb ./cmd/influxd
sudo cp influxdb /usr/local/bin/

This will compile the InfluxDB source code and copy the resulting binary to the /usr/local/bin/ directory, making it accessible from anywhere on your system.

Step 6: Create an InfluxDB configuration file

Create a new file called influxdb.conf in the /etc/ directory using the following command:

sudo nano /etc/influxdb.conf

Add the following basic configuration to the file and save it:

[meta]
  dir = "/var/lib/influxdb/meta"
  logging-enabled = true
  
[data]
  dir = "/var/lib/influxdb/data"
  wal-dir = "/var/lib/influxdb/wal"
  query-log-enabled = true
  
[http]
  bind-address = ":8086"

This file specifies the directories for storing InfluxDB data and metadata, as well as the HTTP port to listen on.

Step 7: Create directories for InfluxDB

Create the necessary directories by running these commands:

sudo mkdir /var/lib/influxdb/data
sudo mkdir /var/lib/influxdb/meta
sudo mkdir /var/lib/influxdb/wal

These directories will store InfluxDB’s data, metadata, and write-ahead log files.

Step 8: Set up systemd service file

Create a new systemd service file for InfluxDB by running the following command:

sudo nano /lib/systemd/system/influxdb.service

Add the following content to the file and save it:

[Unit]
Description=InfluxDB Time Series Database
After=network-online.target

[Service]
User=pi
Group=pi
ExecStart=/usr/local/bin/influxd -config /etc/influxdb.conf
Restart=always
RestartSec=10
KillSignal=SIGINT
TimeoutStopSec=20

[Install]
WantedBy=multi-user.target

This file tells systemd how to start and stop InfluxDB as a service. Replace pi with your username if needed.

Step 9: Enable and start the InfluxDB service

Enable the InfluxDB service to start automatically on boot and start it now by running these commands:

sudo systemctl enable influxdb
sudo systemctl start influxdb

Check the status of the InfluxDB service using this command:

sudo systemctl status influxdb

If everything is working correctly, you should see a message indicating that InfluxDB is active and running.

Step 10: Test your InfluxDB installation

You can test your InfluxDB installation by connecting to its HTTP API using curl or a web browser. Run the following command:

curl http://localhost:8086/ping

If InfluxDB is running, you should see {"version":"x.y.z"} in the output, where x.y.z is the version number of your installation.

You have now successfully installed and configured InfluxDB on your Raspberry Pi! You can start writing data to it or querying existing data using its HTTP API or command line interface. For more information on how to use InfluxDB, check out the official documentation.