InfluxDB 3 Core 的安装与基本使用

1 前言

  • 最近做交易回测,考虑到数据是时序型的,因此采用了influxdb,之前没有用过时序型数据库。初次尝试,感觉不错。
  • 恰好是influxdb3发布不久,相关文档并不多,因此做下笔记。
  • 第三方测试显示,在百万级设备以下场景,写入性能可能不及旧版本,但是这个性能对我来说足矣。

2 安装

  • 安装命令
    此命令仅适用于 Linux 和 macOS ,笔者是在 Ubuntu 系统安装的。
    安装完成后 influxdb3 会立即启动。

    curl -O https://www.influxdata.com/d/install_influxdb3.sh \
    && sh install_influxdb3.sh
    
  • 安装过程
    需要选择Dock镜像或直接安装。
    三种存储方式可供选择:内存、硬盘、云存储。

    ┌───────────────────────────────────────────────────┐
    │ Welcome to InfluxDB! We'll make this quick.       │
    └───────────────────────────────────────────────────┘
    
    Select Installation Type
    
    // 选择Docker镜像、普通安装
    1) Docker Image
       └─ Requires knowledge of Docker and Docker management
    2) Simple Download
       └─ No external dependencies required
    
    Enter your choice (1-2): 2
    
    
    Downloading InfluxDB 3 Core to /home/ubuntu/.influxdb
    ├─ mkdir -p '/home/ubuntu/.influxdb'
    └─ curl -sSL 'https://dl.influxdata.com/influxdb/releases/influxdb3-core-3.1.0_linux_amd64.tar.gz' -o '/home/ubuntu/.influxdb/influxdb3-core.tar.gz'
    
    Verifying '/home/ubuntu/.influxdb/influxdb3-core.tar.gz'
    └─ curl -sSL 'https://dl.influxdata.com/influxdb/releases/influxdb3-core-3.1.0_linux_amd64.tar.gz.sha256' -o '/home/ubuntu/.influxdb/influxdb3-core.tar.gz.sha256'
    └─ sha256sum '/home/ubuntu/.influxdb/influxdb3-core.tar.gz' (OK: a0fe55dfd31e9118d5b6852b583edfe3dd1b74bb272766d6f78060666a26a2f7 = a0fe55dfd31e9118d5b6852b583edfe3dd1b74bb272766d6f78060666a26a2f7)
    └─ rm '/home/ubuntu/.influxdb/influxdb3-core.tar.gz.sha256'
    
    Extracting and Processing
    ├─ tar -xf '/home/ubuntu/.influxdb/influxdb3-core.tar.gz' --strip-components=1 -C '/home/ubuntu/.influxdb'
    └─ rm '/home/ubuntu/.influxdb/influxdb3-core.tar.gz'
    
    Adding InfluxDB to '/home/ubuntu/.bashrc'
    └─ export PATH="$PATH:/home/ubuntu/.influxdb/" >> '/home/ubuntu/.bashrc'
    
    Configuration Options
    └─ Start InfluxDB Now? (y/n): y
    
    Enter Your Node ID
    ├─ A Node ID is a unique, uneditable identifier for a service.
    └─ Enter a Node ID (default: node0): 
    
    // 三种存储方式:内存、硬盘、云存储
    Select Your Storage Solution
    ├─ 1) In-memory storage (Fastest, data cleared on restart)
    ├─ 2) File storage (Persistent local storage)
    ├─ 3) Object storage (Cloud-compatible storage)
    └─ Enter your choice (1-3): 2
    
    Enter storage path (default: /home/ubuntu/.influxdb/data): 
    
    Starting InfluxDB
    ├─ Node ID: node0
    ├─ Storage: File Storage
    ├─ '/home/ubuntu/.influxdb/influxdb3' serve --node-id='node0' --http-bind='0.0.0.0:8181' --object-store=file --data-dir /home/ubuntu/.influxdb/data
    └─ ✓ InfluxDB 3 Core is now installed and running on port 8181. Nice!
    
    Further Info
    ├─ Run source '/home/ubuntu/.bashrc', then access InfluxDB with influxdb3 command.
    ├─ View the Getting Started guide at https://docs.influxdata.com/influxdb3/core/.
    └─ Visit our public Discord at https://discord.gg/az4jPm8x for additional guidance.
    
    ┌────────────────────────────────────────────────────┐
    │ Time is everything. This process took 635 seconds. │
    └────────────────────────────────────────────────────┘
  • 查看是否安装成功
    查看当前版本号,如3.1.0

    ~$ influxdb3 --version
    influxdb3 3.1.0, revision 482dd8aac580c04f37e8713a8fffae89ae8bc264

    3 基本使用

  • 创建 Token
    创建 token 后只显示一次,务必妥善保存。

    // 为 admin 创建 token
    ~$ influxdb3 create token --admin
    
    New token created successfully!
    
    Token: apiv3_s4paVY242p0HqNc15Ntc44sSI1V4BIwAWScR9MELw852nWqAT7fzf6eOx8ccAU1DVZHOvZYnkvYZUrHbQOb8Yg
    HTTP Requests Header: Authorization: Bearer apiv3_xxxxxxxx.....xxxx
    
    IMPORTANT: Store this token securely, as it will not be shown again.
  • 创建database
    默认有一个名为 default 的 database 可以用。
    命名不可以下划线“_”开头,下划线开头的是influxdb 内部数据。
    该操作需要验证权限。

    // 该操作需要验证权限,可通过环境变量配置 token
    ~$ export INFLUXDB3_AUTH_TOKEN=apiv3_s4pxxxxx.....xxxx
    // 创建名为 testing 的 database
    ~$ influxdb3 create database testing
    Database "testing" created successfully
  • 查看已创建的database
    testing 就是我们刚刚创建的。
    该操作需要验证权限,可配置环境变量或传入 token 参数。

    ~$ influxdb3 show databases
    +---------------+
    | iox::database |
    +---------------+
    | _internal     |
    | default       |
    | testing       |
    +---------------+
  • 删除 database
    删除刚才创建的 testing 。
    该操作需要验证权限,可配置环境变量或传入 token 参数。

    ~$ influxdb3 show databases
    +---------------+
    | iox::database |
    +---------------+
    | _internal     |
    | default       |
    | quotes        |
    | testing       |
    +---------------+
    ubuntu@ip-172-31-44-6:~$ influxdb3 delete database testing
    Are you sure you want to delete "testing"? Enter 'yes' to confirm
    yes
    Database "testing" deleted successfully

你可能感兴趣的:(influxdb数据库)