Mosquitto:以仅本地模式启动
我有一个虚拟机,它应该是主机,它可以接收和发送数据。第一张图片是我在主机上遇到的错误(我试图从中发送数据)。第二张图是我的虚拟机上的mosquitto日志。另外,我使用的是默认配置,据我所知,它不会导致这些问题,至少从我从其他示例中看到的情况是这样。我对这一切是如何工作的知之甚少,所以非常感谢任何帮助。
我在主机上尝试过的操作:
- 禁用 Windows Defender
- 为“mosquitto.exe”添加防火墙规则
- 在 Linux 计算机上安装 mosquitto
I have a virtual machine that is supposed to be the host, which can receive and send data. The first picture is the error that I'm getting on my main machine (from which I'm trying to send data from). The second picture is the mosquitto log on my virtual machine. Also I'm using the default config, which as far as I know can't cause these problems, at least from what I have seen from other examples. I have very little understanding on how all of this works, so any help is appreciated.
What I have tried on the host machine:
- Disabling Windows defender
- Adding firewall rules for "mosquitto.exe"
- Installing mosquitto on a linux machine
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
从 Mosquitto 2.0.0 版本开始(您正在运行 v2.0.2),默认配置将仅绑定到
localhost
作为转向更安全的默认状态。如果您希望能够从其他计算机访问代理,则需要显式编辑配置文件以添加绑定到外部 IP 地址(或 0.0.0.0)的新
侦听器
,或者添加默认侦听器的bind
条目。默认情况下,它也只允许来自本地主机的匿名连接(没有用户名/密码),以允许远程添加匿名:
更多详细信息可以在 2.0 发行说明中找到 此处
Starting with the release of Mosquitto version 2.0.0 (you are running v2.0.2) the default config will only bind to
localhost
as a move to a more secure default posture.If you want to be able to access the broker from other machines you will need to explicitly edit the config files to either add a new
listener
that binds to the external IP address (or 0.0.0.0) or add abind
entry for the default listener.By default it will also only allow anonymous connections (without username/password) from localhost, to allow anonymous from remote add:
More details can be found in the 2.0 release notes here
您必须使用
mosquitto.conf 运行,该文件存在于与执行文件相同的文件夹中(C:\Program Files\mosquitto 等),必须包含以下行。
You have to run with
mosquitto.conf, which exists in the folder same with execution file exists (C:\Program Files\mosquitto etc.), have to include following line.
默认情况下,Mosquitto 代理仅接受来自本地计算机(托管代理的服务器)上的客户端的连接。
因此,您的 Mosquitto 实例需要使用自定义配置,以便接受来自远程客户端的连接。
这将在端口 1883 上创建侦听器并允许匿名连接。默认情况下,连接数是无限的。使用扩展名为“.conf”的文件名(例如“your_conf_file.conf”)将文件保存到“C:\Program Files\Mosquitto”。
打开终端窗口并导航到 mosquitto 目录。运行以下命令:
其中
-c :指定代理配置文件。
-v :详细模式 - 启用所有日志记录类型。这会覆盖
配置文件中给出的任何日志记录选项。
By default, the Mosquitto broker will only accept connections from clients on the local machine (the server hosting the broker).
Therefore, a custom configuration needs to be used with your instance of Mosquitto in order to accept connections from remote clients.
This creates a listener on port 1883 and allows anonymous connections. By default the number of connections is infinite. Save the file to "C:\Program Files\Mosquitto" using a file name with the ".conf" extension such as "your_conf_file.conf".
Open a terminal window and navigate to the mosquitto directory. Run the following command:
where
-c : specify the broker config file.
-v : verbose mode - enable all logging types. This overrides
any logging options given in the config file.
我发现我不仅必须添加
bind_address ip_address
,而且还必须设置allow_anonymous true
设备才能成功连接到 MQTT。当然,我知道更好的选择是在每个设备上设置用户和密码。但这是一切在最低配置下实际运行之后的下一步。I found I had to add, not only
bind_address ip_address
but also had to setallow_anonymous true
before devices could connect successfully to MQTT. Of course I understand that a better option would be to set user and password on each device. But that's a next step after everything actually works in the minimum configuration.对于那些在 Mac 上使用 mosquitto 和 homebrew 的人。
将这两行添加到
/opt/homebrew/Cellar/mosquitto/2.0.15/etc/mosquitto/mosquitto.conf
解决了我的问题。For those who use mosquitto with homebrew on Mac.
Adding these two lines to
/opt/homebrew/Cellar/mosquitto/2.0.15/etc/mosquitto/mosquitto.conf
fixed my issue.您可以使用包含的“no-auth”配置文件来运行它,如下所示:
我在 docker 容器(使用 docker-compose 生成)内运行它时遇到了同样的问题。
在 docker-compose.yml 文件中,这是通过以下方式完成的:
you can run it with the included 'no-auth' config file like so:
I had the same problem while running it inside docker container (generated with docker-compose).
In docker-compose.yml file this is done with:
当我在本地 ubuntu 机器上使用 mosquitto 代理运行 mqtt 通信时,我遇到了类似的问题。
我通过编辑位于
etc/mosquitto
的 mosquitto 代理配置文件设法解决了通信问题。然后使用 nano 编辑器编辑文件,通过使用命令打开文件
,并在配置文件中添加以下两行
I faced this similar issue when running an mqtt communication on my local ubuntu machine using mosquitto broker locally.
I managed to get around the communication issue by editing the mosquitto broker configuration file located at
etc/mosquitto
.Then edited the file using nano editor by opening the file with the command
and in the configuration file added the following two lines