Documentation

设置 InfluxDB

在您开始本教程时,请做以下几点,以确保您所需的一切都已就位。

  1. (可选) 下载、安装和配置 influx CLI

    influx CLI 提供了一种简单的方法,通过命令行与 InfluxDB 进行交互。有关详细的安装和设置说明,请参阅 Use the influx CLI

  2. 创建一个全访问API令牌。

    使用 InfluxDB UIinflux CLIInfluxDB API 创建一个 全访问令牌。

    1. Visit cloud2.influxdata.com in a browser to log in and access the InfluxDB UI.
    2. Navigate to Load Data > API Tokens using the left navigation bar.
    3. Click + Generate API token and select All Access API Token.
    4. Enter a description for the API token and click Save.
    5. Copy the generated token and store it for safe keeping.
    1. 如果您还没有,请下载、安装并配置 influx CLI

    2. 使用influx auth create命令创建一个全访问令牌。

      提供以下内容:

      • --all-access 标志
      • --host 标志与您的 InfluxDB 区域 URL
      • -o, --org--org-id 标志与您的 InfluxDB 组织名称或 ID
      • -t, --token 标志与您的操作员令牌
      influx auth create \
        --all-access \
        --host http://cloud2.influxdata.com \
        --org <YOUR_INFLUXDB_ORG_NAME> \
        --token <YOUR_INFLUXDB_OPERATOR_TOKEN>
      
    3. 复制生成的令牌并将其安全存储。

    使用 POST 请求方法向 InfluxDB API /api/v2/authorizations 端点发送请求。

    POST http://cloud2.influxdata.com/api/v2/authorizations

    请在您的请求中包含以下内容:

    • 请求头:
      • 授权: 令牌 <INFLUX_OPERATOR_TOKEN>
      • 内容类型: application/json
    • 请求体: JSON主体具有以下属性:
      • 状态: "active"
      • 描述: API令牌描述
      • orgID: InfluxDB组织ID
      • 权限: 对象数组,每个对象表示对InfluxDB资源类型或特定资源的权限。每个权限包含以下属性:
        • 操作: “read”或“write”
        • 资源: JSON对象,表示要授予权限的InfluxDB资源。每个资源至少包含以下属性:

    以下示例使用cURL和InfluxDB API生成一个全访问令牌:

    export INFLUX_HOST=http://cloud2.influxdata.com
    export INFLUX_ORG_ID=<YOUR_INFLUXDB_ORG_ID>
    export INFLUX_TOKEN=<YOUR_INFLUXDB_OPERATOR_TOKEN>
    
    curl --request POST \
    "$INFLUX_HOST/api/v2/authorizations" \
      --header "Authorization: Token $INFLUX_TOKEN" \
      --header "Content-Type: text/plain; charset=utf-8" \
      --data '{
        "status": "active",
        "description": "All access token for get started tutorial",
        "orgID": "'"$INFLUX_ORG_ID"'",
        "permissions": [
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "authorizations"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "authorizations"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "buckets"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "buckets"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "dashboards"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "dashboards"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "orgs"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "orgs"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "sources"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "sources"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "tasks"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "tasks"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "telegrafs"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "telegrafs"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "users"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "users"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "variables"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "variables"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "scrapers"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "scrapers"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "secrets"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "secrets"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "labels"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "labels"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "views"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "views"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "documents"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "documents"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "notificationRules"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "notificationRules"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "notificationEndpoints"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "notificationEndpoints"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "checks"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "checks"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "dbrp"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "dbrp"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "notebooks"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "notebooks"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "annotations"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "annotations"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "remotes"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "remotes"}},
          {"action": "read", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "replications"}},
          {"action": "write", "resource": {"orgID": "'"$INFLUX_ORG_ID"'", "type": "replications"}}
        ]
      }
    '
    

    响应体包含一个具有以下属性的JSON对象:

    • id: API令牌ID
    • 令牌: API 令牌 (重要)
    • status: 令牌状态
    • 描述: 令牌描述
    • orgID: 与该令牌关联的InfluxDB组织ID
    • org: 与令牌相关联的InfluxDB组织名称
    • userID: 与该令牌关联的用户 ID
    • user: 与该令牌关联的用户名
    • permissions: 组织资源的权限列表

    复制生成的 token 并安全存储。

    我们建议使用密码管理器或秘密存储库来安全地存储敏感令牌。

  3. 配置认证凭据.

    在您进行此教程时,与 InfluxDB Cloud 的交互需要您的 InfluxDB 主机组织名称或 ID以及您的 API 令牌。根据您使用的客户端与 InfluxDB 进行交互,提供这些凭据的方法是不同的。

    在配置你的令牌时,使用你创建的 全访问令牌

    在通过InfluxDB UI 管理 InfluxDB 时,身份验证凭据会自动提供,这些凭据与您登录的用户相关联。

    有三种方式可以向 influx CLI 提供身份验证凭据:

    环境变量

    命令标志

    本快速入门教程中的所有 influx CLI 示例假设您的 InfluxDB 主机组织令牌 是通过 活动 influx CLI 配置 或环境变量提供的。

    使用InfluxDB API时,请以以下方式提供所需的连接凭据:

    • InfluxDB 主机: 您的 InfluxDB Cloud 区域 URL
    • InfluxDB API 令牌: 包含一个 Authorization 标头,使用 BearerToken 方案和您的 InfluxDB API 令牌。例如:
      Authorization: Bearer 0xxx0o0XxXxx00Xxxx000xXXxoo0==.
    • InfluxDB 组织名称或 ID: 根据使用的 API 端点,将其作为 URL 路径、查询字符串或请求体的一部分传递。

    本教程中的所有API示例均使用cURL从命令行执行。要为示例cURL命令提供所有必要的凭据,请在命令行会话中设置以下环境变量。

    export INFLUX_HOST=http://cloud2.influxdata.com
    export INFLUX_ORG=<YOUR_INFLUXDB_ORG_NAME>
    export INFLUX_ORG_ID=<YOUR_INFLUXDB_ORG_ID>
    export INFLUX_TOKEN=<YOUR_INFLUXDB_API_TOKEN>
    
  4. 创建一个桶.

    使用InfluxDB UIinflux CLIInfluxDB API创建一个新桶。

    1. Visit cloud2.influxdata.com in a browser to log in and access the InfluxDB UI.
    2. Navigate to Load Data > Buckets using the left navigation bar.
    3. Click + Create bucket.
    4. Provide a bucket name (get-started) and select Never to create a bucket with an infinite retention period.
    5. Click Create.
    1. 如果您还没有,请下载、安装并配置 influx CLI

    2. 使用influx bucket create命令创建一个新存储桶。

      提供以下内容:

      influx bucket create --name get-started
      

    要使用InfluxDB HTTP API创建一个桶,请使用POST请求方法向InfluxDB API /api/v2/buckets端点发送请求。

    POST http://cloud2.influxdata.com/api/v2/buckets

    请在您的请求中包含以下内容:

    • Headers:
      • Authorization: Token INFLUX_TOKEN
      • Content-Type: application/json
    • 请求正文: JSON 对象,具有以下属性:
      • org: InfluxDB 组织名称
      • name: 桶名称
      • retentionRules: 定义桶的保留期限的保留规则对象列表。 每个保留规则对象具有以下属性:
        • type: "expire"
        • everySeconds: 保留期持续时间,以秒为单位。 0 表示保留期是无限的。
    export INFLUX_HOST=http://cloud2.influxdata.com
    export INFLUX_ORG_ID=<YOUR_INFLUXDB_ORG_ID>
    export INFLUX_TOKEN=<YOUR_INFLUXDB_API_TOKEN>
    
    curl --request POST \
    "$INFLUX_HOST/api/v2/buckets" \
      --header "Authorization: Token $INFLUX_TOKEN" \
      --header "Content-Type: application/json" \
      --data '{
        "orgID": "'"$INFLUX_ORG_ID"'",
        "name": "get-started",
        "retentionRules": [
          {
            "type": "expire",
            "everySeconds": 0
          }
        ]
      }'
    


Flux的未来

Flux 正在进入维护模式。您可以像现在一样继续使用它,而无需对您的代码进行任何更改。

阅读更多

InfluxDB 3 开源版本现已公开Alpha测试

InfluxDB 3 Open Source is now available for alpha testing, licensed under MIT or Apache 2 licensing.

我们将发布两个产品作为测试版的一部分。

InfluxDB 3 核心,是我们新的开源产品。 它是一个用于时间序列和事件数据的实时数据引擎。 InfluxDB 3 企业版是建立在核心基础之上的商业版本,增加了历史查询能力、读取副本、高可用性、可扩展性和细粒度安全性。

有关如何开始的更多信息,请查看:

由TSM驱动的InfluxDB Cloud