InfluxDB


1. Установка

# DEBIAN
$ wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -
$ source /etc/os-release
$ echo "deb https://repos.influxdata.com/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/influxdb.list

# UBUNTU
$ echo "deb https://repos.influxdata.com/ubuntu bionic stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
$ sudo curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install influxdb

# Start and enable the service to start on boot up
$ sudo systemctl enable --now influxdb
$ sudo systemctl status influxdb

Firewall

iptables -A INPUT -p tcp --dport 8086 -j ACCEPT
iptables -A INPUT -p tcp --dport 8888 -j ACCEPT

Configuration

HTTP Authentication

# /etc/influxdb/influxdb.conf
...
# Determines whether HTTP authentication is enabled.
auth-enabled = true
...

если изменить порт и ip по умолчанию в конфигурационном файле, то строка запуска будет иметь вид:

$ influx -port 'xxxx' -username admin -password paswd -host localhost

2. Создание пользователей

$ influx
   > CREATE USER admin WITH PASSWORD 'passwd' WITH ALL PRIVILEGES
   > CREATE USER sensor WITH PASSWORD '123456'
   > CREATE USER web WITH PASSWORD '123456'
   > EXIT

$ sudo service influxdb restart

$ influx -username admin -password passwd
   > SHOW USERS
   > EXIT

3. Создание баз данных

$ influx -username admin -password passwd
   > CREATE DATABASE cache WITH DURATION 1h
   > CREATE DATABASE storage WITH DURATION 90d
   > SHOW DATABASES
   > EXIT

4. Установка прав доступа

$ influx -username admin -password passwd
   > GRANT WRITE ON 'cache' TO 'sensor'
   > GRANT READ ON 'cache' TO 'web'
   > GRANT ALL ON 'storage' TO 'web'
   > SHOW GRANTS FOR sensor
   > SHOW GRANTS FOR web
   > EXIT

5. Запись данных (CLI)

$ influx -username sensor -password 123456 -precision rfc3339
   > USE cache
   > INSERT test, tag1=st10,tag2=state param1=3,param2=100
   > INSERT test, tag1=st10,tag2=state param1=3,param2=200
   ...
   > SHOW MEASUREMENTS
   > SELECT * FROM test

Use HTTP API

# создание пользователей
$ curl -i -XPOST 'http://localhost:8086/query' --data-urlencode "q=CREATE USER admin WITH PASSWORD 'passwd' WITH ALL PRIVILEGES"
$ curl -i -XPOST 'http://localhost:8086/query' --data-urlencode "q=CREATE USER sensor WITH PASSWORD '123456' "
$ curl -i -XPOST 'http://localhost:8086/query' --data-urlencode "q=CREATE USER web WITH PASSWORD '123456' "

# создание баз данных
$ curl -i -XPOST 'http://localhost:8086/query' -u admin:passwd --data-urlencode "q=CREATE DATABASE cache"
$ curl -i -XPOST 'http://localhost:8086/query' -u admin:passwd --data-urlencode "q=CREATE DATABASE storage"
$ curl -i -XPOST 'http://localhost:8086/query' -u admin:passwd --data-urlencode "q=SHOW DATABASES"

# запись данных
$ curl -i -XPOST 'http://localhost:8086/write?db=cache' -u sensor:123456 --data-binary 'test, tag1=st10,tag2=state param1=3,param2=100'
$ curl -i -XPOST 'http://localhost:8086/write?db=cache' -u sensor:123456 --data-binary 'test, tag1=st10,tag2=state param1=3,param2=200'

# чтение данных
$ curl -i -XPOST 'http://localhost:8086/query' -u sensor:123456 --data-urlencode "db=cache" --data-urlencode "q=SELECT * FROM \"st10\" WHERE \"type\"='measured' GROUP BY * ORDER BY DESC LIMIT 1"

jQuery

var url="http://localhost:8086/query?db=cache&u=web&p=123456&q=SELECT * FROM %22st10%22 GROUP BY * ORDER BY DESC LIMIT 1";

$.ajax({
         url: url,
         type: 'POST',
         success: function(data) {  console.log(data); },
         error: function(test, status, exception) { console.log("Error: " + exception); }
      })

Дополнительные источники