
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
本镜像为集成了mosquitto-go-auth插件的Mosquitto MQTT broker。mosquitto-go-auth是一个用Go语言编写的认证与授权插件,通过cgo与Mosquitto交互,支持多种后端存储,为MQTT broker提供用户认证、超级用户检查和访问控制列表(ACL)验证功能。插件兼容Mosquitto 2.0及以上版本,适用于需要灵活认证授权机制的MQTT部署场景。
插件实现了以下后端,每个后端均支持用户认证、超级用户检查和ACL验证,并包含完整测试:
prefix_username),指定特定后端处理认证请求镜像启动需挂载Mosquitto配置文件(通常为mosquitto.conf),并在配置中指定插件路径及后端。示例配置片段:
conf# 加载插件 auth_plugin /etc/mosquitto/go-auth.so # 启用的后端(按优先级排序) auth_opt_backends files,postgres,jwt # 通用缓存配置 auth_opt_cache true auth_opt_cache_type redis auth_opt_auth_cache_seconds 30 auth_opt_acl_cache_seconds 30 # 哈希算法配置(全局) auth_opt_hasher bcrypt auth_opt_hasher_cost 10
缓存配置
| 选项 | 说明 | 默认值 |
|---|---|---|
auth_opt_cache | 是否启用缓存 | false |
auth_opt_cache_type | 缓存类型(go-cache/redis) | go-cache |
auth_opt_auth_cache_seconds | 认证缓存过期时间(秒) | - |
auth_opt_acl_cache_seconds | ACL缓存过期时间(秒) | - |
auth_opt_cache_refresh | 缓存命中时刷新过期时间 | false |
auth_opt_cache_reset | 启动时重置缓存 | false |
哈希配置
支持PBKDF2、Bcrypt、Argon2ID,以Bcrypt为例:
confauth_opt_hasher bcrypt auth_opt_hasher_cost 12 # 计算强度(4-31)
日志配置
confauth_opt_log_level info # 日志级别:debug/info/warn/error/fatal/panic auth_opt_log_dest file # 输出目标:stderr/stdout/file auth_opt_log_file /var/log/mosquitto/auth.log # 文件路径(仅file模式)
Files后端
通过静态文件实现认证与授权:
confauth_opt_files_password_path /etc/mosquitto/passwords.txt # 密码文件路径 auth_opt_files_acl_path /etc/mosquitto/acls.txt # ACL文件路径
密码文件格式(PBKDF2哈希示例):
user1:PBKDF2$sha512$100000$salt$hash user2:PBKDF2$sha512$100000$salt$hash
ACL文件格式(遵循Mosquitto语法):
user user1 topic write sensor/temp topic read sensor/humidity user user2 topic read sensor/#
PostgreSQL后端
通过数据库查询实现认证:
confauth_opt_pg_host postgres auth_opt_pg_port 5432 auth_opt_pg_user dbuser auth_opt_pg_password dbpass auth_opt_pg_dbname mqtt_auth auth_opt_pg_userquery "SELECT password FROM users WHERE username = $1" # 用户查询 auth_opt_pg_aclquery "SELECT topic FROM acls WHERE username = $1 AND access = $2" # ACL查询
单容器部署
bashdocker run -d \ --name mosquitto-go-auth \ -p 1883:1883 \ # MQTT端口 -v $(pwd)/mosquitto.conf:/etc/mosquitto/mosquitto.conf \ -v $(pwd)/passwords.txt:/etc/mosquitto/passwords.txt \ -v $(pwd)/acls.txt:/etc/mosquitto/acls.txt \ eclipse-mosquitto:2.0 # 假设基础镜像为eclipse-mosquitto:2.0,需预安装插件
Docker Compose(含PostgreSQL后端)
yamlversion: '3' services: mosquitto: image: docker.xuanyuan.run/eclipse-mosquitto:2.0 ports: - "1883:1883" volumes: - ./mosquitto.conf:/etc/mosquitto/mosquitto.conf depends_on: - postgres environment: - AUTH_PLUGIN_PATH=/etc/mosquitto/go-auth.so postgres: image: docker.xuanyuan.run/postgres:13 environment: - POSTGRES_USER=dbuser - POSTGRES_PASSWORD=dbpass - POSTGRES_DB=mqtt_auth volumes: - postgres_data:/var/lib/postgresql/data volumes: postgres_data:
debug日志级别会泄露敏感信息(如密码、哈希),生产环境必须使用info及以上级别。cache_refresh可能导致权限撤销延迟,建议结合cache_seconds合理设置过期时间。auth_opt_backends配置顺序依次检查,首个通过验证的后端生效。插件遵循MIT许可证,Mosquitto遵循EPL/EDL许可证。详细信息参见https://github.com/iegomez/mosquitto-go-auth%E3%80%82
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务