使用 SSL 设置 Mosquitto

物联网 蚊子
2021-06-14 05:03:36

我正在尝试在我的 Raspberry Pi 3 上使用 SSL 设置 Mosquitto。我遵循了本教程

现在我的 mosquitto.conf 是:

listener 8883
cafile /etc/mosquitto/certs/mosq-ca.crt
certfile /etc/mosquitto/certs/mosq-serv.crt
keyfile /etc/mosquitto/certs/mosq-serv.key

但是当我运行推荐时:

mosquitto_sub -t "#" -v --cafile /etc/mosquitto/certs/mosq-ca.crt -p 8883

我得到:

Error: connection refused

我已经删除了/etc/mosquitto/conf.d/mosquitto.conf该文件现在是空的。现在默认的 mosquitto.conf 是:

pid_file /var/run/mosquitto.pid 
persistence true persistence_location /var/lib/mosquitto/ 
log_dest file /var/log/mosquitto/mosquitto.log 
include_dir /etc/mosquitto/conf.d 
listener 8883 
cafile /etc/mosquitto/certs/mosq-ca.crt 
certfile /etc/mosquitto/certs/mosq-serv.crt 
keyfile /etc/mosquitto/certs/mosq-serv.key 

但我还是收到

Error: connection refused

我做错了什么或我忘记做什么?

当我使用时(我不会监听端口 8883)sudo mosquitto -v

1514921332: mosquitto version 1.4.10 (build date Mon, 29 May 2017 13:43:29 +0100) starting
1514921332: Using default config.
1514921332: Opening ipv4 listen socket on port 1883.
1514921332: Opening ipv6 listen socket on port 1883.

我的/var/log/mosquitto/mosquitto.log日志:

 1514932164: Config loaded from /etc/mosquitto/mosquitto.conf.
    1514932164: Opening ipv4 listen socket on port 8883.
    1514932164: Opening ipv6 listen socket on port 8883.
    1514932373: Error in poll: Interrupted system call.
    1514932373: mosquitto version 1.4.10 terminating
    1514932378: mosquitto version 1.4.10 (build date Mon, 29 May 2017 13:43:29 +010$

错误已经感谢: Error: A TLS error occurred.

2个回答

正如评论中所建议的(现在由日志输出验证),您的mosquitto.conf文件没有被使用。

您需要在使用-c命令行参数启动代理时指定配置文件

mosquitto -c /etc/mosquitto/mosquitto.conf

Mosquitto不会默认为 /etc/mosquitto/mosquitto.conf,如果没有传递文件,它只会在没有 SSL 的情况下侦听端口 1883。

如果您在启动时将代理作为服务启动,那么您需要检查/etc/init.d/mosquitto脚本以确保它在启动时将配置文件传递给 mosquitto。

mosquitto -c /etc/mosquitto/mosquitto.conf

这应该有效 看看你在做什么,我相信你会使用 server.crt 和 server.key 来验证登录我猜?然后你需要在mosquitto.confie 中添加另一行

require_certificate当设置为时true将要求传入的客户端提供证书