[SOLVED] Error setting up InfluxDB+Grafana

Hi guys, I got in the setup via „sudo openhabian-config“ a error in the installation.

Now I tried via the manual steps to find the issue.
It seems to be a authentification problem.

Connected to http://localhost:8086 version 1.7.9
InfluxDB shell version: 1.7.9
> CREATE DATABASE openhab_db
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>".
> use openhab_db
ERR: unable to parse authentication credentials
DB does not exist!
> CREATE DATABASE openhab_db
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>".

I tried to fix it that way:

[20:44:51] openhabian@openhab:~$ sudo chown -hR openhab:openhab /etc/openhab2
[sudo] Passwort für openhabian:
[20:45:30] openhabian@openhab:~$ sudo su
[20:45:36] root@openhab:/home/openhabian# sudo chown openhab:openhabian /etc/openhab2/services/influxdb.cfg
[20:45:54] root@openhab:/home/openhabian# influx -port 8086 -username admin -password XYZ5 -host localhost
[1] 15369
bash: home: Kommando nicht gefunden.
[20:47:49] root@openhab:/home/openhabian# Connected to http://localhost:8086 version 1.7.9
InfluxDB shell version: 1.7.9


[1]+  Angehalten              influx -port 8086 -username admin -password XYZ5
[20:51:11] root@openhab:/home/openhabian#

Any idea where I have to look to fix that?

You did login first with.

auth

?

If you do not then for

use openhab_db

you will get

ERR: unable to parse authentication credentials
DB does not exist!

InfluxDB requires you to create the admin user first if HTTP authentication is enabled (default).
Your first command should be:

CREATE USER admin WITH PASSWORD '<password>' WITH ALL PRIVILEGES

Only then can you interact with the system and create databases and other users. See the InfluxDB documentation.

openhabian should have worked for you to set this up. What was the error you saw when you tried with it?

I wasn’t sure if openHABian already creates the admin user…
In that case see this post…

Thanks for your help. I tried your this but get following results. Seems like the admin exists but not with the right priviliges.

[09:58:26] openhabian@openhab:~$ influx
Connected to http://localhost:8086 version 1.7.9
InfluxDB shell version: 1.7.9
> CREATE USER admin WITH PASSWORD 'XYZ5' WITH ALL PRIVILEGES
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>".
> auth admin
username: admin
password:
> CREATE DATABASE openhab_db
ERR: authorization failed
Warning: It is possible this error is due to not setting a database.
Please set a database with the command "use <database>".
>  CREATE USER admin WITH PASSWORD 'XYZ5' WITH ALL PRIVILEGES
ERR: authorization failed
Warning: It is possible this error is due to not setting a database.
Please set a database with the command "use <database>".
>
> auth admin
username: admin
password:
> use openhab_db
WARN: authorization failed
Using database openhab_db
>

  1. Is there a possibility to get the log-file from the initial installation?

  2. Or if not; how do I uninstall it in the right way so I can install influx again with openhab-config?

@jswim788

I removed completle the grafana installation via

sudo apt-get remove --auto-remove grafana
sudo apt-get purge --auto-remove grafana

now I installed again via openhab-config, enclosed you see the error as I got it the first time on apretty clean installation. (openhabian)

$ systemctl daemon-reload

$ systemctl enable influxdb.service

$ systemctl restart influxdb.service
OK Configure InfluxDB admin account... curl: (7) Failed to connect to localhost port 8086: Verbindungsaufbau abgelehnt
FAILED Configure listen on localhost only...
$ sed -i -e /# Determines whether HTTP endpoint is enabled./ { n ; s/# enabled = true/enabled = true/ } /etc/influxdb/influxdb.conf

$ sed -i s/# bind-address = ":8086"/bind-address = "localhost:8086"/g /etc/influxdb/influxdb.conf

$ sed -i s/# auth-enabled = false/auth-enabled = true/g /etc/influxdb/influxdb.conf

$ sed -i s/# store-enabled = true/store-enabled = false/g /etc/influxdb/influxdb.conf

$ systemctl restart influxdb.service
FAILED
Setup of inital influxdb database and InfluxDB users... curl: (7) Failed to connect to localhost port 8086: Verbindungsaufbau abgelehnt
curl: (7) Failed to connect to localhost port 8086: Verbindungsaufbau abgelehnt
curl: (7) Failed to connect to localhost port 8086: Verbindungsaufbau abgelehnt
curl: (7) Failed to connect to localhost port 8086: Verbindungsaufbau abgelehnt
curl: (7) Failed to connect to localhost port 8086: Verbindungsaufbau abgelehnt
FAILED Installing Grafana...--2020-02-06 22:37:40--  https://packages.grafana.com/gpg.key
Auflösen des Hostnamens packages.grafana.com (packages.grafana.com)… 2a04:4e42:1b::729, 151.101.114.217
Verbindungsaufbau zu packages.grafana.com (packages.grafana.com)|2a04:4e42:1b::729|:443 … verbunden.
HTTP-Anforderung gesendet, auf Antwort wird gewartet … 200 OK
Länge: 1694 (1,7K) [application/x-iwork-keynote-sffkey]
Wird in »STDOUT« gespeichert.

---- Output on OPENHAB-CONFIG ----------------------------------------------
┌──────────────────┤ Operation Failed! ├───────────────────┐
                                                                │                                                          │
                                                                │ Sadly there was a problem setting up the selected        │
                                                                │ option. Please report this problem in the openHAB        │
                                                                │ community forum or as a openHABian GitHub issue.         │
                                                                │                                                          │
                                                                │                                                          │
                                                                │                          <Ok>  


I’m not an expert on openhabian, but I can see that it is trying to run the code below. For some reason the curl command can’t connect in order to create the admin user. I can think of 2 possible reasons:

  1. The sleep wasn’t long enough
  2. The InfluxDB service didn’t start for some reason

What do you get from this?

systemctl status influxdb

and from?

ps -ef | grep -i influx

Here’s a snippet from what openhabian is trying to do:

    cond_redirect systemctl restart influxdb.service
    sleep 30
    if [ $FAILED -eq 1 ]; then echo -n "FAILED "; else echo -n "OK "; fi
    echo -n "Configure InfluxDB admin account... "; echo -n ""
    curl --insecure $influxdb_address/query --data-urlencode "q=CREATE USER admin WITH PASSWORD '$1' WITH ALL PRIVILEGES" || FAILED=1
    if [ $FAILED -eq 1 ]; then echo -n "FAILED "; else echo -n "OK "; fi
    echo -n "Configure listen on localhost only... "; echo -n ""

I assume this means connection refused?

@noppes123 above in post 3 does show how you can create the admin user manually if needed from the InfluxDB cli. Not sure that is the problem when using openhabian, though.

You can also try the curl command manually to see what it does (fill in the password). You don’t happen to have anything else trying to run on port 8086 do you?

curl --insecure http://localhost:8086/query --data-urlencode "q=CREATE USER admin WITH PASSWORD XXXX WITH ALL PRIVILEGES"
1 Like

From the openhabian-config output it is obvious that the InfluxDB daemon fails to start. The most common reasons are port already in use (as @jswim788 already mentioned), and access rights. Since the setup is done with openHABian, the 2nd option is unlikely. The first option can easily be checked with:

sudo lsof -i -P -n | grep LISTEN

Also, try to start the InfluxDB daemon manually to see what happens:

sudo systemctl start influxdb

and check the status and syslog with

sudo systemctl status influxdb
sudo journalctl -u influxdb

What results do you get?

sorry stupid question, how can it be possible that my linux doesen’t recognize lsof?

[18:27:29] root@openhab:/home/openhabian# sudo lsof -i -P -n | grep LISTEN
sudo: lsof: Befehl nicht gefunden

Looks like you need to install it. See: https://www.raspberrypi.org/forums/viewtopic.php?t=220489

sudo apt update
sudo apt install lsof

now I got to status:

[00:09:05] root@openhab:/home/openhabian# sudo lsof -i -P -n | grep LISTEN
node        463    openhab   19u  IPv4  14888      0t0  TCP *:9001 (LISTEN)
sshd        514       root    3u  IPv4  13690      0t0  TCP *:22 (LISTEN)
sshd        514       root    4u  IPv6  13692      0t0  TCP *:22 (LISTEN)
smbd        586       root   32u  IPv6  13850      0t0  TCP *:445 (LISTEN)
smbd        586       root   33u  IPv6  13851      0t0  TCP *:139 (LISTEN)
smbd        586       root   34u  IPv4  13852      0t0  TCP *:445 (LISTEN)
smbd        586       root   35u  IPv4  13853      0t0  TCP *:139 (LISTEN)
influxd    1714   influxdb    3u  IPv4 496329      0t0  TCP 127.0.0.1:8088 (LISTEN)
influxd    1714   influxdb    5u  IPv4 498344      0t0  TCP 127.0.0.1:8086 (LISTEN)
grafana-s  2593    grafana    6u  IPv6 500317      0t0  TCP *:3000 (LISTEN)
java      11921    openhab   50u  IPv6 384609      0t0  TCP 192.168.178.202:9125 (LISTEN)
java      11921    openhab   59u  IPv6 246205      0t0  TCP *:8443 (LISTEN)
java      11921    openhab   72u  IPv6 246208      0t0  TCP *:8080 (LISTEN)
java      11921    openhab  132u  IPv6 247123      0t0  TCP 127.0.0.1:43731 (LISTEN)
java      11921    openhab  154u  IPv6 248023      0t0  TCP 127.0.0.1:8101 (LISTEN)
java      11921    openhab  164u  IPv6 246224      0t0  TCP *:5007 (LISTEN)
[00:09:28] root@openhab:/home/openhabian#

[00:11:51] root@openhab:/home/openhabian# sudo systemctl status influxdb
● influxdb.service - InfluxDB is an open-source, distributed, time series databa
   Loaded: loaded (/lib/systemd/system/influxdb.service; enabled; vendor preset:
   Active: active (running) since Thu 2020-02-06 22:37:10 CET; 1 day 1h ago
     Docs: https://docs.influxdata.com/influxdb/
 Main PID: 1714 (influxd)
    Tasks: 14 (limit: 2319)
   Memory: 11.8M
   CGroup: /system.slice/influxdb.service
           └─1714 /usr/bin/influxd -config /etc/influxdb/influxdb.conf

Feb 08 00:05:00 openhab influxd[1714]: [httpd] 127.0.0.1 - openhab [08/Feb/2020:
Feb 08 00:06:00 openhab influxd[1714]: [httpd] 127.0.0.1 - openhab [08/Feb/2020:
Feb 08 00:07:00 openhab influxd[1714]: [httpd] 127.0.0.1 - openhab [08/Feb/2020:
Feb 08 00:07:54 openhab influxd[1714]: ts=2020-02-07T23:07:54.469608Z lvl=info m
Feb 08 00:07:54 openhab influxd[1714]: ts=2020-02-07T23:07:54.469920Z lvl=info m
Feb 08 00:08:00 openhab influxd[1714]: [httpd] 127.0.0.1 - openhab [08/Feb/2020:
Feb 08 00:09:00 openhab influxd[1714]: [httpd] 127.0.0.1 - openhab [08/Feb/2020:
Feb 08 00:10:00 openhab influxd[1714]: [httpd] 127.0.0.1 - openhab [08/Feb/2020:
Feb 08 00:11:00 openhab influxd[1714]: [httpd] 127.0.0.1 - openhab [08/Feb/2020:
Feb 08 00:12:00 openhab influxd[1714]: [httpd] 127.0.0.1 - openhab [08/Feb/2020:
lines 1-20/20 (END)
● influxdb.service - InfluxDB is an open-source, distributed, time series database
   Loaded: loaded (/lib/systemd/system/influxdb.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-02-06 22:37:10 CET; 1 day 1h ago
     Docs: https://docs.influxdata.com/influxdb/
 Main PID: 1714 (influxd)
    Tasks: 14 (limit: 2319)
   Memory: 11.8M
   CGroup: /system.slice/influxdb.service
           └─1714 /usr/bin/influxd -config /etc/influxdb/influxdb.conf

Feb 08 00:05:00 openhab influxd[1714]: [httpd] 127.0.0.1 - openhab [08/Feb/2020:00:05:00 +0100] "POST /
Feb 08 00:06:00 openhab influxd[1714]: [httpd] 127.0.0.1 - openhab [08/Feb/2020:00:06:00 +0100] "POST /
Feb 08 00:07:00 openhab influxd[1714]: [httpd] 127.0.0.1 - openhab [08/Feb/2020:00:07:00 +0100] "POST /
Feb 08 00:07:54 openhab influxd[1714]: ts=2020-02-07T23:07:54.469608Z lvl=info msg="Retention policy de
Feb 08 00:07:54 openhab influxd[1714]: ts=2020-02-07T23:07:54.469920Z lvl=info msg="Retention policy de
Feb 08 00:08:00 openhab influxd[1714]: [httpd] 127.0.0.1 - openhab [08/Feb/2020:00:08:00 +0100] "POST /
Feb 08 00:09:00 openhab influxd[1714]: [httpd] 127.0.0.1 - openhab [08/Feb/2020:00:09:00 +0100] "POST /
Feb 08 00:10:00 openhab influxd[1714]: [httpd] 127.0.0.1 - openhab [08/Feb/2020:00:10:00 +0100] "POST /
Feb 08 00:11:00 openhab influxd[1714]: [httpd] 127.0.0.1 - openhab [08/Feb/2020:00:11:00 +0100] "POST /
Feb 08 00:12:00 openhab influxd[1714]: [httpd] 127.0.0.1 - openhab [08/Feb/2020:00:12:00 +0100] "POST /
~
~
~

[00:22:06] root@openhab:/home/openhabian# sudo journalctl -u influxdb
-- Logs begin at Sun 2020-02-02 21:48:39 CET, end at Sat 2020-02-08 00:22:10 CET. --
Feb 02 22:17:37 openhab systemd[1]: Started InfluxDB is an open-source, distributed, time series databa
Feb 02 22:18:07 openhab systemd[1]: Stopping InfluxDB is an open-source, distributed, time series datab
Feb 02 22:18:07 openhab systemd[1]: influxdb.service: Main process exited, code=killed, status=15/TERM
Feb 02 22:18:07 openhab systemd[1]: influxdb.service: Succeeded.
Feb 02 22:18:07 openhab systemd[1]: Stopped InfluxDB is an open-source, distributed, time series databa
Feb 02 22:18:07 openhab systemd[1]: Started InfluxDB is an open-source, distributed, time series databa
Feb 02 22:18:51 openhab influxd[3636]: ts=2020-02-02T21:18:51.980671Z lvl=info msg="InfluxDB starting"
Feb 02 22:18:51 openhab influxd[3636]: ts=2020-02-02T21:18:51.981512Z lvl=info msg="Go runtime" log_id=
Feb 02 22:18:52 openhab influxd[3636]: ts=2020-02-02T21:18:52.096938Z lvl=info msg="Using data dir" log
Feb 02 22:18:52 openhab influxd[3636]: ts=2020-02-02T21:18:52.097703Z lvl=info msg="Compaction settings
Feb 02 22:18:52 openhab influxd[3636]: ts=2020-02-02T21:18:52.097887Z lvl=info msg="Open store (start)"
Feb 02 22:18:52 openhab influxd[3636]: ts=2020-02-02T21:18:52.098266Z lvl=info msg="Open store (end)" l
Feb 02 22:18:52 openhab influxd[3636]: ts=2020-02-02T21:18:52.098634Z lvl=info msg="Opened service" log
Feb 02 22:18:52 openhab influxd[3636]: ts=2020-02-02T21:18:52.098748Z lvl=info msg="Starting monitor se
Feb 02 22:18:52 openhab influxd[3636]: ts=2020-02-02T21:18:52.099030Z lvl=info msg="Registered diagnost
Feb 02 22:18:52 openhab influxd[3636]: ts=2020-02-02T21:18:52.099183Z lvl=info msg="Registered diagnost
Feb 02 22:18:52 openhab influxd[3636]: ts=2020-02-02T21:18:52.099248Z lvl=info msg="Registered diagnost
Feb 02 22:18:52 openhab influxd[3636]: ts=2020-02-02T21:18:52.099331Z lvl=info msg="Registered diagnost
Feb 02 22:18:52 openhab influxd[3636]: ts=2020-02-02T21:18:52.099439Z lvl=info msg="Starting precreatio
Feb 02 22:18:52 openhab influxd[3636]: ts=2020-02-02T21:18:52.099618Z lvl=info msg="Starting snapshot s
Feb 02 22:18:52 openhab influxd[3636]: ts=2020-02-02T21:18:52.100083Z lvl=info msg="Starting continuous
Feb 02 22:18:52 openhab influxd[3636]: ts=2020-02-02T21:18:52.100499Z lvl=info msg="Starting HTTP servi
lines 1-23

So InfluxDB appears to be running. Can you try this as it is what the openhabian script is trying to do and seems to have failed when it ran?

curl --insecure http://localhost:8086/query --data-urlencode "q=CREATE USER admin WITH PASSWORD XXXX WITH ALL PRIVILEGES"

Change the password to something reasonable.

@noppes123 in the 3rd post from the top shows how to do this manually if you run the command line with influx, but openhabian shouldn’t have failed with the above curl command. Let’s see what that does.

looks the result is always my authentification problem which also failed in the official install script

 curl --insecure http://localhost:8086/query --data-urlencode "q=CREATE USER admin WITH PASSWORD @HQ1975&home WITH ALL PRIVILEGES"
{"error":"unable to parse authentication credentials"}

Can you try it with the single quotes around the password?

curl --insecure http://localhost:8086/query --data-urlencode "q=CREATE USER admin WITH PASSWORD '@HQ1975&home' WITH ALL PRIVILEGES"

At least we know that the problem is not connecting with the InfluxDB - it’s running, but for some reason it’s not happy with this particular command. So we need to get it to work. It seems like this is a different error than when it ran in the script, but it’s hard to be sure.

Also, just as a test, try a simpler password. Just regular letters and numbers. I doubt that is an issue, but it is one more thing to try to make the debug easier.

now with a simple password,

[20:30:45] root@openhab:/home/openhabian# curl --insecure http://localhost:8086/                                                                                                             query --data-urlencode "q=CREATE USER admin WITH PASSWORD 'hallo123' WITH AL                                                                                                             L PRIVILEGES"
404 page not found
curl: (6) Could not resolve host: query

again with the right format:

[20:38:42] root@openhab:/home/openhabian# curl --insecure http://localhost:8086/query --data-urlencode "q=CREATE USER admin WITH 'hallo' [REDACTED] WITH ALL PRIVILEGES"
{"error":"unable to parse authentication credentials"}

Is that exactly how you typed it? It seems that the PASSWORD is missing. But maybe the log in this forum changed it? Try adding the -v. I’m beginning to run out of ideas, but maybe that will tell us. Try this:

curl -v --insecure http://localhost:8086/query --data-urlencode "q=CREATE USER admin WITH PASSWORD '123' WITH ALL PRIVILEGES"

Also, make sure that these are the standard quote marks, not the slanted single and double quotes. That can cause trouble - although the script should be correct, so it doesn’t seem to be the root cause.