本教程以最新的的 2.7.0 为基础
InfluxDB 是一个开源的时序数据库,专门用于处理和存储时间序列数据。以下是学习 InfluxDB 的指南资源:
官方文档:InfluxDB 的官方文档是学习的最佳资源。你可以在官方网站上找到完整的文档,包括安装、配置、查询和数据管理等方面的信息。官方文档地址:https://docs.influxdata.com/influxdb/
InfluxData 社区:InfluxData 社区是与其他开发者交流和学习的好地方。你可以在社区论坛上提问、寻求帮助,还可以阅读其他人的问题和解答。社区地址:https://community.influxdata.com/
教程和博客文章:在互联网上有许多针对 InfluxDB 的教程和博客文章,涵盖了从入门到高级主题的各种内容。你可以通过搜索引擎找到相关资源,例如,可以搜索 “InfluxDB 学习教程” 或 “InfluxDB 入门指南”。
视频教程:视频教程可以帮助你通过演示和实际操作更好地理解 InfluxDB 的使用。你可以在 YouTube 等视频平台上找到各种免费的 InfluxDB 视频教程。
GitHub 仓库:InfluxDB 的源代码托管在 GitHub 上,你可以查看源代码、示例和其他资源。GitHub 仓库地址:https://github.com/influxdata/influxdb
通过结合多种资源,你可以系统地学习和掌握 InfluxDB 的各个方面,从而更好地使用这个时序数据库进行数据处理和存储。
进程 CS 架构
InfluxDB 服务端: 对应二进制文件为 influxd
InfluxDB 客户端: 对应二进制文件为 influx
下载地址: Install InfluxDB | InfluxDB OSS 2.7 Documentation (influxdata.com)
brew update
brew install influxdb
网络端口: 默认端口 8086
用于管理 InfluxDB 的客户端
# 默认应该已经安装好了, 判断是否安装成功:
brew list | grep influxdb-cli
InfluxDB 实例的初始设置过程将创建以下内容:
要运行提示您输入所需信息的交互式设置,请使用 influx
用户界面 (UI) 或 influx 命令行界面 (CLI)。
要自动执行设置(例如,使用您编写的脚本),请使用 influx
命令行界面 (CLI) 或 InfluxDB //api/v2
API。
influxd
2023-08-24T02:55:14.774012Z info Welcome to InfluxDB {"log_id": "0jqNKHLG000", "version": "2.7.1", "commit": "407fa622e9", "build_date": "2023-04-27T19:36:53Z", "log_level": "info"}
2023-08-24T02:55:14.848506Z info Resources opened {"log_id": "0jqNKHLG000", "service": "bolt", "path": "/Users/lxm/.influxdbv2/influxd.bolt"}
2023-08-24T02:55:14.848612Z info Resources opened {"log_id": "0jqNKHLG000", "service": "sqlite", "path": "/Users/lxm/.influxdbv2/influxd.sqlite"}
2023-08-24T02:55:14.883516Z info Bringing up metadata migrations {"log_id": "0jqNKHLG000", "service": "KV migrations", "migration_count": 20}
设置初始用户
[外链图片转存中…(img-VELxJsdB-1693019220385)]
API token:
lsY2jCGLdsYgfSqYCdAoJy1knyQ_i2stwWURg-IV5ougpnSfJ5F1VDNDkydqNSXN617Q2QVdB6Y9jFHggn3KUw==
为避免在每个 influx 命令中传递 InfluxDB API 令牌,请设置配置文件来存储凭证,例如,在终端中输入以下代码:
# Set up a configuration profile
influx config create \
--config-name default \
--host-url http://localhost:8086 \
--org INFLUX_ORG \
--token INFLUX_API_TOKEN \
--active
替换以下内容:
lsY2jCGLdsYgfSqYCdAoJy1knyQ_i2stwWURg-IV5ougpnSfJ5F1VDNDkydqNSXN617Q2QVdB6Y9jFHggn3KUw==
influx config create \
--config-name default \
--host-url http://localhost:8086 \
--org test \
--token lsY2jCGLdsYgfSqYCdAoJy1knyQ_i2stwWURg-IV5ougpnSfJ5F1VDNDkydqNSXN617Q2QVdB6Y9jFHggn3KUw== \
--active
Active Name URL Org
* default http://localhost:8086 test
两种方式:
这里我们采用手动下载安装的方式:
wget https://dl.influxdata.com/influxdb/releases/influxdb2-2.7.0-linux-amd64.tar.gz
tar xvzf path/to/influxdb2-2.7.0-linux-amd64.tar.gz
# 可选
cp influxdb2_linux_amd64/influxd /usr/local/bin/
# 可选
chmod 0750 ~/.influxdbv2
# 下载
wget https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.7.3-linux-amd64.tar.gz
# 解压
tar xvzf influxdb2-client-2.7.3-linux-amd64.tar.gz
# 拷贝
cp influx /usr/local/bin/
influxd
influx setup \
--username USERNAME \
--password PASSWORD \
--token TOKEN \
--org ORGANIZATION_NAME \
--bucket BUCKET_NAME \
--force
如果不带 --token , InfluxDB 会自动生成 API token 并且将其存储到 influx CLI 连接配置文件中
实例
influx setup \
--username test \
--password testtest \
--org test \
--bucket test \
--force
[root@mysql01 influxdb]# influx setup \
> --username test \
> --password testtest \
> --org test \
> --bucket test \
> --force
User Organization Bucket
test test test
influx CLI 配置文件(即 influxdb 配置文件)路径:
[root@mysql01 bin]# more ~/.influxdbv2/configs
[default]
url = "http://localhost:8086"
token = "KQmYbPkEwT1Ol02DAQHGr5F5dFc254PftrKoi-tE3v3kK5SJJqu0ic2Tuajr3B3uCOzpYkBmdVz85u6ZffkgIw=="
org = "test"
active = true
#
# [eu-central]
# url = "https://eu-central-1-1.aws.cloud2.influxdata.com"
# token = "XXX"
# org = ""
#
# [us-central]
# url = "https://us-central1-1.gcp.cloud2.influxdata.com"
# token = "XXX"
# org = ""
#
# [us-west]
# url = "https://us-west-2-1.aws.cloud2.influxdata.com"
# token = "XXX"
# org = ""
据此, 我们可以看到通过命令行配置 InfluxDB 之后,生成的 token 值
为避免在每个 influx 命令中传递 InfluxDB API 令牌,请设置配置文件来存储凭证,例如,在终端中输入以下代码:
# Set up a configuration profile
influx config create \
--config-name default \
--host-url http://localhost:8086 \
--org INFLUX_ORG \
--token INFLUX_API_TOKEN \
--active
替换以下内容:
KQmYbPkEwT1Ol02DAQHGr5F5dFc254PftrKoi-tE3v3kK5SJJqu0ic2Tuajr3B3uCOzpYkBmdVz85u6ZffkgIw==
influx config create \
--config-name default \
--host-url http://localhost:8086 \
--org test \
--token KQmYbPkEwT1Ol02DAQHGr5F5dFc254PftrKoi-tE3v3kK5SJJqu0ic2Tuajr3B3uCOzpYkBmdVz85u6ZffkgIw== \
--active
可以通过 InfluxDB UI, influx
CLI, or InfluxDB API 这三种方式实现,
这里以我个人比较习惯的 CLI 命令行方式
示例:
influx auth create \
--all-access \
--host http://localhost:8086 \
--org <YOUR_INFLUXDB_ORG_NAME> \
--token <YOUR_INFLUXDB_OPERATOR_TOKEN>
说明:
--all-access
flag--host
flag with your InfluxDB host URL-o, --org
or --org-id
flags with your InfluxDB organization name or ID-t, --token
flag with your Operator tokeninflux auth create \
--all-access \
--host http://localhost:8086 \
--org test \
--token KQmYbPkEwT1Ol02DAQHGr5F5dFc254PftrKoi-tE3v3kK5SJJqu0ic2Tuajr3B3uCOzpYkBmdVz85u6ZffkgIw==
[root@mysql01 bin]# influx auth create \
> --all-access \
> --host http://localhost:8086 \
> --org test \
> --token KQmYbPkEwT1Ol02DAQHGr5F5dFc254PftrKoi-tE3v3kK5SJJqu0ic2Tuajr3B3uCOzpYkBmdVz85u6ZffkgIw==
ID Description Token User Name User ID Permissions
0bb5943edfdf6000 1fdu2hyegDS0rdxwjl4yiDDvrQrhjEePJWhevfa5pK0uP7xyT3MvesQbK_8gBMHRQ0agNV8tF_M5IK9EHTb0TQ==test 0bb56504da9f6000 [read:orgs/b64afcc7a8ff4a0e/authorizations write:orgs/b64afcc7a8ff4a0e/authorizations read:orgs/b64afcc7a8ff4a0e/buckets write:orgs/b64afcc7a8ff4a0e/buckets read:orgs/b64afcc7a8ff4a0e/dashboards write:orgs/b64afcc7a8ff4a0e/dashboards read:/orgs/b64afcc7a8ff4a0e read:orgs/b64afcc7a8ff4a0e/sources write:orgs/b64afcc7a8ff4a0e/sources read:orgs/b64afcc7a8ff4a0e/tasks write:orgs/b64afcc7a8ff4a0e/tasks read:orgs/b64afcc7a8ff4a0e/telegrafs write:orgs/b64afcc7a8ff4a0e/telegrafs read:/users/0bb56504da9f6000 write:/users/0bb56504da9f6000 read:orgs/b64afcc7a8ff4a0e/variables write:orgs/b64afcc7a8ff4a0e/variables read:orgs/b64afcc7a8ff4a0e/scrapers write:orgs/b64afcc7a8ff4a0e/scrapers read:orgs/b64afcc7a8ff4a0e/secrets write:orgs/b64afcc7a8ff4a0e/secrets read:orgs/b64afcc7a8ff4a0e/labels write:orgs/b64afcc7a8ff4a0e/labels read:orgs/b64afcc7a8ff4a0e/views write:orgs/b64afcc7a8ff4a0e/views read:orgs/b64afcc7a8ff4a0e/documents write:orgs/b64afcc7a8ff4a0e/documents read:orgs/b64afcc7a8ff4a0e/notificationRules write:orgs/b64afcc7a8ff4a0e/notificationRules read:orgs/b64afcc7a8ff4a0e/notificationEndpoints write:orgs/b64afcc7a8ff4a0e/notificationEndpoints read:orgs/b64afcc7a8ff4a0e/checks write:orgs/b64afcc7a8ff4a0e/checks read:orgs/b64afcc7a8ff4a0e/dbrp write:orgs/b64afcc7a8ff4a0e/dbrp read:orgs/b64afcc7a8ff4a0e/notebooks write:orgs/b64afcc7a8ff4a0e/notebooks read:orgs/b64afcc7a8ff4a0e/annotations write:orgs/b64afcc7a8ff4a0e/annotations read:orgs/b64afcc7a8ff4a0e/remotes write:orgs/b64afcc7a8ff4a0e/remotes read:orgs/b64afcc7a8ff4a0e/replications write:orgs/b64afcc7a8ff4a0e/replications]
[root@mysql01 bin]#
influx auth create \
--all-access \
--host http://localhost:8086 \
--org test \
--token lsY2jCGLdsYgfSqYCdAoJy1knyQ_i2stwWURg-IV5ougpnSfJ5F1VDNDkydqNSXN617Q2QVdB6Y9jFHggn3KUw==
influx auth create \
--all-access \
--host http://localhost:8086 \
--org test \
--token lsY2jCGLdsYgfSqYCdAoJy1knyQ_i2stwWURg-IV5ougpnSfJ5F1VDNDkydqNSXN617Q2QVdB6Y9jFHggn3KUw==
ID Description Token User Name User ID Permissions
0bb5942da919e000 kOli_NdX6Zry4n4Zufh0buFjARVfe8_OAsyZ3Tuf-BZIYlwrmSHAKXEie60N5XA4OPgzIg7-1MeLEE_2nfCrHQ== test 0bb55efce699e000 [read:orgs/b309d4176a1415da/authorizations write:orgs/b309d4176a1415da/authorizations read:orgs/b309d4176a1415da/buckets write:orgs/b309d4176a1415da/buckets read:orgs/b309d4176a1415da/dashboards write:orgs/b309d4176a1415da/dashboards read:/orgs/b309d4176a1415da read:orgs/b309d4176a1415da/sources write:orgs/b309d4176a1415da/sources read:orgs/b309d4176a1415da/tasks write:orgs/b309d4176a1415da/tasks read:orgs/b309d4176a1415da/telegrafs write:orgs/b309d4176a1415da/telegrafs read:/users/0bb55efce699e000 write:/users/0bb55efce699e000 read:orgs/b309d4176a1415da/variables write:orgs/b309d4176a1415da/variables read:orgs/b309d4176a1415da/scrapers write:orgs/b309d4176a1415da/scrapers read:orgs/b309d4176a1415da/secrets write:orgs/b309d4176a1415da/secrets read:orgs/b309d4176a1415da/labels write:orgs/b309d4176a1415da/labels read:orgs/b309d4176a1415da/views write:orgs/b309d4176a1415da/views read:orgs/b309d4176a1415da/documents write:orgs/b309d4176a1415da/documents read:orgs/b309d4176a1415da/notificationRules write:orgs/b309d4176a1415da/notificationRules read:orgs/b309d4176a1415da/notificationEndpoints write:orgs/b309d4176a1415da/notificationEndpoints read:orgs/b309d4176a1415da/checks write:orgs/b309d4176a1415da/checks read:orgs/b309d4176a1415da/dbrp write:orgs/b309d4176a1415da/dbrp read:orgs/b309d4176a1415da/notebooks write:orgs/b309d4176a1415da/notebooks read:orgs/b309d4176a1415da/annotations write:orgs/b309d4176a1415da/annotations read:orgs/b309d4176a1415da/remotes write:orgs/b309d4176a1415da/remotes read:orgs/b309d4176a1415da/replications write:orgs/b309d4176a1415da/replications]