我正在使用mosquitto auth plugin这是我的mosquitto.config文件

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)

所有postgres设置都是默认的postgres设置。
当我跑的时候
sudo /usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

命令。我得到这个错误:
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.

如果我取消这两行的注释
#listener 9001 127.0.0.1
#protocol websockets

我得到这个错误:
Error: Websockets support not available.
Error found at /etc/mosquitto/mosquitto.conf:4.
Error: Unable to open configuration file.

我在学习这些教程
Tutorial1
Tutorial2
更改postgres密码并更改默认端口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'.

“mosquitto”用户在哪里提交?

最佳答案

将评论中给出的内容作为实际答案:
websockets问题的根源在于没有通过修改以下行在config.mk中启用websockets来构建:
WITH_WEBSOCKETS:=no
然后重建。您需要确保安装了libwebsocket开发文件。
We were unable to connect to the database错误是数据库配置问题
Error: Invalid user 'mosquitto'.是因为您试图以根用户身份运行mosquitto,而mosquitto试图放弃根用户权限,以便在较低级别上安全运行。默认情况下,mosquitto将尝试以名为mosquitto的用户身份运行,在这种情况下,系统上没有定义mosquitto用户,因此出现错误。您可以通过在mosquitto.conf中添加以下内容来更改它将尝试成为的用户
user foo
这将导致mosquito以用户foo的身份运行。你真的不应该让Mosquito作为根来运行。

关于postgresql - mosquitto auth插件数据库问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35577615/

10-12 03:44