Influxdb

第一章 InfluxDB的认识

InfluxDB是TICK堆栈中的时间序列数据库

InfluxDB用作涉及大量时间戳数据的任何用例的数据存储,包括DevOps监控,应用指标,IoT传感器数据和实时分析。通过配置InfluxDB来保持数据在定义的时间长度,自动过期并从系统中删除任何不需要的数据,从而节省机器上的空间。InfluxDB还提供了一种类似SQL的查询语言,用于与数据交互。

高性能

InfluxDB是专门针对时间序列数据编写的定制高性能数据存储。它允许高吞吐量,压缩和实时查询同一数据。InfluxDB完全写在Go中,它编译成一个没有外部依赖关系的单个二进制文件。InfluxDB提供高性能的写入和查询HTTP / S API,并支持数据采集协议(如Telegraf,Graphite,collectd和OpenTSDB)的插件。

类似SQL的查询

InfluxDB提供InfluxQL作为与数据交互的类SQL查询语言。对于来自其他SQL或类SQL环境的用户来说,它已经被精心设计,同时还提供特定于存储和分析时间序列数据的功能。InfluxQL还支持正则表达式,算术表达式和时间序列特定功能,以加快数据处理速度

采样与数据保留

InfluxDB可以处理每秒数百万个数据点。长时间使用这些数据可能会造成存储问题。一个自然的解决方案是对数据进行缩减; 保持高精度原始数据只有有限的时间,并将较低精度,总结数据存储更长时间或永远。InfluxDB提供了两个功能 - 连续查询(CQ)和保留策略(RP) -帮助您自动执行数据下采样和过期旧数据的过程

第二章 软件程序包的下载安装

2.1 下载位置

DownLoad

2.2 安装Telegraf

wget https://dl.influxdata.com/telegraf/releases/telegraf_1.3.5-1_amd64.deb
sudo dpkg -i telegraf_1.3.5-1_amd64.deb 

2.3 安装InfluxDB

wget https://dl.influxdata.com/influxdb/releases/influxdb_1.3.2_amd64.deb
sudo dpkg -i influxdb_1.3.2_amd64.deb 

2.4 安装Chronograf

wget https://dl.influxdata.com/chronograf/releases/chronograf_1.3.6.1_amd64.deb
sudo dpkg -i chronograf_1.3.6.1_amd64.deb 

2.5 安装Kapacitor

wget https://dl.influxdata.com/kapacitor/releases/kapacitor_1.3.1_amd64.deb
sudo dpkg -i kapacitor_1.3.1_amd64.deb 

了解一些名词概念

  • tag:influxdb中的标签,与表名在一起作为数据库的索引,可以看作是表名称K-V结构
  • field:用于存放数据的部分,可以存在多个值使用逗号分开,K-V结构,k相当于列名称,v相当于插入此条数据的列的值
  • timestamp:时间戳,可以自己制定也可以由系统自己指定,如果不指定,默认就是系统当前的时间戳
    注意:在插入新的数据时tag,field,timestamp需要有空格分开
  • series:序列,所有在数据库中的数据,都需要通过图表来展示,而这个series表示这个表里面的数据,可以在图表上画成几条线
  • Retention policy:数据保留策略,可以定义数据保留的时长,每个数据库可以有多个数据保留策略,但只能有一个默认策略
  • Point:点,表示每个表里某个时刻的某个条件下的一个field的数据,因为体现在图表上就是一个点,于是将其称为point,point的组成:point=timestamp+field+tags

第三章 Influxdb的环境配置

3.1 安装influxdb

Influxdb安装官方参考手册

3.2 Influxdb端口

  • 8003:此端口之前是influxdb提供的web管理页面的端口,1.3版本之后被弃用
  • 8086:TCP端口8086用于通过InfluxDB的HTTP API进行客户端 - 服务器通信
  • 8088:TCP端口8088用于RPC服务进行备份和还原

注意 :除了上述端口,InfluxDB还提供可能需要自定义端口的多个插件。所有端口映射都可以通过配置文件修改,该配置文件位于/etc/influxdb/influxdb.conf默认安装位置

3.3 时间同步

InfluxDB使用主机在UTC的本地时间为数据和协调目的分配时间戳。使用网络时间协议(NTP)来同步主机之间的时间; 如果主机的时钟与NTP不同步,写入InfluxDB的数据的时间戳可能不正确

3.4 Influxdb的配置

  • influxd config:用于查看默认的配置
  • influxd -config PATH/TO/CONFIGFILE:将进程指向正确的配置文件
  • INFLUXDB_CONFIG_PATH:通过环境变量设置配置文件的路径并启动influxdb

注意 :influxdb首先检查-config选项,然后检查环境变量

3.4.1 influxDB配置选项

configure

3.5 influxdb数据目录的权限

chown influxdb:influxdb /PATH/TO/DATA

第四章 CLI/SHELL

InfluxDB的命令行界面(influx)是HTTP API的交互式shell。用于influx手动或从文件写入数据,以交互方式查询数据,并查看不同格式的查询输出。

4.1 启动influx

which influx
find / -iname influx 
influx
  • 启动influxd数据库进程
  • 启动influx终端shell连接数据库

注意 : CLI和InfluxDB版本应该相同。如果没有,它可以导致解析查询问题。

4.2 influx参数

influx --help
influx -execute 'SELECT * FROM "h2o_feet" LIMIT 3' -database="NOAA_water_database" -precision=rfc3339

官方文档

  • -import
    • DDL(数据定义语言):包含用于创建相关数据库和管理保留策略的InfluxQL命令。如果您的数据库和保留策略已经存在,您的文件可以跳过本节
    • DML(数据操作语言):列出相关数据库和(如果需要)保留策略,并包含行协议中的数据。
  • -execute
  • -format
Usage of influx:
  -version
       Display the version and exit.
  -host 'host name'
       Host to connect to.
  -port 'port #'
       Port to connect to.
  -socket 'unix domain socket'
       Unix socket to connect to.
  -database 'database name'
       Database to connect to the server.
  -password 'password'
      Password to connect to the server.  Leaving blank will prompt for password (--password '').
  -username 'username'
       Username to connect to the server.
  -ssl
        Use https for requests.
  -unsafeSsl
        Set this when connecting to the cluster using https and not use SSL verification.
  -execute 'command'
       Execute command and quit.
  -format 'json|csv|column'
       Format specifies the format of the server responses:  json, csv, or column.
  -precision 'rfc3339|h|m|s|ms|u|ns'
       Precision specifies the format of the timestamp:  rfc3339, h, m, s, ms, u or ns.
  -consistency 'any|one|quorum|all'
       Set write consistency level: any, one, quorum, or all
  -pretty
       Turns on pretty print for the json format.
  -import
       Import a previous database export from file
  -pps
       How many points per second the import will allow.  By default it is zero and will not throttle importing.
  -path
       Path to file to import
  -compressed
       Set to true if the import file is compressed

Examples:

    # Use influx in a non-interactive mode to query the database "metrics" and pretty print json:
    $ influx -database 'metrics' -execute 'select * from cpu' -format 'json' -pretty

    # Connect to a specific database on startup and set database context:
    $ influx -database 'metrics' -host 'localhost' -port '8086'

第五章 示例数据

5.1 导入示例数据到influxdb

样本数据是国家海洋和大气管理局(NOAA)运行海洋学产品和服务中心的公开数据。数据包括2015年8月18日至2015年9月18日期间两站(Santa Monica,CA(ID 9410840)和Coyote Creek,CA(ID 9414575))每6秒收集的水位(ft)的15,258次

influx -precision rfc3339 #按照rfc3339格式启动influxdb
CREATE DATABASE NOAA_water_database #创建示例数据数据库
curl https://s3.amazonaws.com/noaa.water-database/NOAA_data.txt -o NOAA_data.txt #下载示例数据到本地
influx -precision rfc3339 -database NOAA_water_database #连接数据库
SHOW DATABASES #测试数据库数据

第六章 InfluxQL

6.1 查询数据库

influxQL中有用的查询及声明*

基础 配置查询结果 查询格式的条件
select语句 ORDER BY time DESC Time Syntax
where子句 The LIMIT and SLIMIT Clauses Regular Expressions
group by子句 The OFFSET and SOFFSET Clauses Data Types and Cast Operations
into子句 The Time Zone Clause Merge Behavior
. . Multiple Statements
. . Subqueries
select语法
SELECT <field_key>[,<field_key>,<tag_key>] FROM <measurement_name>[,<measurement_name>]

select子句支持指定数据的几种格式

第五章 influxdb优化选项参数配置

influxdb config

posted @ 2017-11-02 23:42  云原生生态圈  阅读(2758)  评论(0编辑  收藏  举报