Why InfluxDB?
InfluxDB is purpose-built for time-series data, offering high-performance writes, efficient storage with compression, and powerful query capabilities through Flux. Ideal for DevOps monitoring, IoT, and real-time analytics.
Prerequisites
Minimum Requirements
- • 2 CPU cores
- • 2 GB RAM
- • 20 GB SSD storage
- • Ubuntu 20.04+ / Debian 11+
Recommended for Production
- • 4+ CPU cores
- • 8+ GB RAM
- • 100+ GB NVMe SSD
- • Dedicated data disk
Installation
Add InfluxDB Repository
Add the official InfluxData repository:
# Install prerequisites
sudo apt update
sudo apt install -y curl gnupg2
# Add InfluxData GPG key
curl -s https://repos.influxdata.com/influxdata-archive.key | \
gpg --dearmor | sudo tee /usr/share/keyrings/influxdb-archive-keyring.gpg > /dev/null
# Add repository (Ubuntu/Debian)
echo "deb [signed-by=/usr/share/keyrings/influxdb-archive-keyring.gpg] \
https://repos.influxdata.com/debian stable main" | \
sudo tee /etc/apt/sources.list.d/influxdb.listInstall InfluxDB 2.x
Install the latest InfluxDB 2.x version:
# Update package list
sudo apt update
# Install InfluxDB
sudo apt install -y influxdb2
# Start and enable service
sudo systemctl start influxdb
sudo systemctl enable influxdb
# Verify installation
influx versionInfluxDB v2.7.xInitial Setup
Configure InfluxDB with initial user, organization, and bucket:
# Run initial setup (interactive)
influx setup
# Or use non-interactive setup
influx setup \
--username admin \
--password YourSecurePassword123! \
--org my-organization \
--bucket my-bucket \
--retention 30d \
--forceImportant: Save the generated API token - you will need it for authentication.
Docker Installation
Deploy with Docker
Run InfluxDB in a Docker container:
# Create data directory
mkdir -p ~/influxdb2/{data,config}
# Run InfluxDB container
docker run -d \
--name influxdb \
-p 8086:8086 \
-v ~/influxdb2/data:/var/lib/influxdb2 \
-v ~/influxdb2/config:/etc/influxdb2 \
-e DOCKER_INFLUXDB_INIT_MODE=setup \
-e DOCKER_INFLUXDB_INIT_USERNAME=admin \
-e DOCKER_INFLUXDB_INIT_PASSWORD=YourSecurePassword123! \
-e DOCKER_INFLUXDB_INIT_ORG=my-organization \
-e DOCKER_INFLUXDB_INIT_BUCKET=my-bucket \
-e DOCKER_INFLUXDB_INIT_RETENTION=30d \
-e DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=my-super-secret-token \
influxdb:2.7Configuration
Main Configuration
Edit the main configuration file:
# InfluxDB 2.x Configuration
# Bolt path for metadata storage
bolt-path = "/var/lib/influxdb/influxd.bolt"
# Engine path for time-series data
engine-path = "/var/lib/influxdb/engine"
# HTTP configuration
[http]
bind-address = ":8086"
flux-enabled = true
# Logging configuration
[logging]
level = "info"
format = "auto"
# Storage configuration
[storage-cache]
max-memory-size = "1g"
snapshot-memory-size = "25m"
# Query configuration
[query]
concurrency = 10
queue-size = 10Performance Tuning
Optimize for production workloads:
# Increase memory limits for high-throughput
[storage-cache]
max-memory-size = "4g"
snapshot-memory-size = "100m"
# WAL configuration
[storage-wal]
max-concurrent-writes = 256
max-write-delay = "10m"
# Query limits
[query]
concurrency = 20
queue-size = 20Retention Policies
Configure data retention for buckets:
# Create bucket with retention
influx bucket create \
--name metrics \
--org my-organization \
--retention 7d
# Create bucket for long-term storage
influx bucket create \
--name metrics-archive \
--org my-organization \
--retention 365d
# List buckets
influx bucket list
# Update retention policy
influx bucket update \
--id <bucket-id> \
--retention 90dSecurity Hardening
API Token Management
Create tokens with appropriate permissions:
# Create read-only token
influx auth create \
--org my-organization \
--read-bucket my-bucket \
--description "Read-only access"
# Create write-only token
influx auth create \
--org my-organization \
--write-bucket my-bucket \
--description "Write-only access"
# List tokens
influx auth list
# Delete token
influx auth delete --id <token-id>Enable TLS/SSL
Configure HTTPS for secure communication:
# Generate self-signed certificate
sudo mkdir -p /etc/influxdb/ssl
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/influxdb/ssl/influxdb.key \
-out /etc/influxdb/ssl/influxdb.crt \
-subj "/CN=influxdb.example.com"
# Set permissions
sudo chown influxdb:influxdb /etc/influxdb/ssl/*
sudo chmod 600 /etc/influxdb/ssl/*[http]
bind-address = ":8086"
tls-cert = "/etc/influxdb/ssl/influxdb.crt"
tls-key = "/etc/influxdb/ssl/influxdb.key"
tls-min-version = "1.2"Firewall Configuration
Restrict network access:
# Allow InfluxDB port from specific IPs only
sudo ufw allow from 10.0.0.0/8 to any port 8086
# Or from specific hosts
sudo ufw allow from 192.168.1.100 to any port 8086
# Deny public access
sudo ufw deny 8086
# Enable firewall
sudo ufw enableBasic Operations
Writing Data
Write time-series data using various methods:
# Write using CLI (Line Protocol)
influx write \
--bucket my-bucket \
--org my-organization \
'cpu,host=server1,region=us-west usage=45.2 1625000000000000000'
# Write from file
influx write \
--bucket my-bucket \
--org my-organization \
--file data.lp
# Write using API
curl -XPOST "http://localhost:8086/api/v2/write?org=my-organization&bucket=my-bucket" \
--header "Authorization: Token $INFLUX_TOKEN" \
--header "Content-Type: text/plain" \
--data-binary 'cpu,host=server1 usage=45.2'Querying Data (Flux)
Query data using Flux query language:
# Basic query
influx query 'from(bucket: "my-bucket")
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == "cpu")'
# Query with aggregation
influx query 'from(bucket: "my-bucket")
|> range(start: -24h)
|> filter(fn: (r) => r._measurement == "cpu")
|> aggregateWindow(every: 1h, fn: mean)
|> yield(name: "hourly_avg")'Managing Resources
Manage buckets and organizations:
# List organizations
influx org list
# Create organization
influx org create --name production
# List buckets
influx bucket list
# Delete bucket
influx bucket delete --id <bucket-id>
# Create user
influx user create --name grafana --org my-organization
# Set user password
influx user password --name grafanaBackup & Recovery
Full Backup
Create a complete backup:
# Create backup directory
mkdir -p /backup/influxdb
# Full backup
influx backup /backup/influxdb/$(date +%Y%m%d) \
--host http://localhost:8086 \
--token $INFLUX_TOKEN
# Backup specific bucket
influx backup /backup/influxdb/metrics-$(date +%Y%m%d) \
--bucket metrics \
--host http://localhost:8086 \
--token $INFLUX_TOKENRestore from Backup
Restore data from backup:
# Full restore (new instance)
influx restore /backup/influxdb/20240101 \
--host http://localhost:8086 \
--token $INFLUX_TOKEN \
--full
# Restore specific bucket
influx restore /backup/influxdb/20240101 \
--bucket metrics \
--new-bucket metrics-restored \
--host http://localhost:8086 \
--token $INFLUX_TOKENMonitoring
Health Checks
Monitor InfluxDB health:
# Check health endpoint
curl http://localhost:8086/health
# Check readiness
curl http://localhost:8086/ready
# Get server status
influx ping{
"name": "influxdb",
"message": "ready for queries and writes",
"status": "pass",
"version": "2.7.1"
}Telegraf Integration
Use Telegraf to collect system metrics:
# Output to InfluxDB 2.x
[[outputs.influxdb_v2]]
urls = ["http://localhost:8086"]
token = "$INFLUX_TOKEN"
organization = "my-organization"
bucket = "telegraf"
# Collect CPU metrics
[[inputs.cpu]]
percpu = true
totalcpu = true
# Collect memory metrics
[[inputs.mem]]
# Collect disk metrics
[[inputs.disk]]
ignore_fs = ["tmpfs", "devtmpfs"]Troubleshooting
High Memory Usage
# Check current memory usage
influx query 'from(bucket: "_monitoring")
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == "go_memstats")'
# Reduce cache size in config and restart
sudo systemctl restart influxdbWrite Failures
# Check logs for errors
sudo journalctl -u influxdb -f
# Verify token permissions
influx auth list
# Check disk space
df -h /var/lib/influxdb
# Test write
influx write --bucket my-bucket 'test value=1'Service Issues
# Check service status
sudo systemctl status influxdb
# View detailed logs
sudo journalctl -u influxdb --no-pager -n 100
# Check config syntax
influxd print-config
# Check file permissions
ls -la /var/lib/influxdb/
sudo chown -R influxdb:influxdb /var/lib/influxdb/Quick Reference
Default Ports
- • HTTP API: 8086
Important Paths
- • Config: /etc/influxdb/config.toml
- • Data: /var/lib/influxdb/
- • Logs: journalctl -u influxdb
Common Commands
- • influx bucket list
- • influx write
- • influx query
- • influx backup/restore
Key Concepts
- • Organization → Workspace
- • Bucket → Database with retention
- • Measurement → Table
- • Tags → Indexed metadata
