InfluxDB is a time-series database designed to store metrics, events and sensor readings that arrive continuously with a timestamp. InfluxDB 2 bundles the storage engine, an HTTP API, a web UI and the Flux query language in a single service. In this tutorial you will install InfluxDB 2 on Ubuntu 24.04 from the official InfluxData repository, create an organization and buckets with retention periods, collect system metrics with Telegraf, query them with Flux and schedule daily backups.

Prerequisites

To follow this guide you need:

  • A server running Ubuntu 24.04 LTS, for example a CubePath VPS, with a non-root user with sudo privileges.
  • At least 2 GB of RAM and SSD storage. Production workloads with many series need more memory.
  • Port 8086 reachable only from trusted addresses if you want to use the web UI remotely.

Step 1 - Adding the InfluxData repository

InfluxDB 2 and Telegraf are published in the official InfluxData APT repository. Download the signing key:

curl -fsSLO https://repos.influxdata.com/influxdata-archive.key

Display its fingerprint and compare it with the one published in the InfluxData installation documentation before trusting it:

gpg --show-keys --with-fingerprint influxdata-archive.key

Convert the key to the binary format APT expects and store it in /etc/apt/keyrings:

sudo install -m 0755 -d /etc/apt/keyrings
gpg --dearmor < influxdata-archive.key | sudo tee /etc/apt/keyrings/influxdata-archive.gpg > /dev/null
rm influxdata-archive.key

Add the repository, restricted to that key:

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

Step 2 - Installing InfluxDB

Update the package index and install the server and the influx command-line client:

sudo apt update
sudo apt install influxdb2 influxdb2-cli

Enable and start the service:

sudo systemctl enable --now influxdb

Check that it is running and answering on port 8086:

systemctl status influxdb --no-pager
curl -s http://localhost:8086/health
{"name":"influxdb", "message":"ready for queries and writes", "status":"pass", "checks":[], "version": "v2.x.x", "commit": "..."}

InfluxDB stores its data in /var/lib/influxdb and reads its optional configuration from /etc/influxdb/config.toml.

Step 3 - Running the initial setup

A fresh InfluxDB instance has no users. The influx setup command creates the first user, an organization, a first bucket and an operator token with full access. Run it as your regular user, replacing your_strong_password with a password of at least 8 characters:

influx setup \
  --username admin \
  --password 'your_strong_password' \
  --org myorg \
  --bucket metrics \
  --retention 30d \
  --force
User	Organization	Bucket
admin	myorg		metrics

Besides creating these resources, influx setup saves a CLI configuration profile in ~/.influxdbv2/configs with the URL, organization and operator token, so the following influx commands work without extra flags. Confirm it:

influx config list
Active	Name	URL			Org
*	default	http://localhost:8086	myorg

If you prefer the browser, you can run the same setup from the web UI at http://your_server_ip:8086 instead, but open port 8086 only to your own IP (see Step 8).

Step 4 - Creating buckets and retention periods

A bucket is where data is written, and each bucket has a retention period after which InfluxDB deletes old data automatically. The metrics bucket you created keeps 30 days.

Create a second bucket for long-term data that keeps one year:

influx bucket create --name metrics_longterm --retention 365d

List all buckets and their retention:

influx bucket list
ID			Name			Retention	Shard group duration	Organization ID		Schema Type
0a1b2c3d4e5f6a7b	_monitoring		168h0m0s	24h0m0s			...		implicit
1b2c3d4e5f6a7b8c	_tasks			72h0m0s		24h0m0s			...		implicit
2c3d4e5f6a7b8c9d	metrics			720h0m0s	24h0m0s			...		implicit
3d4e5f6a7b8c9d0e	metrics_longterm	8760h0m0s	168h0m0s		...		implicit

To change the retention of an existing bucket, use its ID:

influx bucket update --id 2c3d4e5f6a7b8c9d --retention 90d

A retention of 0 means data is kept forever. Use it only when you have a plan for disk space.

Step 5 - Writing and querying data

InfluxDB receives data in line protocol: a measurement name, optional tags (indexed metadata), one or more fields (the values) and an optional timestamp. Write two points with the CLI:

influx write --bucket metrics 'server_load,host=web01 load1=0.64,load5=0.52'
influx write --bucket metrics 'server_load,host=web02 load1=1.20,load5=0.98'

Without a timestamp, InfluxDB uses the time the point was received. Read the data back with a Flux query:

influx query 'from(bucket: "metrics")
  |> range(start: -10m)
  |> filter(fn: (r) => r._measurement == "server_load" and r._field == "load1")'
Result: _result
Table: keys: [_start, _stop, _field, _measurement, host]
...  _field:string  _measurement:string  host:string  _time:time                      _value:float
...  load1          server_load          web01        2026-09-25T10:14:03.512000000Z  0.64
Table: keys: [_start, _stop, _field, _measurement, host]
...  load1          server_load          web02        2026-09-25T10:14:04.107000000Z  1.2

Every Flux query starts with from() and a range(). Always put range() first: it limits the data InfluxDB has to scan.

Applications write through the HTTP API with a token. Create a token that can only write to the metrics bucket. First get the bucket ID:

influx bucket list --name metrics

Then create the token, replacing your_bucket_id:

influx auth create --org myorg --write-bucket your_bucket_id --description "telegraf write"

The output includes the new token in the Token column. Copy it; you will use it in the next step.

Step 6 - Collecting server metrics with Telegraf

Telegraf is InfluxData's collection agent. It is in the same repository you added in Step 1:

sudo apt install telegraf

The package ships a very long example configuration that writes to InfluxDB 1.x by default. Keep it as a reference and replace it with a short configuration for InfluxDB 2:

sudo mv /etc/telegraf/telegraf.conf /etc/telegraf/telegraf.conf.example
sudo nano /etc/telegraf/telegraf.conf
[agent]
  interval = "10s"
  flush_interval = "10s"

[[outputs.influxdb_v2]]
  urls = ["http://127.0.0.1:8086"]
  token = "${INFLUX_TOKEN}"
  organization = "myorg"
  bucket = "metrics"

[[inputs.cpu]]
  percpu = false
  totalcpu = true

[[inputs.mem]]

[[inputs.disk]]
  ignore_fs = ["tmpfs", "devtmpfs", "overlay", "squashfs"]

[[inputs.diskio]]

[[inputs.net]]

[[inputs.system]]

The ${INFLUX_TOKEN} reference is read from the environment, which keeps the token out of the main configuration file. The Telegraf systemd service loads variables from /etc/default/telegraf. Create it with the write token from Step 5:

sudo nano /etc/default/telegraf
INFLUX_TOKEN=your_write_token

Restrict access to that file:

sudo chown root:telegraf /etc/default/telegraf
sudo chmod 0640 /etc/default/telegraf

Before starting the service, run one collection cycle in test mode. It prints the metrics to the terminal without sending them anywhere:

sudo -u telegraf telegraf --config /etc/telegraf/telegraf.conf --test --input-filter cpu:mem
> cpu,cpu=cpu-total,host=your-hostname usage_idle=97.8,usage_system=0.9,usage_user=1.1,... 1790000000000000000
> mem,host=your-hostname available=1622343680i,total=2061258752i,used_percent=21.3,... 1790000000000000000

Restart Telegraf so it picks up the new configuration, and check that it has no errors:

sudo systemctl restart telegraf
sudo journalctl -u telegraf -n 20 --no-pager

After a minute, query the CPU usage it collected, averaged per minute:

influx query 'from(bucket: "metrics")
  |> range(start: -10m)
  |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_idle" and r.cpu == "cpu-total")
  |> aggregateWindow(every: 1m, fn: mean, createEmpty: false)'

You should see one row per minute. You can also explore the data visually in the web UI under Data Explorer.

Step 7 - Backing up InfluxDB

influx backup takes a consistent copy of all buckets and metadata while the service is running. It needs the operator token. Store that token in a file only root can read. Show your tokens and copy the one with the description admin's Token:

influx auth list
sudo install -d -m 0700 /etc/influxdb/backup
sudo nano /etc/influxdb/backup/operator.token

Paste the operator token into the file, save it and restrict it:

sudo chmod 0600 /etc/influxdb/backup/operator.token

Create a backup script that writes a dated directory and keeps 7 days of backups:

sudo nano /usr/local/sbin/influxdb-backup
#!/usr/bin/env bash
set -euo pipefail

BACKUP_ROOT="/var/backups/influxdb"
TOKEN_FILE="/etc/influxdb/backup/operator.token"
TARGET="${BACKUP_ROOT}/$(date +%F)"

mkdir -p "${BACKUP_ROOT}"
rm -rf "${TARGET}"
influx backup "${TARGET}" --host http://127.0.0.1:8086 --token "$(cat "${TOKEN_FILE}")"

find "${BACKUP_ROOT}" -mindepth 1 -maxdepth 1 -type d -mtime +7 -exec rm -rf {} +

Make it executable and run it once to test it:

sudo chmod 0750 /usr/local/sbin/influxdb-backup
sudo /usr/local/sbin/influxdb-backup
sudo ls /var/backups/influxdb/

Schedule it every night at 03:15 with a cron file:

echo '15 3 * * * root /usr/local/sbin/influxdb-backup' | sudo tee /etc/cron.d/influxdb-backup

To restore everything on a new or empty instance, run influx restore with the --full flag, which replaces all existing data and metadata with the backup:

influx restore /var/backups/influxdb/2026-09-25 --full

Copy the backups to another server or object storage; a backup on the same disk does not protect against losing the server.

Step 8 - Securing access to port 8086

InfluxDB listens on all interfaces on port 8086 and every request needs a token, but the port should still not be open to the internet. If UFW is enabled, allow the web UI only from your own IP address:

sudo ufw allow from your_ip to any port 8086 proto tcp

If you do not need remote access at all, make InfluxDB listen only on localhost. Edit /etc/influxdb/config.toml:

sudo nano /etc/influxdb/config.toml
http-bind-address = "127.0.0.1:8086"

Restart the service and use an SSH tunnel (ssh -L 8086:localhost:8086 your_user@your_server_ip) to open the UI at http://localhost:8086 from your computer:

sudo systemctl restart influxdb

Troubleshooting

Error: failed to determine if instance has been configured. The service is not running or is not listening on port 8086. Check sudo journalctl -u influxdb -n 50 --no-pager and sudo ss -tlnp | grep 8086.

Telegraf logs 401 Unauthorized. The token in /etc/default/telegraf is wrong or lacks write access to the bucket. Create a new token with --write-bucket for the correct bucket ID and restart Telegraf.

Writes fail with field type conflict. A field was first written as one type (for example an integer, 12i) and later as another (a float, 12.5). Field types are fixed per measurement and shard; send the same type every time, or write the new data to a different field name.

Disk usage keeps growing. Check the retention of each bucket with influx bucket list. A bucket with retention 0 never deletes data.

Conclusion

InfluxDB 2 is now running on Ubuntu 24.04 with an organization, buckets with retention periods, Telegraf sending system metrics with a scoped token and nightly backups. As next steps, add Grafana with the InfluxDB data source (using Flux and a read-only token) to build dashboards, install Telegraf on your other servers pointing at this instance over the private network, and use InfluxDB tasks to downsample the 10-second data into the metrics_longterm bucket.