gcgarner / IOTstack

docker stack for getting started on IOT on the Raspberry PI
GNU General Public License v3.0
1.52k stars 582 forks source link

Influx 1.7.9 container ignores env file? #105

Closed Habilya closed 4 years ago

Habilya commented 4 years ago

I've brought up an IoT Stack portainer Influxdb NodeRed Grafana Mosquitto

I've configured the InfluxDB env file.

INFLUXDB_DB=mydb
INFLUXDB_DATA_ENGINE=tsm1
INFLUXDB_REPORTING_DISABLED=false
#INFLUXDB_HTTP_AUTH_ENABLED=true
INFLUXDB_ADMIN_ENABLED=true
#INFLUXDB_ADMIN_USER=[...]
#INFLUXDB_ADMIN_PASSWORD=[...]
INFLUXDB_USER=nodered
INFLUXDB_USER_PASSWORD=[...]
INFLUXDB_READ_USER=myreaduser
INFLUXDB_READ_USER_PASSWORD=[...]
#INFLUXDB_WRITE_USER=mywriteuser
#INFLUXDB_WRITE_USER_PASSWORD=mywritepassword

But when I'm in the container and try to create a database, here is what I get.

root@60a13711febb:/# influx -precision rfc3339
Connected to http://localhost:8086 version 1.7.9
InfluxDB shell version: 1.7.9
> SHOW DATABASES
ERR: unable to parse authentication credentials
Warning: It is possible this error is due to not setting a database.
Please set a database with the command "use <database>".

here is what local influxdb.conf looks like

root@60a13711febb:/# cat /etc/influxdb/influxdb.conf
[meta]
  dir = "/var/lib/influxdb/meta"

[data]
  dir = "/var/lib/influxdb/data"
  engine = "tsm1"
  wal-dir = "/var/lib/influxdb/wal"
Paraphraser commented 4 years ago

You have to create a database first:

CREATE DATABASE test;

Also, as a useful hint, set up an alias in your .profile (ie outside the container) like this:

alias influx='docker exec -it influxdb influx -precision=rfc3339'

Then you can just type "influx" and be inside Influx's CLI in a single step. When you quit or exit, you're back to the Raspbian shell prompt.

Another alias I use for Influx is:

alias INFLUX_SHELL='docker exec -it influxdb bash'

You'll need that if you want to bring a portable-format backup from another instance of Influx into the container to side-load it.

Habilya commented 4 years ago

My apologies, It seems, I've edited the ENV file. Could it be, Influx, same as MariaDB, won't reflect changes in the ENV file upon container reload? perhaps same as in this issue: https://github.com/gcgarner/IOTstack/issues/102

I had to

  1. stop container
  2. remove container
  3. remove image
  4. sudo rm -rf volumes/influxdb
  5. nano ./services/influxdb/influxdb.env
  6. docker-compose up -d influxdb

Also, as you say

CREATE DATABASE test;

Do not forget to grant access to NodeRed user grants are not magically appearing for non admin users on freshly created databases (other than the on ein ENVfile). Which is a good thing

Thanks for useful info on the aliases, I figured it out, at last.

Paraphraser commented 4 years ago

I suppose that's entirely possible. In my case, I did not edit influxdb.env at all. It has always been "as supplied" so I can't comment one way or the other:

$ cat ~/IOTstack/services/influxdb/influxdb.env 
#INFLUXDB_DB=mydb
INFLUXDB_DATA_ENGINE=tsm1
INFLUXDB_REPORTING_DISABLED=false
#INFLUXDB_HTTP_AUTH_ENABLED=true
INFLUXDB_ADMIN_ENABLED=true
#INFLUXDB_ADMIN_USER=myadminuser
#INFLUXDB_ADMIN_PASSWORD=myadminpassword
INFLUXDB_USER=nodered
INFLUXDB_USER_PASSWORD=nodered
#INFLUXDB_READ_USER=myreaduser
#INFLUXDB_READ_USER_PASSWORD=myreadpassword
#INFLUXDB_WRITE_USER=mywriteuser
#INFLUXDB_WRITE_USER_PASSWORD=mywritepassword

On the topic of needing to grant access to the NodeRed user, I didn't do anything special there either. I knew I would have to create the database via the CLI before I could use it in Node-Red, so I did that but unless I'm forgetting something, that was the only thing I did.

In Node-Red, I have the "InfluxDB Out" nodes configured:

There is a basic four-node flow for each measurement:

Just works:

$ influx
Connected to http://localhost:8086 version 1.7.8
InfluxDB shell version: 1.7.8

> use power
Using database power

> select count(voltage) from solax;
name: solax
time                 count
----                 -----
1970-01-01T00:00:00Z 425069

> select count(voltage) from hiking;
name: hiking
time                 count
----                 -----
1970-01-01T00:00:00Z 5093955

> settings
Setting           Value
--------          --------
Host              localhost:8086
Username          
Database          power
RetentionPolicy   
Pretty            false
Format            column
Write Consistency all
Chunked           true
Chunk Size        0

> quit

Now that I'm actually looking at the .env file, it does seem to set the username and password to "nodered" but I'm definitely not using that in the Node-Red flows. Two measurements, one with half a million rows and the other with 5 million rows do not lie!

Before moving to IOTstack, I had been running non-Docker Influx on a Mac. Even on the Mac I didn't do anything more than create the empty database. No usernames or password. The only significant difference between the Mac and IOTstack flows was the former using "localhost" where the latter uses "influxdb" in the host field.

My migration strategy was to run in parallel until I was happy both the Mac and RPi4 were logging the incoming data to the respective Influx databases reliably, then a "portable" backup of everything on the Mac, move that onto the RPi4 and into the Influx container, side-load as a database with a different name, work out where the overlap began in terms of timestamps, then suck in everything the RPI4 didn't already have. Drop the side-loaded database and we're done. Since then it's been ticking away as happy as the proverbial Larry.

My biggest nagging doubt with the containerised version is the risk of everything turning to custard when the container needs to be upgraded. The situation with the Mosquitto container (#91) has made me very twitchy.