mosquitto - Mosquitto 的 Docker-compose 健康检查
问题描述
我使用密码文件设置 mosquitto 密码
volumes:
- /password:/mosquitto/config
如何在 docker-compose 中添加健康检查?我尝试了此处提供的以下解决方案 Script to check mosquitto is healthy
healthcheck:
test: ["CMD-SHELL", "timeout -t 5 mosquitto_sub -t '$$SYS/#' -C 1 | grep -v Error || exit 1"]
interval: 10s
timeout: 10s
retries: 6
此外,我尝试了其他几个选项,但他们要求我传递用户名和密码。我不能使用这个密码文件吗?
更新:mosquitto.conf
allow_anonymous false
password_file /mosquitto/config/pwfile
port 1883
listener 9001
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
解决方案
在推送时,您可以使用 MQTT over Websockets 作为协议启用侦听器,然后使用基本的 curl get 请求来检查代理是否已启动。
例如将其添加到 mosquitto.conf
listener 8080 127.0.0.1
protocol websockets
和健康检查之类的
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080" ]
interval: 10s
timeout: 10s
retries: 6
原始 HTTP GET 请求应该在不需要验证的情况下完成。
另一个选项是重新启用匿名用户并为匿名用户添加只读访问权限以$SYS/#
使用 acl 文件 ( acl_file )访问主题模式
推荐阅读
- android - 如何使用 navigateUp 关闭应用程序
- python - 当网站上的产品被覆盖层隐藏时,如何获取它们的名称?
- scala - 为什么 val 声明不遵循 scala 常量命名约定?
- javascript - 检查是点击或悬停事件 - jQuery
- css - 如何使整个数据表行成为有角度的材质按钮
- knex.js - `knex.js` 播种时违反外键约束
- java - 获取 java.sql.SQLFeatureNotSupportedException:不支持的功能:checkValidIndex 异常
- android - kotlin 全局活动视图引用以在片段中使用
- php - AJAX 如何循环浏览每个文件夹的内容而不重复?
- sql - 使用 while 循环迭代 Sql 的替代方法