mosquitto auth插件数据库问题

时间:2016-02-23 12:28:48

标签: postgresql mqtt mosquitto

我正在使用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"用户来了吗?

1 个答案:

答案 0 :(得分:2)

将评论中给出的内容形成一个实际答案:

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

    WITH_WEBSOCKETS:=no

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

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

  3. Error: Invalid user 'mosquitto'.是因为你试图以root身份运行mosquitto,而mosquitto试图放弃root权限以便安全地运行在较低级别。默认情况下,mosquitto将尝试以名为 mosquitto 的用户身份运行,在这种情况下,系统上没有定义mosquitto用户因此错误。您可以通过在mosquitto.conf中添加以下内容来更改将尝试使用的用户

    user foo

    这会导致mosquitto以用户 foo 运行。你真的不应该让mosquitto以root身份运行。