本文主要是介绍Influxdb系列(二)influx Cli工具操作influxdb,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、安装并使用 influx CLI
客户端下载地址:https://docs.influxdata.com/influxdb/v2/tools/influx-cli/
[root@192 bin]# tar -xvzf influxdb2-client-2.7.3-linux-amd64.tar.gz
[root@192 bin]# cp influx /usr/local/bin/
二、客户端方式创建用户
相关的官网地址可直接查看如下地址:
https://docs.influxdata.com/influxdb/v2/install/?t=Set+up+with+the+CLI
https://docs.influxdata.com/influxdb/v2/admin/tokens/create-token/#create-a-token-using-the-influx-cli
[root@localhost influxdb2-2.7.3]# ./influx setup \--username dameng \--password dameng123. \--token dameng123 \--org dameng \--bucket sqllog \--retention 3d \--force
User Organization Bucket
dameng dameng sqllog## 创建token
[root@localhost influxdb2-2.7.3]# ./influx auth create -o dameng --all-access
ID Description Token User Name User ID Permissions
0c1df02480e81000 7oIcg9OPYU31GS6Tu9oUklBSJx5iEM63iJU0AXXPbqXFfGe-zZ9p6mGLFtctteGVLJcFk9TvMePFQjqvk26rkQ== dameng 0c1def88b1281000 [read:orgs/6a10c0d35d75074f/authorizations write:orgs/6a10c0d35d75074f/authorizations read:orgs/6a10c0d35d75074f/buckets write:orgs/6a10c0d35d75074f/buckets read:orgs/6a10c0d35d75074f/dashboards write:orgs/6a10c0d35d75074f/dashboards read:/orgs/6a10c0d35d75074f read:orgs/6a10c0d35d75074f/sources write:orgs/6a10c0d35d75074f/sources read:orgs/6a10c0d35d75074f/tasks write:orgs/6a10c0d35d75074f/tasks read:orgs/6a10c0d35d75074f/telegrafs write:orgs/6a10c0d35d75074f/telegrafs read:/users/0c1def88b1281000 write:/users/0c1def88b1281000 read:orgs/6a10c0d35d75074f/variables write:orgs/6a10c0d35d75074f/variables read:orgs/6a10c0d35d75074f/scrapers write:orgs/6a10c0d35d75074f/scrapers read:orgs/6a10c0d35d75074f/secrets write:orgs/6a10c0d35d75074f/secrets read:orgs/6a10c0d35d75074f/labels write:orgs/6a10c0d35d75074f/labels read:orgs/6a10c0d35d75074f/views write:orgs/6a10c0d35d75074f/views read:orgs/6a10c0d35d75074f/documents write:orgs/6a10c0d35d75074f/documents read:orgs/6a10c0d35d75074f/notificationRules write:orgs/6a10c0d35d75074f/notificationRules read:orgs/6a10c0d35d75074f/notificationEndpoints write:orgs/6a10c0d35d75074f/notificationEndpoints read:orgs/6a10c0d35d75074f/checks write:orgs/6a10c0d35d75074f/checks read:orgs/6a10c0d35d75074f/dbrp write:orgs/6a10c0d35d75074f/dbrp read:orgs/6a10c0d35d75074f/notebooks write:orgs/6a10c0d35d75074f/notebooks read:orgs/6a10c0d35d75074f/annotations write:orgs/6a10c0d35d75074f/annotations read:orgs/6a10c0d35d75074f/remotes write:orgs/6a10c0d35d75074f/remotes read:orgs/6a10c0d35d75074f/replications write:orgs/6a10c0d35d75074f/replications]## 创建bucket
https://docs.influxdata.com/influxdb/v2/admin/buckets/create-bucket/?t=influx+CLIinflux bucket create \--name my-bucket \--org my-org \--retention 72h
三、创建配置文件_token认证
https://docs.influxdata.com/influxdb/v2/tools/influx-cli/
[root@192 bin]# ./influx config create --config-name influx.conf --host-url http://localhost:8086 --org dameng --token PMDQZts55MPX8LVnM7tr9dbA3_3_qwdyWnM0dBiLHzmNyjWOi1hIFJQFXFbssvUc2yJ8fpdQhDut4FUBzvN3qg== --active
Active Name URL Org
* influx.conf http://localhost:8086 dameng## 配置文件
[root@192 bin]# ll /root/.influxdbv2/configs
-rw-------. 1 root root 505 11月 4 20:33 /root/.influxdbv2/configs
四、InfluxQL语法
(一)DBRP映射
https://docs.influxdata.com/influxdb/v2/query-data/influxql/dbrp/
查询实体与DB的映射
- InfluxQL 需要数据库和保留策略 (DBRP) 组合才能查询数据。在 InfluxDB 2.7中,数据库和保留策略已合并并被 InfluxDB存储桶取代。要使用 InfluxQL 查询 InfluxDB 2.7,指定的 DBRP 组合必须映射到存储桶。
- InfluxDB 2.7将在以下操作过程中自动创建 DBRP 映射
[root@192 bin]# influx v1 dbrp list
ID Database Bucket ID Retention Policy Default Organization IDVIRTUAL DBRP MAPPINGS (READ-ONLY)
----------------------------------
ID Database Bucket ID Retention Policy Default Organization ID
07f41697d8ea4b1b _monitoring 07f41697d8ea4b1b autogen true ecaa1a71e66f91c3
7f9d57076f240d08 _tasks 7f9d57076f240d08 autogen true ecaa1a71e66f91c3
cdbb8518f3289a64 sqllog_20231104 cdbb8518f3289a64 autogen true ecaa1a71e66f91c3
(二)查询表数据
https://docs.influxdata.com/influxdb/v2/query-data/influxql/explore-data/
# 进入数据库
[root@192 bin]# influx v1 shell
# 使用数据库
> use "sqllog"
select execSqlStr from SqlEntity LIMIT 1;select execSqlStr from SqlEntity where entityType =3 LIMIT 5;## 计算条数
五、其他的命令
https://docs.influxdata.com/influxdb/v2/reference/cli/influx/auth/list/
influx auth list
这篇关于Influxdb系列(二)influx Cli工具操作influxdb的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!