Log inSign up

Store metrics and sensor data in InfluxDB

Add the InfluxData APT repository, install influxdb2 and influxdb2-cli, start the service and run influx setup to create the first user, organization, bucket and admin token. Keep port 8086 on localhost or behind HTTPS, give every writer its own token limited to one bucket, set a retention period so old points expire, and schedule influx backup.

Topic: Databases · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13 · Updated 2026-12-03

Which InfluxDB release fits a VPS?

For a self-managed server that collects metrics, prices or sensor readings, InfluxDB 2 OSS is the mature, packaged choice with a built-in web UI, buckets with retention, scoped tokens and both Flux and InfluxQL queries. That is what this guide installs.

The project also ships InfluxDB 3 Core, a rewrite that stores data as Parquet files and queries it with SQL. It suits new projects that want SQL and recent data at high speed, and it installs from an upstream script, a tarball or a container image. Its API and tooling differ from version 2, so pick one line per project rather than mixing them.

Memory needs depend on how many distinct series (unique tag combinations) you store more than on the raw number of points. A few thousand series fit comfortably in 1 to 2 GB of RAM; tens of thousands want 4 GB or more. Start from a fresh Ubuntu 24.04 or Debian 12 server and log in as a sudo user.

How do you install InfluxDB from the official repository?

Download the InfluxData signing key, compare its fingerprint with the one published on the InfluxData download page, convert it to a keyring and add the repository line.

sudo apt update
sudo apt install -y curl gnupg
curl -fsSL -O https://repos.influxdata.com/influxdata-archive.key
gpg --show-keys --with-fingerprint influxdata-archive.key
sudo install -d -m 0755 /etc/apt/keyrings
gpg --dearmor < influxdata-archive.key | sudo tee /etc/apt/keyrings/influxdata-archive.gpg >/dev/null
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
sudo apt update
sudo apt install -y influxdb2 influxdb2-cli
sudo systemctl enable --now influxdb
influxd version
influx version

The same repository serves Ubuntu and Debian. Data lands in /var/lib/influxdb/, and the service runs as the influxdb user.

How do you run the first setup?

Run influx setup once on the server. It creates the first user, organization and bucket, and stores an operator token in a local CLI profile so later commands need no extra flags.

influx setup \
  --username admin \
  --password 'Long-Random-Passphrase-31' \
  --org example \
  --bucket metrics \
  --retention 30d \
  --force
influx bucket list
influx auth list

The operator token can do anything, including deleting every organization, so treat the profile file in ~/.influxdbv2/configs like a private key and avoid putting that token into applications. Clear the password from your shell history afterwards with history -d, or omit --password to be prompted for it.

How do you keep port 8086 private and add HTTPS?

Bind the HTTP API to loopback in /etc/influxdb/config.toml and publish it through a reverse proxy with a certificate when something outside the server needs it.

http-bind-address = "127.0.0.1:8086"
sudo systemctl restart influxdb
sudo ss -ltnp | grep 8086

With a DNS record for metrics.example.net, a two-line Caddy site serves the UI and API over HTTPS:

metrics.example.net {
    reverse_proxy 127.0.0.1:8086
}

See Caddy HTTPS for installing Caddy. InfluxDB can also terminate TLS itself with tls-cert and tls-key paths in the same config file, which is handy when no web server runs on the machine. Keep 8086 closed in ufw either way. For a quick look at the UI without any public exposure, use an SSH tunnel: ssh -N -L 8086:127.0.0.1:8086 deploy@198.51.100.24, then browse to http://127.0.0.1:8086.

How do you write and query data?

Points use line protocol: a measurement name, comma-separated tags, fields and an optional timestamp. Write one from the CLI and read it back with Flux.

influx write --bucket metrics --precision s \
  "cpu,host=web1,region=eu usage_user=12.5,usage_system=3.1 $(date +%s)"
influx query 'from(bucket: "metrics")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "cpu")'

Applications usually send batches over HTTP. The same write as a raw API call, with a token in a header:

curl -s -X POST "http://127.0.0.1:8086/api/v2/write?org=example&bucket=metrics&precision=s" \
  -H "Authorization: Token $INFLUX_TOKEN" \
  --data-binary "cpu,host=web2 usage_user=8.4 $(date +%s)"

Keep tag values to a bounded set (host names, regions, symbols) and put changing numbers in fields. A tag that holds user IDs or random strings creates a new series per value and makes memory use climb fast.

If a tool expects InfluxQL, map a database name to the bucket with influx v1 dbrp create and query through the version 1 compatible endpoint.

How do you give each app its own token?

Create a token per writer that can only write to its bucket, and a separate read token for dashboards. A leaked token then exposes one bucket, not the whole server.

BUCKET_ID=$(influx bucket list --name metrics --hide-headers | awk '{print $1}')
influx auth create --org example --write-bucket "$BUCKET_ID" --description "telegraf web1"
influx auth create --org example --read-bucket "$BUCKET_ID" --description "grafana read"
influx auth list

Store each token in the client config with file mode 600. Revoke one with influx auth delete --id ID when a host is retired. Dashboards in Grafana connect with the read token.

How do you collect server metrics with Telegraf?

Install Telegraf from the same repository, point its InfluxDB v2 output at the server with the write token, and it ships CPU, memory, disk and network figures every ten seconds.

sudo apt install -y telegraf
sudo tee /etc/telegraf/telegraf.d/out.conf >/dev/null <<'EOF'
[[outputs.influxdb_v2]]
  urls = ["http://127.0.0.1:8086"]
  token = "$INFLUX_WRITE_TOKEN"
  organization = "example"
  bucket = "metrics"
EOF
echo 'INFLUX_WRITE_TOKEN=paste-the-write-token' | sudo tee /etc/default/telegraf
sudo chmod 600 /etc/default/telegraf
sudo systemctl restart telegraf
sudo journalctl -u telegraf -n 20 --no-pager

Telegraf expands environment variables in its config, so the token stays in a root-only file. Other servers can send to the same InfluxDB through the HTTPS name from the previous step.

How do you handle retention, backups and upgrades?

Set a retention period on every bucket so disk use stays flat, back up with influx backup on a timer, and upgrade with apt.

influx bucket update --id "$BUCKET_ID" --retention 90d
sudo install -d -o "$USER" /var/backups/influx
influx backup /var/backups/influx/$(date +%F)
influx restore /var/backups/influx/2026-12-01 --bucket metrics --new-bucket metrics_restored
du -sh /var/lib/influxdb

Keep long histories cheaply by writing hourly averages into a second bucket with a longer retention through an InfluxDB task, and let the raw bucket expire. Package upgrades within version 2 arrive with sudo apt upgrade; read the release notes first. When the service fails, check sudo journalctl -u influxdb -n 50 --no-pager: typical causes are a bad TOML line, a full disk and memory pressure from too many series. Copy the backup folder off the server, and add the daily backups add-on for a full disk copy.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A1-2metrics for a handful of servers1 vCPU, 2 GB RAM, 50 GB NVMe$7.20/mo$43.20 for 6 months
A2-4more series and longer retention2 vCPU, 4 GB RAM, 100 GB NVMe$14.40/mo$43.20 for 3 months

Questions about InfluxDB for time series

What port does InfluxDB use?

TCP 8086 for the HTTP API and the web UI. Keep it on localhost and publish it through HTTPS or an SSH tunnel.

Should I use InfluxDB 2 or InfluxDB 3 Core?

Use version 2 for a packaged server with a UI, Flux and InfluxQL that many tools already support. Choose 3 Core for a new project that wants SQL queries and Parquet storage, and check that your tools support it.

How long does InfluxDB keep data?

As long as the bucket retention period says. A bucket with infinite retention keeps everything, so set a period such as 30 or 90 days for raw metrics.

What is cardinality and why does it matter?

Cardinality is the number of unique series, meaning distinct combinations of measurement and tag values. High cardinality raises memory use and slows queries, so keep unbounded values in fields, not tags.

Can I reset the admin password?

Yes, with the operator token: influx user password --name admin. Without any token, you need to restore from backup or start a fresh instance.