mosquitto auth 插件数据库问题

mosquitto auth plugin database issue

我正在使用 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 =  limit 1
auth_opt_superquery SELECT COALESCE(COUNT(*),0) FROM account WHERE username =  AND super = 1
auth_opt_aclquery SELECT topic FROM acls WHERE (username = ) AND (rw >= )

所有 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 =  AND super = 1
1456228482: |-- HERE: SELECT topic FROM acls WHERE (username = ) AND (rw >= )
|-- 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 =  AND super = 1
1456232627: |-- HERE: SELECT topic FROM acls WHERE (username = ) AND (rw >= )
1456232627: Opening ipv4 listen socket on port 1884.
1456232627: Opening ipv6 listen socket on port 1884.
1456232627: Error: Invalid user 'mosquitto'.

"mosquitto" 用户来自哪里?

根据评论中给出的内容形成实际答案:

  1. websockets 问题归结为未通过修改以下行在 config.mk 中启用 Websockets 进行构建:

    WITH_WEBSOCKETS:=no

    然后重建。您需要确保安装了 libwebsocket 开发文件。

  2. We were unable to connect to the database 错误是数据库配置问题

  3. Error: Invalid user 'mosquitto'. 是因为您正在尝试 运行 mosquitto 作为 root 而 mosquitto 正试图放弃 root 权限以便安全地 运行等级。默认情况下,mosquitto 将尝试 运行 作为名为 mosquitto 的用户,在这种情况下,系统上没有定义 mosquitto 用户,因此会出现错误。您可以通过将以下内容添加到 mosquitto.conf

    来更改它将尝试成为的用户

    user foo

    这会导致 mosquitto 运行 作为用户 foo。你真的不应该让 mosquitto 运行ning 成为 root。