简体   繁体   中英

mosquitto auth plugin database issue

I am using mosquitto auth plugin here is my mosquitto.config file

listener 1883

#listener 9001 127.0.0.1
#protocol websockets

auth_opt_backends postgres
auth_plugin /etc/mosquitto/auth-plug.so
auth_opt_dbname mqtt
auth_opt_host localhost
auth_opt_port 5432
auth_opt_user postgres
auth_opt_pass postgres
auth_opt_userquery SELECT password FROM account WHERE username = $1 limit 1
auth_opt_superquery SELECT COALESCE(COUNT(*),0) FROM account WHERE username = $1 AND super = 1
auth_opt_aclquery SELECT topic FROM acls WHERE (username = $1) AND (rw >= $2)

all postgres setting are default postgres settings. when I run

sudo /usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

command. I am getting this error:

1456228482: mosquitto version 1.4.8 (build date 2016-02-22 18:23:09+0530) starting
1456228482: Config loaded from /etc/mosquitto/mosquitto.conf.
1456228482: |-- *** auth-plug: startup
1456228482: |-- ** Configured order: postgres

1456228482: |-- }}}} POSTGRES
1456228482: |-- HERE: SELECT COALESCE(COUNT(*),0) FROM account WHERE username = $1 AND super = 1
1456228482: |-- HERE: SELECT topic FROM acls WHERE (username = $1) AND (rw >= $2)
|-- We were unable to connect to the database
|-- *** ABORT.

If I uncomment these two line

#listener 9001 127.0.0.1
#protocol websockets

i get this error:

Error: Websockets support not available.
Error found at /etc/mosquitto/mosquitto.conf:4.
Error: Unable to open configuration file.

I was following these tutorial

Tutorial1 Tutorial2

after changing password of postgres and chaging the default port 1883

1456232627: mosquitto version 1.4.8 (build date 2016-02-22 18:23:09+0530) starting
1456232627: Config loaded from /etc/mosquitto/mosquitto.conf.
1456232627: |-- *** auth-plug: startup
1456232627: |-- ** Configured order: postgres

1456232627: |-- }}}} POSTGRES
1456232627: |-- HERE: SELECT COALESCE(COUNT(*),0) FROM account WHERE username = $1 AND super = 1
1456232627: |-- HERE: SELECT topic FROM acls WHERE (username = $1) AND (rw >= $2)
1456232627: Opening ipv4 listen socket on port 1884.
1456232627: Opening ipv6 listen socket on port 1884.
1456232627: Error: Invalid user 'mosquitto'.

from where "mosquitto" user is comming ?

Taking the what has been given in the comment to form an actual answer:

  1. The websockets problem is down to not building with Websockets enabled in config.mk by modifying the following line:

    WITH_WEBSOCKETS:=no

    And then rebuilding. You will need to ensure you have the libwebsocket development files installed.

  2. The We were unable to connect to the database error was a database configuration issue

  3. Error: Invalid user 'mosquitto'. is because you are trying to run mosquitto as root and mosquitto is trying to drop the root privileges in order to safely run at a lower level. By default mosquitto will try to run as a user called mosquitto , in this case there is no mosquitto user defined on the system hence the error. You can change the user that it will try and become by adding a the following to the mosquitto.conf

    user foo

    This would cause mosquitto to run as user foo . You really should not leave mosquitto running as root.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM