配置MOSQUITO MQTT代理以侦听多个端口
我在Win7 PC上安装了mosquitto,希望它可以在多个端口上侦听,因此我根据mosquitto文档和web上的一些教程/示例修改了mosquitto.conf。以下是我在mosquitto.conf上所做的修改:配置MOSQUITO MQTT代理以侦听多个端口,mqtt,mosquitto,Mqtt,Mosquitto,我在Win7 PC上安装了mosquitto,希望它可以在多个端口上侦听,因此我根据mosquitto文档和web上的一些教程/示例修改了mosquitto.conf。以下是我在mosquitto.conf上所做的修改: # Plain MQTT protocol listener 1883 # MQTT over TLS/SSL listener 8883 protocol mqtt require_certificate false
# Plain MQTT protocol
listener 1883
# MQTT over TLS/SSL
listener 8883
protocol mqtt
require_certificate false
# MQTT over TLS/SSL with certificates
listener 8884
protocol mqtt
require_certificate true
certfile cert.pem
cafile chain.pem
keyfile privkey.pem
# Plain WebSockets configuration
listener 9001
protocol websockets
# WebSockets over TLS/SSL
listener 9883
protocol websockets
require_certificate true
cafile mosquitto/ca.crt
certfile mosquitto/hostname.crt
keyfile mosquitto/hostname.key
# Log system configuration
log_type all
#log_dest file C:/Dati/mosquitto/mosquitto.log
log_facility 5
log_type error
log_type warning
log_type notice
log_type information
不幸的是,这些修改不再有效。
所以,我需要学习一个工作示例来理解什么是对的,什么是错的。
我的目标是让MOSQUITO在1883端口(无加密的普通MQTT)8883(通过TLS 1.2但不使用证书)8884(使用证书的TLS 1.2)9001(普通WebSocket)和最后9883(需要证书的web套接字)上侦听
我怀疑证书有问题,但我遵循了test.mosquito.org报告中的指示:
服务器侦听以下端口:
- 1883年:MQTT,未加密
- 8883:MQTT,加密
- 8884:MQTT,加密,需要客户端证书
- 8080:WebSocket上的MQTT,未加密
- 8081:WebSocket上的MQTT,加密
mosquitto -c mosquitto.conf -v
这是在端口8883上测试MOSQUITO的测试命令及其结果:
mosquitto_pub --cafile C:\Dati\mosquitto\ca.crt -h 192.168.1.2 -t "test" -m "message" -p 8883
Error: Unknown error.
这是在端口1883上测试MOSQUITO的测试命令(日志文件的最后几行):
这是日志文件:
mosquitto_pub -h 192.168.1.2 -t "test" -m "message" -p 1883
1559207712: mosquitto version 1.5.8 starting
1559207712: Config loaded from mosquitto.conf.
1559207712: Opening ipv6 listen socket on port 8883.
1559207712: Opening ipv4 listen socket on port 8883.
1559207712: Opening ipv6 listen socket on port 1883.
1559207712: Opening ipv4 listen socket on port 1883.
1559207731: New connection from 192.168.1.2 on port 8883.
1559207731: Socket error on client <unknown>, disconnecting.
1559207789: New connection from 192.168.1.2 on port 1883.
1559207789: New client connected from 192.168.1.2 as MQTT_FX_Client (c1, k60).
1559207789: No will message specified.
1559207789: Sending CONNACK to MQTT_FX_Client (0, 0)
1559207808: Received DISCONNECT from MQTT_FX_Client
1559207808: Client MQTT_FX_Client disconnected.
1559207902: New connection from 192.168.1.2 on port 8883.
1559207902: Socket error on client <unknown>, disconnecting.
1559207902: New connection from 192.168.1.2 on port 8883.
1559207902: Socket error on client <unknown>, disconnecting.
1559207949: New connection from 192.168.1.2 on port 8883.
1559207949: Socket error on client <unknown>, disconnecting.
1559207949: New connection from 192.168.1.2 on port 8883.
1559207949: Socket error on client <unknown>, disconnecting.
1559207956: New connection from 192.168.1.2 on port 8883.
1559207956: Socket error on client <unknown>, disconnecting.
1559207956: New connection from 192.168.1.2 on port 8883.
1559207956: Socket error on client <unknown>, disconnecting.
1559207994: New connection from 192.168.1.2 on port 8883.
1559207994: Socket error on client <unknown>, disconnecting.
1559208345: New connection from 192.168.1.2 on port 1883.
1559208345: New client connected from 192.168.1.2 as mosqpub|7544-NOTEBOOK (c1, k60).
1559208345: No will message specified.
1559208345: Sending CONNACK to mosqpub|7544-NOTEBOOK (0, 0)
1559208345: Received PUBLISH from mosqpub|7544-NOTEBOOK (d0, q0, r0, m0, 'test', ... (7 bytes))
1559208345: Received DISCONNECT from mosqpub|7544-NOTEBOOK
1559208345: Client mosqpub|7544-NOTEBOOK disconnected.
实际上,我在非标准端口上启动了两个新侦听器,以确保只有mosquitto.conf上的配置会影响它们,因此没有太多幻想…1883->1893和8883->8893
然后,现在在不使用SSL的情况下执行mosquitto_pub,结果如下(右):
这是在端口8893上使用SSL执行mosquitto_pub的(错误)结果:
mosquitto_pub --cafile C:\Dati\mosquitto\ca.crt -h 192.168.1.2 -i "MQTT_FX_Client" -t "test" -m "message" -p 8893 -d
Client MQTT_FX_Client sending CONNECT
OpenSSL Error: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
Error: A TLS error occurred.
但是使用MQTT.fx可以使用以下参数:
配置文件类型:MQTT代理
经纪人地址:192.168.1.2
代理端口:8893
客户ID§:MQTT_FX_客户
启用SSL/TLS:是
协议TLSv1.2
CA证书文件:C:\Dati\MOSQUITO\CA.crt
一切都按照日志中的报告工作:
1559231176: New connection from 192.168.1.2 on port 8893.
1559231177: New client connected from 192.168.1.2 as MQTT_FX_Client (c1, k60).
1559231177: No will message specified.
1559231177: Sending CONNACK to MQTT_FX_Client (0, 0)
在我看来,MQTT.fx和mosquitto_pub参数是相同的,但是……无论如何都出了问题,那么……还有什么
谢谢,
Massimo编辑问题,以便在启动MOSQUITO时包含日志输出,以便我们可以看到错误消息。此外,您需要为要使用TLS的所有侦听器指定证书/密钥对(没有代理证书的TLS是不存在的,例如端口8883)。此外,您可能应该使用这些文件的完整路径。我怀疑证书有问题,但我遵循了报告中的指示:服务器侦听以下端口:1883:MQTT、未加密的8883:MQTT、加密的8884:MQTT、加密的、需要客户端证书的WebSocket上的8080:MQTT,未加密8081:WebSockets上的MQTT,已加密,因此似乎不需要证书连接到端口8883客户端证书需要或不需要是连接到代理的客户端使用证书来标识自身的一种方式,而不是用户名和密码。它与蚊子本身。您仍然需要端口8883的蚊子证书-服务器在使用TLS时总是需要证书。@hardlib要求您包括日志内容;这应该可以说明出了什么问题。关于日志:似乎Windows上的Mosquetto不起作用,唯一可能的日志是系统日志如果MOSQUITO是作为一项服务启动的。那么,我最初尝试创建一个文件日志,正如您在我的原始帖子中看到的,但它不起作用,或者至少它不写任何东西。然后我尝试使用syslog,但在这种情况下,它不会产生任何输出(它使用可通过系统管理员应用程序访问的windows系统日志)。我很乐意阅读日志…我添加了服务器证书,但我的客户端在端口8883 ans上没有连接。我在windows系统日志上仍然没有看到任何内容。可能还缺少什么?
mosquitto_pub --cafile C:\Dati\mosquitto\ca.crt -h 192.168.1.2 -i "MQTT_FX_Client" -t "test" -m "message" -p 8893 -d
Client MQTT_FX_Client sending CONNECT
OpenSSL Error: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
Error: A TLS error occurred.
1559231176: New connection from 192.168.1.2 on port 8893.
1559231177: New client connected from 192.168.1.2 as MQTT_FX_Client (c1, k60).
1559231177: No will message specified.
1559231177: Sending CONNACK to MQTT_FX_Client (0, 0)