一、InfluxDB简介

InfluxDB 是一个开源分布式时序、事件和指标数据库。使用 Go 语言编写,无需外部依赖。其设计目标是实现分布式和水平伸缩扩展。

它有三大特性:

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 自带管理工具
API

InfluxDB 支持两种api方式

  • HTTP API
  • Protobuf API

 

二、InfluxDB安装

# cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo
> [influxdb]
> name = InfluxDB Repository - RHEL \$releasever
> baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
> enabled = 1
> gpgcheck = 1
> gpgkey = https://repos.influxdata.com/influxdb.key
> EOF
yum install influxdb

#Redhat6
service influxdb start

#Redhat7
systemctl start influxdb

三、InfluxDB 命令行简单操作

# influx -precision rfc3339
Connected to http://localhost:8086 version 1.2.0
InfluxDB shell version: 1.2.0
> CREATE DATABASE mydb
> show databases;
name: databases
name
----
_internal
mydb

> use mydb
Using database mydb
> insert cpu,host=192.168.62.200,region=kbsonlong value=0.8
> select host,region,value from cpu
name: cpu
time                           host           region    value
----                           ----           ------    -----
2017-03-02T05:44:55.584864069Z 192.168.62.200 kbsonlong 0.8

>  INSERT temperature,machine=unit42,type=assembly external=25,internal=37
> SELECT * FROM "temperature"
name: temperature
time                           external internal machine type
----                           -------- -------- ------- ----
2017-03-02T05:45:31.933478802Z 25       37       unit42  assembly

> SELECT * FROM "cpu" WHERE "value" > 0.7
name: cpu
time                           host           region    value
----                           ----           ------    -----
2017-03-02T05:44:55.584864069Z 192.168.62.200 kbsonlong 0.8

>

 

四、配置Web管理界面

InfluxDB管理界面默认端口为8083,默认没有开启。

# netstat -ntlp|grep 808
tcp        0      0 :::8086                     :::*                        LISTEN      2654/influxd        
tcp        0      0 :::8088                     :::*                        LISTEN      2654/influxd        

# vim /etc/influxdb/influxdb.conf

找到[admin]选项 修改enabled = falseenabled = true

重启InfluxDB服务

# service influxdb restart
Stopping influxdb...
influxdb process was stopped [ OK ]
Starting influxdb...
influxdb process was started [ OK ]

# netstat -ntlp|grep 808
tcp        0      0 :::8083                     :::*                        LISTEN      3115/influxd        
tcp        0      0 :::8086                     :::*                        LISTEN      3115/influxd        
tcp        0      0 :::8088                     :::*                        LISTEN      3115/influxd

image

image