1. InfluxDB概述与环境规划
InfluxDB是一款开源的时序数据库,专为存储和查询时间序列数据而设计。InfluxDB广泛应用于监控、IoT、金融分析等领域,具有高性能写入、灵活的数据保留策略、强大的查询语言等特点。更多学习教程www.fgedu.net.cn
1.1 InfluxDB版本说明
InfluxDB目前主要版本为InfluxDB 2.7,本教程以InfluxDB 2.7为例进行详细讲解。
$ influx version
Influx CLI 2.7.3 (git: 0cbee86d3d) build_date: 2024-01-01T00:00:00Z
# 查看服务器信息
$ influx server-config
{
“engine-path”: “/var/lib/influxdb/engine”,
“bolt-path”: “/var/lib/influxdb/influxd.bolt”,
“nats-port”: 0
}
1.2 环境规划
本次安装环境规划如下:
IP地址:192.168.1.51
HTTP端口:8086
RPC端口:8088
数据目录:/var/lib/influxdb
日志目录:/var/log/influxdb
备份目录:/backup/influxdb
存储规划:
数据保留期:30天
写入速率:100万点/秒
1.3 InfluxDB核心特性
1. 时序存储:专为时间序列数据优化
2. 高性能写入:支持每秒百万级数据点写入
3. Flux查询语言:强大的数据查询和分析能力
4. 数据保留策略:自动过期旧数据
5. 连续查询:自动聚合计算
6. 多协议支持:支持Line Protocol、HTTP API
7. 认证授权:完善的用户权限管理
8. Web UI:内置管理界面
2. 硬件环境要求与检查
在安装InfluxDB之前,需要对服务器硬件环境进行全面检查。学习交流加群风哥微信: itpux-com
2.1 最低硬件要求
CPU:2核心
内存:4GB
磁盘:20GB
推荐配置(生产环境):
CPU:8核心以上
内存:16GB以上
磁盘:500GB以上SSD
高负载环境配置:
CPU:16核心以上
内存:32GB以上
磁盘:1TB以上NVMe SSD
2.2 系统环境检查
# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.8 (Ootpa)
# 检查内核版本
# uname -a
Linux fgedudb01 4.18.0-477.10.1.el8_8.x86_64 #1 SMP Fri Apr 4 10:00:00 CST 2026 x86_64 x86_64 x86_64 GNU/Linux
# 检查内存信息
# free -h
total used free shared buff/cache available
Mem: 31Gi 1.0Gi 29Gi 256Mi 1.0Gi 30Gi
Swap: 7Gi 0B 7Gi
# 检查磁盘空间
# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/vg_system-lv_root 50G 2.5G 48G 5% /
/dev/sda2 1014M 150M 865M 15% /boot
/dev/mapper/vg_data-lv_data 500G 20G 480G 4% /data
/dev/mapper/vg_backup-lv_backup 100G 10G 90G 10% /backup
# 检查时间同步
# timedatectl status
Local time: 五 2026-04-04 10:00:00 CST
Universal time: 五 2026-04-04 02:00:00 UTC
RTC time: 五 2026-04-04 02:00:00
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
# 安装依赖包
# dnf install -y wget curl
2.3 内核参数配置
# vi /etc/sysctl.d/99-influxdb.conf
# 添加以下参数
# 网络参数
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
# 文件描述符限制
fs.file-max = 655360
# 内存参数
vm.swappiness = 1
# 使内核参数生效
# sysctl -p /etc/sysctl.d/99-influxdb.conf
# 输出示例:
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
…
2.4 用户资源限制配置
# vi /etc/security/limits.conf
# 添加以下配置
influxdb soft nofile 65535
influxdb hard nofile 65535
influxdb soft nproc 65535
influxdb hard nproc 65535
# 配置systemd限制
# mkdir -p /etc/systemd/system/influxdb.service.d
# vi /etc/systemd/system/influxdb.service.d/limits.conf
[Service]
LimitNOFILE=65535
LimitNPROC=65535
3. InfluxDB数据库安装步骤
本节详细介绍InfluxDB 2.7的安装过程。学习交流加群风哥QQ113257174
3.1 创建用户和目录
# useradd -r -s /sbin/nologin influxdb
# 创建目录结构
# mkdir -p /var/lib/influxdb/{engine,data}
# mkdir -p /var/log/influxdb
# mkdir -p /backup/influxdb
# 设置目录权限
# chown -R influxdb:influxdb /var/lib/influxdb
# chown -R influxdb:influxdb /var/log/influxdb
# chown -R influxdb:influxdb /backup/influxdb
# chmod -R 750 /var/lib/influxdb
# chmod -R 750 /var/log/influxdb
# chmod -R 750 /backup/influxdb
# 验证目录权限
# ls -la /var/lib/
总用量 0
drwxr-xr-x. 3 influxdb influxdb 20 4月 4 10:00 influxdb
3.2 下载并安装InfluxDB
# cd /usr/local/src
# wget https://dl.influxdata.com/influxdb/releases/influxdb2-2.7.3-1.x86_64.rpm
# 输出示例:
–2026-04-04 10:00:00– https://dl.influxdata.com/influxdb/releases/influxdb2-2.7.3-1.x86_64.rpm
正在解析主机 dl.influxdata.com… 192.168.1.100
正在连接 dl.influxdata.com|192.168.1.100|:443… 已连接。
已发出 HTTP 请求,正在等待回应… 200 OK
长度:100000000 (95M) [application/x-rpm]
正在保存至: “influxdb2-2.7.3-1.x86_64.rpm”
100%[======================================>] 100,000,000 10.0MB/s 用时 9.5s
2026-04-04 10:00:10 (10.0 MB/s) – 已保存 “influxdb2-2.7.3-1.x86_64.rpm”
# 安装InfluxDB
# rpm -ivh influxdb2-2.7.3-1.x86_64.rpm
# 输出示例:
警告:influxdb2-2.7.3-1.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID xxxxxx: NOKEY
Verifying… ################################# [100%]
准备中… ################################# [100%]
正在升级/安装…
1:influxdb2-2.7.3-1 ################################# [100%]
# 验证安装
# which influxd
/usr/bin/influxd
# which influx
/usr/bin/influx
# 查看版本
# influxd version
InfluxDB 2.7.3 (git: abc123) build_date: 2024-01-01T00:00:00Z
# influx version
Influx CLI 2.7.3 (git: abc123) build_date: 2024-01-01T00:00:00Z
3.3 创建配置文件
# vi /etc/influxdb/config.toml
# 添加以下配置
# 基本配置
bolt-path = “/var/lib/influxdb/influxd.bolt”
engine-path = “/var/lib/influxdb/engine”
data-path = “/var/lib/influxdb/data”
# HTTP配置
http-bind-address = “:8086”
http-read-header-timeout = “10s”
http-idle-timeout = “3m0s”
# 存储配置
storage-series-id-set-cache-size = 0
storage-series-file-max-concurrent-snapshot-compactions = 0
storage-wal-fsync-delay = “0s”
storage-cache-max-memory-size = 1073741824
storage-cache-snapshot-memory-size = 26214400
storage-cache-snapshot-write-cold-duration = “10m0s”
storage-compact-full-write-cold-duration = “4h0m0s”
storage-compact-throughput-burst = 50331648
storage-max-concurrent-compactions = 0
storage-max-index-log-file-size = 1048576
# 日志配置
log-level = “info”
# 创建目录
# mkdir -p /etc/influxdb
3.4 创建Systemd服务
# vi /etc/systemd/system/influxdb.service
[Unit]
Description=InfluxDB is an open-source time series database
Documentation=https://docs.influxdata.com/influxdb/
After=network-online.target
[Service]
User=influxdb
Group=influxdb
Type=simple
Restart=on-failure
ExecStart=/usr/bin/influxd -config /etc/influxdb/config.toml
RestartSec=5
LimitNOFILE=65535
LimitNPROC=65535
[Install]
WantedBy=multi-user.target
# 重载systemd
# systemctl daemon-reload
# 启动InfluxDB服务
# systemctl start influxdb
# 设置开机自启动
# systemctl enable influxdb
# 输出示例:
Created symlink /etc/systemd/system/multi-user.target.wants/influxdb.service → /etc/systemd/system/influxdb.service.
# 检查服务状态
# systemctl status influxdb
● influxdb.service – InfluxDB is an open-source time series database
Loaded: loaded (/etc/systemd/system/influxdb.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2026-04-04 10:00:00 CST; 5s ago
Docs: https://docs.influxdata.com/influxdb/
Main PID: 12345 (influxd)
Tasks: 8 (limit: 4915)
Memory: 50.0M
CGroup: /system.slice/influxdb.service
└─12345 /usr/bin/influxd -config /etc/influxdb/config.toml
# 检查端口
# netstat -tlnp | grep influxd
tcp 0 0 :::8086 :::* LISTEN 12345/influxd
tcp 0 0 :::8088 :::* LISTEN 12345/influxd
3.5 初始化InfluxDB
$ influx setup \
–username admin \
–password fgedupass123 \
–org fgedu \
–bucket fgedudb \
–retention 720h \
–force
# 输出示例:
User Organization Bucket
admin fgedu fgedudb
# 验证初始化
$ influx user list
ID Name Status
=================== =========== =======
abc123def456 admin active
$ influx org list
ID Name
=================== ======
abc123def456 fgedu
$ influx bucket list
ID Name Organization Retention Policy Schema Type
=================== =========== =============== =================== ===========
abc123def456 fgedudb fgedu 720h0m0s implicit
# 获取认证令牌
$ influx auth list
ID Description Token
======================= ============== ====================================
abc123def456… abc123def456_abcdefghijklmnopqrstuvwxyz…
4. 数据库参数配置
数据库参数配置是InfluxDB安装的关键步骤,直接影响数据库性能和稳定性。更多学习教程公众号风哥教程itpux_com
4.1 配置数据保留策略
$ influx bucket list –org fgedu
ID Name Organization Retention Policy Schema Type
=================== =========== =============== =================== ===========
abc123def456 fgedudb fgedu 720h0m0s implicit
# 创建新的bucket
$ influx bucket create \
–name fgedu_metrics \
–org fgedu \
–retention 168h
# 输出示例:
ID Name Organization Retention Policy Schema Type
=================== =============== =============== =================== ===========
def456ghi789 fgedu_metrics fgedu 168h0m0s implicit
# 更新bucket保留策略
$ influx bucket update \
–id abc123def456 \
–retention 720h
# 删除bucket
$ influx bucket delete –name old_bucket –org fgedu
4.2 配置用户和权限
$ influx user create \
–name fgedu_user \
–org fgedu \
–password userpass123
# 输出示例:
ID Name Status
=================== =========== =======
ghi789jkl012 fgedu_user active
# 创建读写令牌
$ influx auth create \
–org fgedu \
–read-bucket abc123def456 \
–write-bucket abc123def456 \
–description “fgedudb read/write token”
# 输出示例:
ID Description Token
======================= ========================== ====================================
mno345pqr678 fgedudb read/write token abc123def456_abcdefghijklmnopqrstuvwxyz…
# 查看用户列表
$ influx user list
ID Name Status
=================== =========== =======
abc123def456 admin active
ghi789jkl012 fgedu_user active
# 删除用户
$ influx user delete –id ghi789jkl012
4.3 配置存储引擎
$ influx server-config
{
“bolt-path”: “/var/lib/influxdb/influxd.bolt”,
“engine-path”: “/var/lib/influxdb/engine”,
“data-path”: “/var/lib/influxdb/data”,
“http-bind-address”: “:8086”,
“storage-cache-max-memory-size”: 1073741824,
“storage-cache-snapshot-memory-size”: 26214400,
“storage-cache-snapshot-write-cold-duration”: “10m0s”
}
# 修改存储配置
# vi /etc/influxdb/config.toml
# 调整缓存大小
storage-cache-max-memory-size = 2147483648
storage-cache-snapshot-memory-size = 52428800
# 调整压缩配置
storage-max-concurrent-compactions = 4
storage-compact-throughput-burst = 100663296
# 重启服务
# systemctl restart influxdb
5. 数据写入与查询
InfluxDB使用Line Protocol格式写入数据,使用Flux语言进行查询。from:www.itpux.com
5.1 数据写入
$ influx write \
–bucket fgedudb \
–org fgedu \
–precision s \
‘cpu,host=fgedudb01,region=cn-north usage=80.5,memory=60.2 1712205600
cpu,host=fgedudb01,region=cn-north usage=75.3,memory=55.8 1712205660
cpu,host=fgedudb02,region=cn-north usage=65.2,memory=45.6 1712205600’
# 输出示例:
# 无输出表示写入成功
# 使用HTTP API写入数据
$ curl -X POST “http://192.168.1.51:8086/api/v2/write?org=fgedu&bucket=fgedudb&precision=s” \
–header “Authorization: Token abc123def456_abcdefghijklmnopqrstuvwxyz…” \
–data-raw ‘cpu,host=fgedudb01,region=cn-north usage=85.5,memory=65.2 1712205720’
# 使用文件批量写入
$ cat > /tmp/metrics.txt << 'EOF'
cpu,host=fgedudb01,region=cn-north usage=80.5,memory=60.2 1712205600
cpu,host=fgedudb01,region=cn-north usage=75.3,memory=55.8 1712205660
cpu,host=fgedudb02,region=cn-north usage=65.2,memory=45.6 1712205600
memory,host=fgedudb01,region=cn-north used=8589934592,free=8589934592 1712205600
EOF
$ influx write \
--bucket fgedudb \
--org fgedu \
--file /tmp/metrics.txt
5.2 数据查询
$ influx query ‘
from(bucket: “fgedudb”)
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == “cpu”)
|> filter(fn: (r) => r.host == “fgedudb01”)
‘
# 输出示例:
Result: _result
Table: keys: [_start, _stop, _field, _measurement, host, region]
_start:time _stop:time _field:string _measurement:string host:string region:string _time:time _value:float
—————————— —————————— ———————- ———————- ———————- ———————- —————————— —————————-
2026-04-04T09:00:00.000000000Z 2026-04-04T10:00:00.000000000Z usage cpu fgedudb01 cn-north 2026-04-04T09:30:00.000000000Z 80.5
2026-04-04T09:00:00.000000000Z 2026-04-04T10:00:00.000000000Z usage cpu fgedudb01 cn-north 2026-04-04T09:31:00.000000000Z 75.3
# 使用HTTP API查询
$ curl -X POST “http://192.168.1.51:8086/api/v2/query?org=fgedu” \
–header “Authorization: Token abc123def456_abcdefghijklmnopqrstuvwxyz…” \
–header “Content-Type: application/vnd.flux” \
–data ‘from(bucket: “fgedudb”)
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == “cpu”)’
# 聚合查询
$ influx query ‘
from(bucket: “fgedudb”)
|> range(start: -24h)
|> filter(fn: (r) => r._measurement == “cpu”)
|> aggregateWindow(every: 1h, fn: mean)
|> yield(name: “mean”)
‘
# 降采样查询
$ influx query ‘
from(bucket: “fgedudb”)
|> range(start: -7d)
|> filter(fn: (r) => r._measurement == “cpu”)
|> aggregateWindow(every: 1d, fn: max)
|> yield(name: “daily_max”)
‘
5.3 连续查询与任务
$ influx task create \
–name “cpu_downsample” \
–org fgedu \
–every 1h \
–query ‘
from(bucket: “fgedudb”)
|> range(start: -2h)
|> filter(fn: (r) => r._measurement == “cpu”)
|> aggregateWindow(every: 1h, fn: mean)
|> to(bucket: “fgedu_metrics”, org: “fgedu”)
‘
# 输出示例:
ID Name Organization Every Cron Status
======================= =============== =============== ======== ======= =======
task123abc cpu_downsample fgedu 1h0m0s active
# 查看任务列表
$ influx task list
ID Name Organization Every Cron Status
======================= =============== =============== ======== ======= =======
task123abc cpu_downsample fgedu 1h0m0s active
# 手动运行任务
$ influx task run create –task-id task123abc
# 查看任务运行历史
$ influx task run list –task-id task123abc
# 删除任务
$ influx task delete –id task123abc
6. 网络连接配置
网络连接配置是客户端访问数据库的关键,需要正确配置监听端口和连接方式。更多学习教程www.fgedu.net.cn
6.1 配置网络监听
# netstat -tlnp | grep influxd
tcp 0 0 :::8086 :::* LISTEN 12345/influxd
tcp 0 0 :::8088 :::* LISTEN 12345/influxd
# 修改监听地址
# vi /etc/influxdb/config.toml
http-bind-address = “192.168.1.51:8086”
# 重启服务
# systemctl restart influxdb
# 配置防火墙
# firewall-cmd –permanent –add-port=8086/tcp
success
# firewall-cmd –reload
success
6.2 配置认证
$ influx auth list
ID Description Token
======================= ========================== ====================================
abc123def456 abc123def456_abcdefghijklmnopqrstuvwxyz…
# 创建全权限令牌
$ influx auth create \
–org fgedu \
–all-access \
–description “admin token”
# 输出示例:
ID Description Token
======================= ============== ====================================
def456ghi789 admin token def456ghi789_abcdefghijklmnopqrstuvwxyz…
# 创建只读令牌
$ influx auth create \
–org fgedu \
–read-buckets \
–description “read-only token”
# 删除令牌
$ influx auth delete –id abc123def456
6.3 配置HTTPS
# openssl req -x509 -nodes -newkey rsa:2048 \
-keyout /etc/influxdb/influxdb.key \
-out /etc/influxdb/influxdb.crt \
-days 365 \
-subj “/CN=fgedudb01.fgedu.net.cn”
# 输出示例:
Generating a RSA private key
…………+++++
………………..+++++
writing new private key to ‘/etc/influxdb/influxdb.key’
# 设置证书权限
# chown influxdb:influxdb /etc/influxdb/influxdb.*
# chmod 600 /etc/influxdb/influxdb.key
# chmod 644 /etc/influxdb/influxdb.crt
# 配置HTTPS
# vi /etc/influxdb/config.toml
tls-cert = “/etc/influxdb/influxdb.crt”
tls-key = “/etc/influxdb/influxdb.key”
# 重启服务
# systemctl restart influxdb
# 使用HTTPS连接
$ influx –host https://192.168.1.51:8086 –skip-verify
7. 备份恢复配置
备份恢复是数据库管理的重要环节,InfluxDB提供了完整的备份恢复工具。学习交流加群风哥微信: itpux-com
7.1 全量备份
# mkdir -p /backup/influxdb/full
# 执行全量备份
$ influx backup /backup/influxdb/full
# 输出示例:
2026/04/04 10:00:00 backing up tsdb data in “/var/lib/influxdb/engine/data”
2026/04/04 10:00:00 backing up kv in “/var/lib/influxdb/influxd.bolt”
2026/04/04 10:00:00 backup complete
# 查看备份文件
# ls -la /backup/influxdb/full/
总用量 1024
-rw-r–r–. 1 root root 512 4月 4 10:00 20260404T100000Z.manifest
-rw-r–r–. 1 root root 512 4月 4 10:00 20260404T100000Z.symbols.tar.gz
drwxr-xr-x. 2 root root 6 4月 4 10:00 data
7.2 增量备份
# mkdir -p /backup/influxdb/incremental
# 执行增量备份(基于上次全量备份)
$ influx backup \
–incremental \
/backup/influxdb/incremental
# 输出示例:
2026/04/04 11:00:00 backing up tsdb data in “/var/lib/influxdb/engine/data”
2026/04/04 11:00:00 backing up kv in “/var/lib/influxdb/influxd.bolt”
2026/04/04 11:00:00 backup complete
# 备份指定bucket
$ influx backup \
–bucket fgedudb \
/backup/influxdb/fgedudb_backup
# 备份指定组织
$ influx backup \
–org fgedu \
/backup/influxdb/fgedu_backup
7.3 数据恢复
$ influx restore /backup/influxdb/full
# 输出示例:
2026/04/04 12:00:00 restoring kv from backup
2026/04/04 12:00:00 restoring tsdb data from backup
2026/04/04 12:00:00 restore complete
# 恢复指定bucket
$ influx restore \
–bucket fgedudb \
–new-bucket fgedudb_restored \
/backup/influxdb/full
# 恢复到新的组织
$ influx restore \
–org fgedu \
–new-org fgedu_restored \
/backup/influxdb/full
# 查看恢复的bucket
$ influx bucket list
ID Name Organization Retention Policy Schema Type
=================== =================== =============== =================== ===========
abc123def456 fgedudb fgedu 720h0m0s implicit
ghi789jkl012 fgedudb_restored fgedu 720h0m0s implicit
7.4 自动备份脚本
# vi /usr/local/bin/influxdb_backup.sh
#!/bin/bash
BACKUP_DIR=/backup/influxdb
DATE=$(date +%Y%m%d_%H%M%S)
LOG_FILE=/var/log/influxdb/backup.log
echo “=== Backup started at $(date) ===” >> $LOG_FILE
# 执行全量备份
influx backup ${BACKUP_DIR}/full_${DATE} >> $LOG_FILE 2>&1
if [ $? -eq 0 ]; then
echo “Backup completed successfully” >> $LOG_FILE
else
echo “Backup failed” >> $LOG_FILE
fi
# 清理7天前的备份
find ${BACKUP_DIR} -name “full_*” -type d -mtime +7 -exec rm -rf {} \; >> $LOG_FILE 2>&1
echo “=== Backup finished at $(date) ===” >> $LOG_FILE
echo “” >> $LOG_FILE
# 设置脚本权限
# chmod +x /usr/local/bin/influxdb_backup.sh
# 配置定时任务
# crontab -e
# 添加以下内容(每天凌晨2点执行备份)
0 2 * * * /usr/local/bin/influxdb_backup.sh
8. 升级与迁移
数据库升级和迁移是运维工作中的重要环节,需要仔细规划和执行。更多学习教程公众号风哥教程itpux_com
8.1 版本升级
$ influxd version
InfluxDB 2.7.3 (git: abc123) build_date: 2024-01-01T00:00:00Z
# 执行完整备份
$ influx backup /backup/influxdb/pre_upgrade
# 停止服务
# systemctl stop influxdb
# 下载新版本
# cd /usr/local/src
# wget https://dl.influxdata.com/influxdb/releases/influxdb2-2.7.4-1.x86_64.rpm
# 升级安装
# rpm -Uvh influxdb2-2.7.4-1.x86_64.rpm
# 启动服务
# systemctl start influxdb
# 验证版本
$ influxd version
InfluxDB 2.7.4 (git: def456) build_date: 2024-02-01T00:00:00Z
8.2 从InfluxDB 1.x迁移
# 安装迁移工具
# wget https://dl.influxdata.com/influxdb/releases/influxdb-tools-1.0.0-1.x86_64.rpm
# rpm -ivh influxdb-tools-1.0.0-1.x86_64.rpm
# 使用influx_inspect导出数据
$ influx_inspect export \
-database fgedudb \
-retention default \
-out /tmp/fgedudb_export.txt \
-lponly
# 导入到InfluxDB 2.x
$ influx write \
–bucket fgedudb \
–org fgedu \
–file /tmp/fgedudb_export.txt
# 或使用HTTP API迁移
$ curl -G “http://influx1x_host:8086/query” \
–data-urlencode “db=fgedudb” \
–data-urlencode “q=SELECT * FROM cpu” \
| influx write –bucket fgedudb –org fgedu –format csv
9. 生产环境实战案例
本节提供一个完整的生产环境配置案例,帮助读者更好地理解InfluxDB的实际应用。from:www.itpux.com
9.1 监控数据采集
$ influx bucket create \
–name monitoring \
–org fgedu \
–retention 168h
# 创建监控令牌
$ influx auth create \
–org fgedu \
–write-bucket monitoring_bucket_id \
–description “monitoring write token”
# 使用Telegraf采集数据
# 安装Telegraf
# wget https://dl.influxdata.com/telegraf/releases/telegraf-1.28.0-1.x86_64.rpm
# rpm -ivh telegraf-1.28.0-1.x86_64.rpm
# 配置Telegraf
# vi /etc/telegraf/telegraf.conf
[[outputs.influxdb_v2]]
urls = [“http://192.168.1.51:8086”]
token = “monitoring_token_here”
organization = “fgedu”
bucket = “monitoring”
[[inputs.cpu]]
percpu = true
totalcpu = true
collect_cpu_time = false
report_active = false
[[inputs.mem]]
[[inputs.disk]]
[[inputs.net]]
# 启动Telegraf
# systemctl start telegraf
# systemctl enable telegraf
# 查询监控数据
$ influx query ‘
from(bucket: “monitoring”)
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == “cpu”)
|> limit(n: 10)
‘
9.2 性能监控
$ influx query ‘
import “influxdata/influxdb”
influxdata/influxdb.cardinality(bucket: “fgedudb”, start: -30d)
‘
# 输出示例:
0
# 查看写入统计
$ curl -s “http://192.168.1.51:8086/metrics” | grep influxdb_write
# 输出示例:
# HELP influxdb_write_points Number of points written
# TYPE influxdb_write_points counter
influxdb_write_points{bucket=”fgedudb”,org=”fgedu”} 1000000
# 查看查询统计
$ curl -s “http://192.168.1.51:8086/metrics” | grep influxdb_query
# 输出示例:
# HELP influxdb_query_requests Number of query requests
# TYPE influxdb_query_requests counter
influxdb_query_requests{bucket=”fgedudb”,org=”fgedu”} 5000
# 查看存储引擎统计
$ curl -s “http://192.168.1.51:8086/metrics” | grep influxdb_tsm
# 输出示例:
# HELP influxdb_tsm1_filestore_bytes_total Total size of TSM files
# TYPE influxdb_tsm1_filestore_bytes_total gauge
influxdb_tsm1_filestore_bytes_total{bucket=”fgedudb”} 1073741824
9.3 高可用配置
# 建议使用以下方案实现高可用:
# 方案1:使用负载均衡器
# 在多个InfluxDB节点前配置负载均衡器
# 客户端写入时使用负载均衡器地址
# 方案2:使用复制
# 在每个节点配置相同的写入
# 使用Telegraf的outputs.influxdb_v2插件同时写入多个节点
# Telegraf配置示例
# vi /etc/telegraf/telegraf.conf
[[outputs.influxdb_v2]]
alias = “influxdb1”
urls = [“http://192.168.1.51:8086”]
token = “token1”
organization = “fgedu”
bucket = “fgedudb”
[[outputs.influxdb_v2]]
alias = “influxdb2”
urls = [“http://192.168.1.52:8086”]
token = “token2”
organization = “fgedu”
bucket = “fgedudb”
# 方案3:使用云服务
# 使用InfluxDB Cloud或阿里云时序数据库
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
