Mosquitto:以仅本地模式启动

发布于 2025-01-13 15:51:58 字数 485 浏览 2 评论 0原文

我有一个虚拟机,它应该是主机,它可以接收和发送数据。第一张图片是我在主机上遇到的错误(我试图从中发送数据)。第二张图是我的虚拟机上的mosquitto日志。另外,我使用的是默认配置,据我所知,它不会导致这些问题,至少从我从其他示例中看到的情况是这样。我对这一切是如何工作的知之甚少,所以非常感谢任何帮助。

我在主机上尝试过的操作:

  1. 禁用 Windows Defender
  2. 为“mosquitto.exe”添加防火墙规则
  3. 在 Linux 计算机上安装 mosquitto

First错误

第二个错误

Netstat 信息

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:

  1. Disabling Windows defender
  2. Adding firewall rules for "mosquitto.exe"
  3. Installing mosquitto on a linux machine

First error

Second error

Netstat info

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

悲凉≈ 2025-01-20 15:51:58

从 Mosquitto 2.0.0 版本开始(您正在运行 v2.0.2),默认配置将仅绑定到 localhost 作为转向更安全的默认状态。

如果您希望能够从其他计算机访问代理,则需要显式编辑配置文件以添加绑定到外部 IP 地址(或 0.0.0.0)的新侦听器,或者添加默认侦听器的 bind 条目。

默认情况下,它也只允许来自本地主机的匿名连接(没有用户名/密码),以允许远程添加匿名:

allow_anonymous true
listener 1883

更多详细信息可以在 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 a bind 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:

allow_anonymous true
listener 1883

More details can be found in the 2.0 release notes here

尐籹人 2025-01-20 15:51:58

您必须使用

mosquitto -c mosquitto.conf

mosquitto.conf 运行,该文件存在于与执行文件相同的文件夹中(C:\Program Files\mosquitto 等),必须包含以下行。

listener 1883 ip_address_of_the_machine(192.168.1.1 etc.)

You have to run with

mosquitto -c mosquitto.conf

mosquitto.conf, which exists in the folder same with execution file exists (C:\Program Files\mosquitto etc.), have to include following line.

listener 1883 ip_address_of_the_machine(192.168.1.1 etc.)
久而酒知 2025-01-20 15:51:58

默认情况下,Mosquitto 代理仅接受来自本地计算机(托管代理的服务器)上的客户端的连接。
因此,您的 Mosquitto 实例需要使用自定义配置,以便接受来自远程客户端的连接。

  1. 在 Windows 计算机上,以管理员身份运行文本编辑器并粘贴以下文本:
listener 1883
allow_anonymous true
  1. 这将在端口 1883 上创建侦听器并允许匿名连接。默认情况下,连接数是无限的。使用扩展名为“.conf”的文件名(例如“your_conf_file.conf”)将文件保存到“C:\Program Files\Mosquitto”。

  2. 打开终端窗口并导航到 mosquitto 目录。运行以下命令:

mosquitto -v -c your_conf_file.conf

其中

-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.

  1. On your Windows machine, run a text editor as administrator and paste the following text:
listener 1883
allow_anonymous true
  1. 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".

  2. Open a terminal window and navigate to the mosquitto directory. Run the following command:

mosquitto -v -c your_conf_file.conf

where

-c : specify the broker config file.

-v : verbose mode - enable all logging types. This overrides
any logging options given in the config file.

怪我入戏太深 2025-01-20 15:51:58

我发现我不仅必须添加 bind_address ip_address,而且还必须设置 allow_anonymous true 设备才能成功连接到 MQTT。当然,我知道更好的选择是在每个设备上设置用户和密码。但这是一切在最低配置下实际运行之后的下一步。

I found I had to add, not only bind_address ip_address but also had to set allow_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.

梦旅人picnic 2025-01-20 15:51:58

对于那些在 Mac 上使用 mosquitto 和 homebrew 的人。


将这两行添加到 /opt/homebrew/Cellar/mosquitto/2.0.15/etc/mosquitto/mosquitto.conf 解决了我的问题。

allow_anonymous true 
listener 1883

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.

allow_anonymous true 
listener 1883
不甘平庸 2025-01-20 15:51:58

您可以使用包含的“no-auth”配置文件来运行它,如下所示:

mosquitto -c /mosquitto-no-auth.conf 

我在 docker 容器(使用 docker-compose 生成)内运行它时遇到了同样的问题。
在 docker-compose.yml 文件中,这是通过以下方式完成的:

command: mosquitto -c /mosquitto-no-auth.conf 

you can run it with the included 'no-auth' config file like so:

mosquitto -c /mosquitto-no-auth.conf 

I had the same problem while running it inside docker container (generated with docker-compose).
In docker-compose.yml file this is done with:

command: mosquitto -c /mosquitto-no-auth.conf 
dawn曙光 2025-01-20 15:51:58

当我在本地 ubuntu 机器上使用 mosquitto 代理运行 mqtt 通信时,我遇到了类似的问题。
我通过编辑位于 etc/mosquitto 的 mosquitto 代理配置文件设法解决了通信问题。
然后使用 nano 编辑器编辑文件,通过使用命令打开文件

sudo nano mosquitto.conf 

,并在配置文件中添加以下两行

allow_anonymous true 
listener 1883

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

sudo nano mosquitto.conf 

and in the configuration file added the following two lines

allow_anonymous true 
listener 1883
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文