开源时序数据库influxDB解决方案

InfluxDB 是一个开源分布式时序、事件和指标数据库。

使用 Go 语言编写,无需外部依赖。其设计目标是实现分布式和水平伸缩扩展。

一、与传统数据库中的名词做比较
nfluxDB中的名词 传统数据库中的概念
database 数据库
measurement 数据库中的表
points 表里面的一行数据

 

二、InfluxDB中独有的概念

1)database--数据库,这个同传统数据库的数据库概念。

2)measurement--数据表,在InfluxDB中,measurement即为表的作用,同传统数据库中的table作用一致。

1)tag--标签,在InfluxDB中,tag是一个非常重要的部分,表名+tag一起作为数据库的索引,是“key-value”的形式。

2)field--数据,field主要是用来存放数据的部分,也是“key-value”的形式。

3)timestamp--时间戳,作为时序型数据库,时间戳是InfluxDB中最重要的部分,在插入数据时可以自己指定也可留空让系统指定。

说明:在插入新数据时,tag、field和timestamp之间用空格分隔。

4)series--序列,所有在数据库中的数据,都需要通过图表来展示,而这个series表示这个表里面的数据,可以在图表上画成几条线。

5)Retention policy--数据保留策略,可以定义数据保留的时长,每个数据库可以有多个数据保留策略,但只能有一个默认策略。。

6)Point--点,表示每个表里某个时刻的某个条件下的一个field的数据,因为体现在图表上就是一个点,于是将其称为point。

1)Point

Point由时间戳(time)、数据(field)、标签(tags)组成。

Point相当于传统数据库里的一行数据,如下表所示:

Point属性 传统数据库中的概念
time 每个数据记录时间,是数据库中的主索引(会自动生成)
fields 各种记录值(没有索引的属性)也就是记录的值:温度, 湿度
tags 各种有索引的属性:地区,海拔
2)series

所有在数据库中的数据,都需要通过图表来展示,而这个series表示这个表里面的数据,可以在图表上画成几条线:通过tags排列组合算出来。

如下所示:

>show series from cpu
key
cpu,cpu=cpu-total,host=ResourcePool-0246-billing07
cpu,cpu=cpu-total,host=billing07
cpu,cpu=cpu0,host=ResourcePool-0246-billing07
cpu,cpu=cpu0,host=billing07
cpu,cpu=cpu1,host=ResourcePool-0246-billing07
cpu,cpu=cpu1,host=billing07
cpu,cpu=cpu10,host=ResourcePool-0246-billing07
cpu,cpu=cpu10,host=billing07
cpu,cpu=cpu11,host=ResourcePool-0246-billing07
cpu,cpu=cpu11,host=billing07
cpu,cpu=cpu12,host=ResourcePool-0246-billing07
cpu,cpu=cpu12,host=billing07
cpu,cpu=cpu13,host=ResourcePool-0246-billing07
cpu,cpu=cpu13,host=billing07
cpu,cpu=cpu14,host=ResourcePool-0246-billing07
cpu,cpu=cpu14,host=billing07
cpu,cpu=cpu15,host=ResourcePool-0246-billing07
cpu,cpu=cpu15,host=billing07
cpu,cpu=cpu16,host=ResourcePool-0246-billing07
cpu,cpu=cpu17,host=ResourcePool-0246-billing07
cpu,cpu=cpu18,host=ResourcePool-0246-billing07
cpu,cpu=cpu19,host=ResourcePool-0246-billing07
cpu,cpu=cpu2,host=ResourcePool-0246-billing07
cpu,cpu=cpu2,host=billing07
cpu,cpu=cpu20,host=ResourcePool-0246-billing07
cpu,cpu=cpu21,host=ResourcePool-0246-billing07
cpu,cpu=cpu22,host=ResourcePool-0246-billing07
cpu,cpu=cpu23,host=ResourcePool-0246-billing07
cpu,cpu=cpu3,host=ResourcePool-0246-billing07
cpu,cpu=cpu3,host=billing07
cpu,cpu=cpu4,host=ResourcePool-0246-billing07
cpu,cpu=cpu4,host=billing07
cpu,cpu=cpu5,host=ResourcePool-0246-billing07
cpu,cpu=cpu5,host=billing07
cpu,cpu=cpu6,host=ResourcePool-0246-billing07
cpu,cpu=cpu6,host=billing07
cpu,cpu=cpu7,host=ResourcePool-0246-billing07
cpu,cpu=cpu7,host=billing07
cpu,cpu=cpu8,host=ResourcePool-0246-billing07
cpu,cpu=cpu8,host=billing07
cpu,cpu=cpu9,host=ResourcePool-0246-billing07
cpu,cpu=cpu9,host=billing07



它有三大特性:

1. Time Series (时间序列):你可以使用与时间有关的相关函数(如最大,最小,求和等)

2. Metrics(度量):你可以实时对大量数据进行计算

3. Eevents(事件):它支持任意的事件数据

特点

schemaless(无结构),可以是任意数量的列

Scalable

min, max, sum, count, mean, median 一系列函数,方便统计

Native HTTP API, 内置http支持,使用http读写

Powerful Query Language 类似sql

Built-in Explorer 自带管理工具


安装好influxdb后通过终端登录到数据库,http api over 8086,页面为8083

[root@mycat ~]# inf

influx          influx_inspect  influx_tsm      infocmp         infotocap

influxd         influx_stress   info            infokey     


通过influx登陆终端

[root@mycat ~]# influx

Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.

Connected to http://localhost:8086 version 0.13.0

InfluxDB shell version: 0.13.0

1、Creating a database,注意关键词的大小写

> CREATE DATABASE mydb;

> SHOW DATABASES;

name: databases

---------------

name

telegraf

_internal

mytab

mydb

2、切换库,有的关键字也没那么规范

> use mydb

Using database mydb

> USE mydb

Using database mydb

3、Writing and exploring data,写入一条数据需要基础格式

1、a short primer on the datastore#存放数据的实体对象,相当在关系型数据的表名

数据在时序数据库(influxDB)是有组织的时间序列,包含一个 测量值(即在RMDB中的字段),在INFLUXDB中如cpu_load或者temperature,


Points are written to InfluxDB using the Line Protocol, which follows the following format:

<measurement>[,<tag-key>=<tag-value>...] <field-key>=<field-value>[,<field2-key>=<field2-value>...] [unix-nano-timestamp]


The following lines are all examples of points that can be written to InfluxDB:


cpu,host=serverA,region=us_west value=0.64

payment,device=mobile,product=Notepad,method=credit billed=33,licenses=3i 1434067467100293230

stock,symbol=AAPL bid=127.46,ask=127.48

temperature,machine=unit42,type=assembly external=25,internal=37 1434067467000000000

这3条例子具体写法:


InfluxDB中没有显式的新建表的语句,只能通过insert数据的方式来建立新表。如下所示:

insert disk_free,hostname=server01 value=442221834240i 1435362189575692182

其中 disk_free 就是表名,hostname是索引,value=xx是记录值,记录值可以有多个,最后是指定的时间

> insert cpu,host=serverA,region=us_west value=0.64

> select host,region ,value from cpu ##官方写法是把这些测量值加引号

name: cpu

---------

timehostregionvalue

1481203149917071248serverAus_west0.64


insert disk_free,hostname=server01 value=442221834240i 1435362189575692182

在这条语句中,disk_free是表名,hostname=server01是tag,属于索引,value=xx是field,这个可以随意写,随意定义。


A point with the measurement name of cpu and tags host and region has now been written to the database, with the measured value of 0.64.


另一种类型的数据存储,在相同的测量两个字段:

相同的测量值包含两个字段类型的数据

INSERT temperature,machine=unit42,type=assembly external=25,internal=37

> select * from temperature

name: temperature

-----------------

timeexternalinternalmachinetype

14812037975306309012537unit42assembly

删除一个度量值

delete from cpu

show 支持的方法

 CONTINUOUS, DATABASES, DIAGNOSTICS, FIELD, GRANTS, MEASUREMENTS, QUERIES, 

RETENTION, SERIES, SHARD, SHARDS, STATS, SUBSCRIPTIONS, TAG, USERS


SHOW TAG KEYS FROM "temperature" 显示度量值的标签===show create table aa

influxdb支持正则



series操作

series表示这个表里面的数据,可以在图表上画成几条线,series主要通过tags排列组合算出来

show series from mem




设置TS的authorized,提高安全性,针对指定用户拥有权限才能访问数据库的数据,TS默认用户分为普通用户和管理员用户,权限分为read,write,all privileges三种权限

添加用户可以通过终端或者WEB方式2种方式:

开启一个用户权限的过程:

1、在安装好数据库后,通过默认方式登陆数据库:[root@mycat ~]# influx 

2、添加用户

    CREATE USER "influxdb" WITH PASSWORD 'root123' WITH ALL PRIVILEGES

3、修改配置文件:

wKiom1hNNznAKuzZAAC7j5wzLNI073.png-wh_50

4、设置好后重启服务

5、WEB验证登陆数据:

wKioL1hNN-XxJyjoAAB1TyTlUPg870.png-wh_50

注意这里若不是admin权限登录的,会ERROR

Server returned error: error authorizing query: dlan not authorized to execute statement 'SHOW DATABASES', requires admin privilege

终端登录:

influx  -host 'localhost' -port '8086' -username 'admin' -password 'root123' 

目前测试遇到问题:

添加普通用户,授权write或者read或者all都不能生效,用普通方式创建的用户登录会提示:

[root@mycat ~]# influx  -host '192.168.1.114' -port '8086' -username 'dlan2' -password 'root123'  

Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.

Connected to http://192.168.1.114:8086 version 0.13.0

InfluxDB shell version: 0.13.0

> show databases

ERR: error authorizing query: dlan2 not authorized to execute statement 'SHOW DATABASES', requires admin privilege

Warning: It is possible this error is due to not setting a database.

Please set a database with the command "use <database>".

>show grants for dlan2

databaseprivilege

mytabREAD   #权限修改依然无法访问,一样提示错误


根据目前测试只能使用admin权限才可以操作数据库,或者需要设置那里,需要验证,,,,,

删除用户:

     drop user dlan

用户授权:

    grant all on mydb to dlan

   用户授权只能对单个measurement

删除权限:

     revoke read on mydb from dlan

貌似目前开启auth只能通过admin权限管理库,其他等待验证









influxdb的几种操作方法,有喜欢用http API的方式来写入数据,或者通过influxdb的终端来操作(我喜欢的类型),每种方式都适合的场景。

介绍通过API接口和终端方式来操作:

http://192.168.15.104:8086/write?db=mydb&cpu_load_short,host=server01,dc=mycat,region=us-west value=0.64

终端写入:

use mydb

insert cpu_load_short,host=server01,dc=mycat,region=us-west value=0.64


查询数据:(在URL的窗口里),开始以为是在8083的页面那查询,一直乌龙着......

wKioL1hYmC2i0V-_AACXBDSdKX0624.png-wh_50

http://192.168.15.104:8086/query?db=mydb&q=SHOW%20MEASUREMENTS  #查看库下的measurements

http://192.168.15.104:8086/query?db=mydb&q=select%20*%20from%20disk_use #查看具体的数据



##小记事:

%20是空格

%22是“


  • 0
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
时序数据库InfluxDB的性能测试是通过在特定环境下对其进行写入和查询测试来评估其性能表现。在一个具体的测试环境中,使用了4核16G的CPU内存和1Gbit/s的带宽,操作系统为Ubuntu 4.8.4-2ubuntu1~14.04.3。测试结果显示,InfluxDB在处理时序数据方面表现出色。 引用\[2\]中提到了对InfluxDB的性能测试报告。测试环境包括写入测试和查询测试。在写入测试中,通过模拟大量的写入操作来测试InfluxDB的写入性能。在查询测试中,通过执行各种类型的查询操作来测试InfluxDB的查询性能。 InfluxDB是用Go语言编写的一个开源分布式时序、事件和指标数据库,无需外部依赖。它专门设计用于处理时序数据,并且在处理大量数据和多样化数据类型方面表现出色。相比传统的关系型数据库InfluxDB时序数据处理方面具有更高的性能和效率。 总结来说,时序数据库InfluxDB在性能测试中展现出了优秀的表现,特别适用于处理时序数据。它的高性能和高效率使其成为许多应用场景中的首选数据库。 #### 引用[.reference_title] - *1* [【数据库时序数据库InfluxDB 性能测试和为什么时序数据库更快、时序数据库应用场景...](https://blog.csdn.net/weixin_42319496/article/details/119372355)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [性能爆表-时序数据库InfluxDB](https://blog.csdn.net/kobe_okok/article/details/117233188)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值