# 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
iptables -A INPUT -p tcp --dport 8086 -j ACCEPT
iptables -A INPUT -p tcp --dport 8888 -j ACCEPT
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
$ 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
$ influx -username admin -password passwd
> CREATE DATABASE cache WITH DURATION 1h
> CREATE DATABASE storage WITH DURATION 90d
> SHOW DATABASES
> EXIT
$ 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
$ 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
# создание пользователей
$ 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"
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); }
})