使用 TLS 与 Mosquitto 进行 Telegraf 连接

Lor*_*nzo 1 raspberry-pi mosquitto telegraf

在我的系统(带有树莓派)中,我有一些传感器将数据发布到 Mosquitto,我使用 Telegraf 将数据传输到 influxDB 数据库,我使用 Grafana 来显示数据。

在没有 TLS 连接的测试期间(在 mosquittos 中)一切正常,但当我激活 TLS 时,我开始遇到 Telegraf 问题。

传感器使用 client.key、c​​lient.crt 和 ca.crt 将数据发送到代理。在代理中我可以看到来自传感器的数据。所以我认为问题不在于此。

在 telegraf 中(我想它作为客户端工作)我尝试配置 TLS 连接。查看 telegraf.service status ,它处于活动状态并且正在运行。查看日志,我没有看到连接中的错误,但我看不到来自代理的任何数据。

在 Telegraf.conf 中,我设置了证书,如下所示。我使用了用于连接到系统的传感器或其他客户端的文件,而不是使用 pem 文件:扩展名不同,我不知道问题是否在这里。

这里是Telegraf的配置(mqtt_consumer)

# # Read metrics from MQTT topic(s)
 [[inputs.mqtt_consumer]]
#   ## Broker URLs for the MQTT server or cluster.  To connect to multiple
#   ## clusters or standalone servers, use a seperate plugin instance.
#   ##   example: servers = ["tcp://localhost:1883"]
#   ##            servers = ["ssl://localhost:1883"]
#   ##            servers = ["ws://localhost:1883"]
   servers = ["tcp://192.168.1.58:8883"]
#
#   ## Topics that will be subscribed to.
   topics = [
     "sensors/#"
   ]
#
#   ## The message topic will be stored in a tag specified by this value.  If set
#   ## to the empty string no topic tag will be created.
#   # topic_tag = "topic"
#
#   ## QoS policy for messages
#   ##   0 = at most once
#   ##   1 = at least once
#   ##   2 = exactly once
#   ##
#   ## When using a QoS of 1 or 2, you should enable persistent_session to allow
#   ## resuming unacknowledged messages.
#   # qos = 0
#
#   ## Connection timeout for initial connection in seconds
#   # connection_timeout = "30s"
#
#   ## Maximum messages to read from the broker that have not been written by an
#   ## output.  For best throughput set based on the number of metrics within
#   ## each message and the size of the output's metric_batch_size.
#   ##
#   ## For example, if each message from the queue contains 10 metrics and the
#   ## output metric_batch_size is 1000, setting this to 100 will ensure that a
#   ## full batch is collected and the write is triggered immediately without
#   ## waiting until the next flush_interval.
#   # max_undelivered_messages = 1000
#
#   ## Persistent session disables clearing of the client session on connection.
#   ## In order for this option to work you must also set client_id to identify
#   ## the client.  To receive messages that arrived while the client is offline,
#   ## also set the qos option to 1 or 2 and don't forget to also set the QoS when
#   ## publishing.
#   # persistent_session = false
#
#   ## If unset, a random client ID will be generated.
    client_id = ""
#
#   ## Username and password to connect MQTT server.
    #username = ""
    #password = ""
#
#   ## Optional TLS Config
    tls_ca   = "/etc/telegraf/ca.crt"
    tls_cert = "/etc/telegraf/client.crt"
    tls_key  = "/etc/telegraf/client.key"
#   ## Use TLS but skip chain & host verification
#    insecure_skip_verify = false
#
#   ## Data format to consume.
#   ## Each data format has its own unique set of configuration options, read
#   ## more about them here:
#   ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
    data_format = "influx"
Run Code Online (Sandbox Code Playgroud)

如何在 Telegraf 中检查与代理的连接?配置正确还是我应该只使用 .pem 文件?

har*_*llb 5

您的 MQTT URL 开头为,但对于 MQTT over SSL 连接,tcp://它应该开头。ssl://