You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mosquitto使用mosquitto-go-auth插件遇扩展认证未启用及PostgreSQL连接问题

问题:Mosquitto使用mosquitto-go-auth插件认证遇到的启动及PostgreSQL连接问题

背景

我在Mosquitto Broker中使用mosquitto-go-auth插件实现认证功能,已完成插件的基础配置。

初始配置与启动失败

初始mosquitto.conf配置内容如下:

per_listener_settings false 
listener 1883 
protocol mqtt
auth_plugin /home/user/mosquitto-go-auth/go-auth.so
allow_anonymous false 
persistence true 
persistence_location /var/lib/mosquitto/ 
log_dest file /var/log/mosquitto/mosquitto.log

重启Broker后,日志重复输出以下内容,且Broker启动失败:

1731240636:  ├── TLS-PSK checking enabled.
1731240636:  └── Extended authentication not enabled.
1731240636: mosquitto version 2.0.15 starting
1731240636: Config loaded from /etc/mosquitto/mosquitto.conf.
1731240636: Loading plugin: /home/user/mosquitto-go-auth/go-auth.so
1731240636:  ├── Username/password checking enabled.
1731240636:  ├── TLS-PSK checking enabled.
1731240636:  └── Extended authentication not enabled.
1731240637: mosquitto version 2.0.15 starting
1731240637: Config loaded from /etc/mosquitto/mosquitto.conf.
1731240637: Loading plugin: /home/user/mosquitto-go-auth/go-auth.so
1731240637:  ├── Username/password checking enabled.
1731240637:  ├── TLS-PSK checking enabled.
1731240637:  └── Extended authentication not enabled.
1731240637: mosquitto version 2.0.15 starting
1731240637: Config loaded from /etc/mosquitto/mosquitto.conf.
1731240637: Loading plugin: /home/user/mosquitto-go-auth/go-auth.so
1731240637:  ├── Username/password checking enabled.
1731240637:  ├── TLS-PSK checking enabled.
1731240637:  └── Extended authentication not enabled.

移除该认证插件后,Broker可正常运行。

更新配置后的异常情况

更新mosquitto.conf配置,添加PostgreSQL相关认证参数:

allow_anonymous false
per_listener_settings false

listener 1883
protocol mqtt


auth_plugin /home/user/mosquitto-go-auth/go-auth.so
auth_opt_backends postgres
auth_opt_pg_host 172.25.34.117
auth_opt_pg_port 5432
auth_opt_pg_dbname go_auth
auth_opt_pg_user postgres
auth_opt_pg_password postgres
auth_opt_pg_userquery  SELECT password FROM users WHERE name = ? LIMIT 1
auth_opt_hasher bcrypt
auth_opt_hasher_cost 10
auth_opt_cache true
auth_opt_cache_reset true
#auth_opt_auth_cache_seconds 30
#auth_opt_acl_cache_seconds 90
#auth_opt_auth_jitter_second 3
#auth_opt_acl_jitter_seconds 5
#auth_opt_http_host auth.backend.com
#auth_opt_http_port 80


persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

此时Broker可正常启动,但日志仍显示Extended authentication not enabled,且查看服务状态时出现PostgreSQL连接错误(所有数据库配置信息均已正确输入):

user@DESKTOP-J9NGCNR:/etc/mosquitto$ sudo systemctl status mosquitto
● mosquitto.service - Mosquitto MQTT v3.1/v5 server
     Loaded: loaded (/etc/systemd/system/mosquitto.service; enabled; preset: enabled)
     Active: active (running) since Mon 2024-11-11 04:58:51 UTC; 1s ago
       Docs: http://mosquitto.org/documentation/
   Main PID: 10909 (mosquitto)
      Tasks: 7 (limit: 9337)
     Memory: 13.8M ()
     CGroup: /system.slice/mosquitto.service
             └─10909 /usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Nov 11 04:58:51 DESKTOP-J9NGCNR systemd[1]: Started mosquitto.service - Mosquitto MQTT v3.1/v5 server.
Nov 11 04:58:51 DESKTOP-J9NGCNR Mosquitto[10909]: time="2024-11-11T04:58:51Z" level=error msg="ping database postgres error, will re 

内容的提问来源于stack exchange,提问作者user28052177

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 08:40:18