Installing InfluxDB to the Raspberry Pi (2024)

In this Raspberry Pi InfluxDB tutorial, we will be showing you how to set up and install InfluxDB to the Raspbian operating system.

Installing InfluxDB to the Raspberry Pi (1)

We will also be showing you how to enable authentication on your InfluxDB server to improve its security, as well as showing you how to interact with the database through the command line.

For those who are wondering what InfluxDB is, it is a time series based database system. This means that each data point in the database will contain a timestamp.

Being time series based makes InfluxDB one of the best databases for monitoring metrics and events. You can easily use InfluxDB to store information like the temperature in a room or the CPU usage of a system.

InfluxDB is the perfect database software to go alongside the popular visualization tool Grafana. Grafana has inbuilt support for displaying data from an InfluxDB database.

Equipment

Below is all the equipment that you will need to set up InfluxDB on your Raspberry Pi.

Recommended

  • Raspberry Pi
  • Micro SD Card
  • Power Supply
  • Ethernet Cable or Wi-Fi

Optional

  • USB Keyboard
  • USB Mouse
  • HDMI Cable

Installing InfluxDB to the Raspberry Pi

1. The first thing we should do before installing InfluxDB to the Raspberry Pi is making sure that all the currently installed packages are up to date.

We can upgrade all installed packages by running the following two commands.

sudo apt updatesudo apt upgrade

2. With everything now up to date, we can now proceed with installing InfluxDB to the Raspberry Pi.

Our next step is to add the InfluxDB repository key to our Raspberry Pi.

Adding the key will allow the package manager on Raspbian to search the repository and verify the packages its installing.

We can add the InfluxDB key by running the following command.

curl https://repos.influxdata.com/influxdb.key | gpg --dearmor | sudo tee /usr/share/keyrings/influxdb-archive-keyring.gpg >/dev/null

This command will download the key using curl and pass it directly into the “gpg” program by using a pipe “|“. Once the keyring has been de-armored it gets saved into the “/usr/share/keyrings/” directory.

3. Now that we have the InfluxDB repository key installed to our Raspberry Pi, we will need to go ahead and add its repository to the sources list.

Now enter the following command to add the InfluxDB repository to the sources list. Make sure you pick the right command for the version of Raspbian that you are running.

Most users running on new installations of Raspbian will likely be running Raspbian Buster.

Raspbian / Raspberry Pi OS

echo "deb [signed-by=/usr/share/keyrings/influxdb-archive-keyring.gpg] https://repos.influxdata.com/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/influxdb.list

Ubuntu (or Ubuntu Mate)

echo "deb [signed-by=/usr/share/keyrings/influxdb-archive.keyring.gpg] https://repos.influxdata.com/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/influxdb.list

4. With the repository added, we now need to go ahead and update the package list again.

We need to do this so that the apt package manager searches the repository that we just added for packages. The operating system does not automatically do this.

Run the following command on your Raspberry Pi to update the package list.

sudo apt update

5. Now that we have set up the repository, we can now move on to installing the InfluxDB software.

To install InfluxDB to our Raspberry Pi, all we need to do is run the command below.

sudo apt install influxdb

6. With InfluxDB now installed to our Raspberry Pi, let’s now get it to start at boot.

We can do this by making use of the systemctl service manager to enable our InfluxDB service file.

Run the following two commands to enable InfluxDB to start at boot on your Raspberry Pi.

sudo systemctl unmask influxdbsudo systemctl enable influxdb

The first command we use unmasks the influxdb service file. Unmasking the service ensures that we can enable and start the service as a masked service is unable to be started.

Our second command enables the influxdb service. This command will tell the service manager to keep an eye on the “influxdb.service” file and setup the service based on its contents.

7. Now that everything has been set up, we can now proceed to start up InfluxDB on our Raspberry Pi.

To start up the InfluxDB server, we will need to run the following command. The service manager will then start up the service and begin monitoring it.

sudo systemctl start influxdb

Using InfluxDB on your Raspberry Pi

1. As we have now installed InfluxDB, we can now start talking with the database.

To do this, we will need to launch up Influx’s command-line tool by running the command below.

You don’t have to worry about specifying an address to connect to as the tool will automatically detect the local installation of InfluxDB.

By default, InfluxDB has no users setup. In our next section, we will explore creating an admin user to lock down access to your InfluxDB. For now, however, we will quickly explore InfluxDB.

influx

2. InfluxDB comes with no databases by default, so our first task will be to create one.

Creating a database is simple in InfluxDB and can be done by using “CREATE DATABASE <DBNAME>“.

For our example, we will be creating a database called “pimylifeuptemperature“.

CREATE DATABASE pimylifeuptemperature

3. Before we can start modifying our new database, we must tell the CLI to “use” it.

Using a database is as simple as running the following command.

USE pimylifeuptemperature

4. Our next step is to write some data to our newly created InfluxDB database.

To do this, we must first get a basic understanding of InfluxDB’s datastore.

Data in InfluxDB are sorted by “time series“. These “time series” can contain as many or as little data points as you need. Each of these data points represents a single sample of that metric.

A data point consists of the time, a measurement name such as “temperature”, and at least one field. You can also use tags which are indexed pieces of data that are a string only. Tags are essential for optimizing database lookups.

If you are familiar with the general layout of an SQL table, you can consider “time” to be the primary index, measurement as the table name, and the tags and fields as the column names.

You do not need to specify the timestamp unless you want to specify a specific time and date for the data point.

Below we have included the basic format of an InfluxDB data point.

<measurement>[,<tag-key>=<tag-value>...] <field-key>=<field-value>[,<field2-key>=<field2-value>...] [unix-nano-timestamp]

If you would like to learn more about the InfluxDB line syntax, then you can check out the InfluxDB official documentation.

5. Now that we have a basic understanding of data in InfluxDB, we can now proceed to add our very first data point to our database.

For this example database, we are going to be storing measurements of the “temperature” of various locations around a house.

So for this, we will be inserting data points with a measurement name of “temperature” and a tag key of “location“, and a field key of “value“.

For our first sample point, we will be saying the location is the “living_room“, and the value is “20” .

INSERT temperature,location=living_room value=20

6. To make the data more interesting for showing off “selecting” data in InfluxDB, let’s go ahead and add some more random data.

Enter the following few commands to enter some extra data into our database. These are just variations of the above “INSERT” command but with the value and location adjusted.

INSERT temperature,location=living_room value=10INSERT temperature,location=bedroom value=34INSERT temperature,location=bedroom value=23

7. Now that we have some sample data, we can now show you how to query this data using “SELECT“.

To start with, you can retrieve all data from a measurement by using a command like below. This command will grab all fields and keys from the specified measurement.

SELECT * FROM temperature

Using that command with our sample data you should get a result like we have below.

name: temperaturetime location value---- -------- -----1574055049844513350 living_room 201574055196564029842 living_room 101574055196576516557 bedroom 341574055197188117724 bedroom 23

8. Let’s say that you now only wanted to retrieve the temperature of the bedroom. You can do that by making use of the “WHERE” statement alongside a “SELECT” statement.

We also specify the name of the tags/fields that we want to retrieve the values from.

When querying tag fields, you need to remember that all tags are considered to be strings. This means that we must wrap the value we are searching for in single quotes.

SELECT value FROM temperature WHERE location='bedroom'

With that command, you should receive the following data set, showing only the temperature value in the bedroom.

Which in our example data’s case, this should be 34 and 23.

name: temperaturetime location value---- -------- -----1574055049844513350 living_room 201574055196564029842 living_room 101574055196576516557 bedroom 341574055197188117724 bedroom 23

9. At this point, you should now have a basic understanding of InfluxDB and how its data works.

Adding Authentication to InfluxDB

1. The next step is to add extra authentication to our InfluxDB installation on the Raspberry Pi. Without authentication, anyone could interact with your database.

To get started, we need to first create a user to act as our admin.

To create this user, we must first load up the InfluxDB CLI tool by running the following command.

influx

2. Within this interface, we can create a user that will have full access to the database. This user will act as our admin account.

To create this admin user, run the following command within InfluxDB’s CLI tool.

Make sure that you replace <password> with a secure password of your choice.

CREATE USER admin WITH PASSWORD '<password>' WITH ALL PRIVILEGES

This command will create a new user called “admin” with your chosen password and grant it all privileges.

3. With that done, you can now exit out of InfluxDB by typing in “exit” and pressing ENTER.

4. Our next job is to modify the InfluxDB config file to enable authentication.

We can begin editing the file by using the command below.

sudo nano /etc/influxdb/influxdb.conf

5. Within this file, use CTRL + W to find the [HTTP] section and add the following options underneath that section.

Find

[HTTP]

Add Below

auth-enabled = truepprof-enabled = truepprof-auth-enabled = trueping-auth-enabled = true

6. Once added, save the file by pressing CTRL + X, then Y, followed by ENTER.

7. Now, as we have made changes to InfluxDB’s configuration, we will need to go ahead and restart the service by using the following command.

Restarting the service will ensure that our configuration changes are read in.

sudo systemctl restart influxdb

8. As we have now turned InfluxDB’s authentication on, we will need to enter our username and password before using the InfluxDB CLI tool.

You can use the “auth” command within the tool or pass the username and password in through the command line, as we have below.

influx -username admin -password <password>

Hopefully, at this point, you will now have successfully set up InfluxDB on your Raspberry Pi. You should now have a basic understanding of InfluxDB as well as have authentication mode enabled.

You can easily see how using this database model will make storing data from sensors and other sources very useful.

If you have run into any issues with getting a Raspberry Pi InfluxDB up and running, then feel free to drop a comment below.

Recommended

Running Raspberry Pi Desktop within VirtualBox

The Ultimate Guide to the Raspi-Config Tool

Using the ping Command on Linux

Arduino Traffic Light Project

Raspberry Pi Epiphany Browser (Gnome Web)

How to Upgrade Raspbian Wheezy to Raspbian Jessie

Installing InfluxDB to the Raspberry Pi (2024)

FAQs

How do I open InfluxDB on Raspberry Pi? ›

Install InfluxDB
  1. First of all, update the aptitude package: ...
  2. Then, add the InfluxDB repository key to your industrial Raspberry Pi PLC in order to allow the package manager on Raspbian to search the repository and verify the packages installed. ...
  3. Add the repository to the sources list. ...
  4. Update the package list again.
23 Sept 2021

How do I install InfluxDB? ›

Once brew is installed, you can install InfluxDB by running:
  1. brew update brew install influxdb. To have launchd start InfluxDB at login, run:
  2. ln -sfv /usr/local/opt/influxdb/*.plist ~/Library/LaunchAgents. And then to start InfluxDB now, run:
  3. launchctl load ~/Library/LaunchAgents/homebrew.mxcl.influxdb.plist.

How does Python connect to InfluxDB? ›

Creating the Connection
  1. # importing the required module.
  2. from influxdb import InfluxDBClient.
  3. # defining the host and port.
  4. my_Client = InfluxDBClient(host = 'localhost', port = 8086)

How do I launch InfluxDB? ›

Note:* To run InfluxDB, start the influxd daemon (InfluxDB service) using the InfluxDB command line interface. Once you've started the influxd daemon, use localhost:8086 to log in to your InfluxDB instance.

How do I connect to InfluxDB server? ›

By default, InfluxDB runs on localhost. -import Import new data from a file or import a previously exported database from a file. See -import. -password 'password' The password influx uses to connect to the server.

How do I view my database in InfluxDB? ›

Run a SHOW DATABASES query

The query returns database names in a tabular format. This InfluxDB instance has two databases: NOAA_water_database and _internal .

Does InfluxDB have a UI? ›

The InfluxDB user interface (UI) provides tools for building custom dashboards to visualize your data.

What is InfluxDB and Grafana? ›

InfluxDB is a time series database built specifically for storing time series data, and Grafana is a visualization tool for time series data.

How do I view my database in InfluxDB? ›

Run a SHOW DATABASES query

The query returns database names in a tabular format. This InfluxDB instance has two databases: NOAA_water_database and _internal .

Does InfluxDB have a UI? ›

The InfluxDB user interface (UI) provides tools for building custom dashboards to visualize your data.

How do I add a user to InfluxDB? ›

To create a new user, use the influx user create command and include the following: Username. Organization name or organization ID to add the user to (provided in the output of influx org list )

How do I uninstall InfluxDB? ›

InfluxDB 2.0 stores all of its data in ~/. influxdbv2 ; you can delete this directory to remove your data and configuration and start over. If you want to completely uninstall the database and remove all of its data, you can delete the four files that came in the download as well as your ~/. influxdbv2 directory.

Top Articles
Latest Posts
Article information

Author: Saturnina Altenwerth DVM

Last Updated:

Views: 5963

Rating: 4.3 / 5 (44 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Saturnina Altenwerth DVM

Birthday: 1992-08-21

Address: Apt. 237 662 Haag Mills, East Verenaport, MO 57071-5493

Phone: +331850833384

Job: District Real-Estate Architect

Hobby: Skateboarding, Taxidermy, Air sports, Painting, Knife making, Letterboxing, Inline skating

Introduction: My name is Saturnina Altenwerth DVM, I am a witty, perfect, combative, beautiful, determined, fancy, determined person who loves writing and wants to share my knowledge and understanding with you.