我正在使用 mosquitto-go-auth 插件在 mosquitto 代理中进行身份验证。
我已经通过以下链接设置了插件
https://github.com/iegomez/mosquitto-go-auth
https://www.chirpstack.io/project/guides/mqtt-authentication/#build-for-mosquitto-14x
这是我的 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
当我重启我的代理时。我在日志文件中看到了这个。
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.
如果我删除该插件,那么代理就可以正常工作。但是如果我添加身份验证插件,它就会失败。
Hardillb 我已经更新了我的 mosquitto.conf 文件
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
但在日志中我得到了相同的信息,即未启用加密,但这次代理运行正常,没有任何问题。但当我检查 mosquitto 状态时,我得到了 postgres 错误。即使所有配置设置都输入正确。
● 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 ```