0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Mosquitto: 設定のサンプル

Last updated at Posted at 2025-03-06

ブローカーの設定サンプルです。
Let'sEncrypt の証明書を使います。

ポート 1883 mqtt
ポート 8883 mqtts
ポート 8884 mqtts over WebSocket

設定ファイル

/etc/mosquitto/conf.d/robot.conf
allow_anonymous true

listener 1883
protocol mqtt
listener 9001
protocol websockets

# SSL 設定
listener 8883
tls_version tlsv1.2
cafile /etc/ssl/certs/ISRG_Root_X1.pem
certfile /etc/letsencrypt/live/example.org/fullchain.pem
keyfile /etc/letsencrypt/live/example.org/privkey.pem
#
# SSL 設定 (wss 対応のため)
listener 8884
protocol websockets
tls_version tlsv1.2
cafile /etc/ssl/certs/ISRG_Root_X1.pem
certfile /etc/letsencrypt/live/example.org/fullchain.pem
keyfile /etc/letsencrypt/live/example.org/privkey.pem
#
# websockets_path /mqtt
#

mosquitto のバージョン

$ mosquitto -h
mosquitto version 2.0.18

mosquitto is an MQTT v5.0/v3.1.1/v3.1 broker.

証明書の確認

openssl s_client -connect example.com:8883 -showcerts

mqtts の確認

サブスクライブ

BROKER="example.com"
mosquitto_sub -d -h $BROKER \
     -p 8883 --capath /etc/ssl/certs/ \
    --topic example/testTopic

パブリッシュ

BROKER="example.com"
message="Hello Mqtt "`date`
mosquitto_pub -d -m "${message}" \
        -h $BROKER -p 8883 \
        --cafile /etc/ssl/certs/ISRG_Root_X1.pem \
        --topic example/testTopic
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?