ブローカーの設定サンプルです。
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