首页 > 解决方案 > mosquitto.db 文件未创建

问题描述

在测试 mosquitto Persistence 的过程中,我已从 Persistence 位置删除 mosquitto.db 以启用新的开始。但是,令我懊恼的是,即使在我重新启动代理后,该文件也不会创建。

经纪人根据配置创建 .db 文件是不是我弄错了?任何有关如何获取新 mosquitto.db 文件的指针将不胜感激。

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /var/run/mosquitto.pid
max_inflight_messages 1

persistence true
persistence_file mosquitto.db
persistence_location /var/lib/mosquitto/

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

include_dir /etc/mosquitto/conf.d

password_file /etc/mosquitto/passwd
allow_anonymous false
max_queued_messages 1000000

autosave_interval 30
# autosave_on_changes false

标签: persistencemqttmosquitto

解决方案


如果您在代理运行时删除文件,它可能不会重新创建,因为代理已经拥有一个打开的文件句柄。

在进程打开文件时删除文件实际上并不会删除文件,只是它在目录中的条目,进程将继续读/写文件,直到句柄关闭。

如果您在删除文件后重新启动 mosquitto,它不会写入文件,直到它实际上有一些数据要写入它,例如

  • 有一个订阅的客户端(在 QOS 1 或 2)
  • 发送一些消息
  • 断开订阅者
  • 发送更多消息
  • 关闭蚊子

现在应该写入包含在客户端断开连接时发布的消息的文件。


推荐阅读