mosquitto服务器修改监听端口号,解决Mosquitto创建MQTT服务器提示Starting in local only mode...

原标题:解决Mosquitto创建MQTT服务器提示Starting in local only mode

一、问题现象

使用新下载的Mosquitto创建MQTT服务器提示Starting in local only mode. Connections will only be possible from clients running on this machine.测试发现服务器只能接入本机的客户端,而其他设备上的客户端在连接时直接被重置了。

二、原因分析

随后查阅了一下Mosquitto的更新记录,原来在其2.0.0大版本更新后如果不加载配件文件则使用回环接口(仅可用于本地Socket通信)。

Breaking changes

· When the Mosquitto broker is run without configuring any listeners it will now bind to the loopback interfaces 127.0.0.1 and/or ::1. This means that only connections from the local host will be possible.

· Running the broker as mosquitto or mosquitto -p 1883 will bind to the loopback interface.

· Running the broker with a configuration file with no listeners configured will bind to the loopback interface with port 1883.

· Running the broker with a listener defined will bind by default to 0.0.0.0 / :: and so will be accessible from any interface. It is still possible to bind to a specific address/interface.

附Mosquitto更新记录: https://mosquitto.org/blog/2020/12/version-2-0-0-released

三、解决方法

先修改软件安装目录中的配置文件mosquitto.conf然后加载配置文件来启动服务器。

配置端口号,编辑mosquitto.conf,搜索listener去掉行首的#并加上端口号,示例端口为1883

# On systems that support Unix Domain Sockets, it is also possible

# to create a # Unix socket rather than opening a TCP socket. In

# this case, the port number should be set to 0 and a unix socket

# path must be provided, e.g.

# listener 0 /tmp/mosquitto.sock

#

# listener port-number [ip address/host name/unix socket path]

listener 1883

启用匿名访问,若不允许匿名访问则只有添加客户端鉴权信息才能接入。为简化测试我们启用匿名访问:将mosquitto.conf里的allow_anonymous选项改为true并保存

# Boolean value that determines whether clients that connect

# without providing a username are allowed to connect. If set to

# false then a password file should be created (see the

# password_file option) to control authenticated client access.

#

# Defaults to false, unless there are no listeners defined in the configuration

# file, in which case it is set to true, but connections are only allowed from

# the local machine.

allow_anonymous true

加载配置文件启动服务器测试,执行命令mosquitto.exe -c mosquitto.conf -v,此时LOG上已经没了Starting in local only mode且非本地客户端可以正常接入了

c565fce83643a5fd6e6593e05ff47982.png文章版权归优易通物联网所有,转载请注明出处返回搜狐,查看更多

责任编辑:

MQTT.fx是一个用于调试和测试MQTT协议的工具,可以用来连接和交互Mosquitto搭建的MQTT服务。下面是使用MQTT.fx调试Mosquitto的步骤: 1. 下载和安装MQTT.fx:首先,你需要从MQTT.fx官方网站下载并安装MQTT.fx工具。 2. 打开MQTT.fx:安装完成后,打开MQTT.fx应用程序。 3. 配置连接参数:在MQTT.fx的主界面上,点击左上角的"新增连接"按钮,弹出连接配置窗口。 4. 配置连接参数:在连接配置窗口中,填写以下参数: - Connection Name: 连接名称,可以自定义。 - Broker Address: Mosquitto服务器的地址,可以是IP地址或域名。 - Port: Mosquitto服务器的端口,默认为1883。 - Client ID: 客户端ID,可以自定义。 - Username: 如果Mosquitto服务器需要用户名认证,填写对应的用户名。 - Password: 如果Mosquitto服务器需要密码认证,填写对应的密码。 5. 连接到Mosquitto服务器:填写完连接参数后,点击"连接"按钮,连接到Mosquitto服务器。 6. 订阅主题:在MQTT.fx的主界面上,点击左下角的"新增订阅"按钮,弹出订阅配置窗口。 7. 配置订阅参数:在订阅配置窗口中,填写以下参数: - Topic: 要订阅的主题名称。 - QoS: 消息的服务质量等级,默认为0。 8. 订阅主题:填写完订阅参数后,点击"订阅"按钮,开始订阅指定主题。 9. 发布消息:在MQTT.fx的主界面上,点击右下角的"新增发布"按钮,弹出发布配置窗口。 10. 配置发布参数:在发布配置窗口中,填写以下参数: - Topic: 要发布消息的主题名称。 - QoS: 消息的服务质量等级,默认为0。 - Message: 要发布的消息内容。 11. 发布消息:填写完发布参数后,点击"发布"按钮,将消息发布到指定主题。 12. 查看消息:在MQTT.fx的主界面上,可以看到已经订阅的主题和接收到的消息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值