UbuntuのMosquitto下のインストールと設定
Eclipse Mosquitto是一个开源消息代理,实现了MQTT协议版本3.1和3.1.1.Mosquitto轻量,适用于低功耗单板计算机到完整服务器的所有设备.
Mosquitto项目还提供了用于实现MQTT客户端的C库以及非常受欢迎的mosquitto_pub和mosquitto_sub命令行MQTT客户端.
この記事は、最後の日に変更された:2020年3月4日午前1時10分水曜日
タイガー兄の記事:この記事からコピーMosquittoを設定し、設定
を参照することにより本明細書:トゥーム-穏やかな心の記事であれば、各トピックのサブスクリプションmosquittoサーバのステータス
超コード、Ubuntuのサーバ18.04 LTSでテストされている、クライアント数に加入(SYS /ブローカー/クライアント/ \アクティブ(1.4 \バージョンがキャンセルされた)、修正された) / SYS /ブローカー/クライアントは、(現在の接続を期限切れクライアントの数)
達成するために、他のプロキシサーバ:https://github.com/mqtt/mqtt.github.io/wiki/servers
各オペレーティングシステムのインストールガイドライン:https://mosquitto.org/download/
Mosquittoインストール
- リポジトリを追加
sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
- アップデートパッケージ
sudo apt-get update
- インストール
sudo apt-get install mosquitto -y
- インストールコマンドラインクライアント
sudo apt-get install mosquitto-clients -y
コンフィギュレーション
/etc/mosquitto/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
# 禁止匿名访问
allow_anonymous false
# 认证配置
password_file /etc/mosquitto/pwfile
# 权限配置
acl_file /etc/mosquitto/aclfile
- 認証PWFILE
ファイルを作成します。
touch /etc/mosquitto/pwfile
- オープンサービスオープン
mosquitto_passwd /etc/mosquitto/pwfile 用户名
- 権利プロファイルaclfile
nano /etc/mosquitto/aclfile
# user1只能发布以test为前缀的主题,订阅以$SYS开头的主题即系统主题
user user1
topic write test/#
topic read $SYS/#
# user2只能订阅以test为前缀的主题
user user2
topic read test/#
サーバを起動します
#-c:指定特定配置文件启动
#-d:后台运行
mosquitto -c /etc/mosquitto/mosquitto.conf -d
テスト
使用mosquitto_pubコマンド発行、導入一般的な使用mosquitto_subコマンドパラメータを購読します:
パラメータ | 説明 |
---|---|
-h | Serverホスト、デフォルトはlocalhost |
-t | 指定されたテーマ |
-u | ユーザー名 |
-P | パスワード |
-私 | クライアントID、のみ |
-m | ニュースコンテンツを公開 |
- 購読
mosquitto_sub -h localhost -t "test/#" -u user2 -P 123456 -i "client1"
- システムのテーマを購読
# 订阅客户端存活连接数
mosquitto_sub -h localhost –t '$SYS/broker/clients/expired' -u user1 -P 123456 -i "client2"
- 解除
mosquitto_pub -h localhost -t "test/abc" -u user1 -P 123456 -i "client3" -m "How are you?"
他の
- プロジェクトのウェブサイト:https://www.eclipse.org/paho
- Eclipseのプロジェクト情報:https://projects.eclipse.org/projects/iot.paho
- GitHubの:https://github.com/eclipse/paho.mqtt.java
- 使用MQTT Javaクライアント:https://www.jianshu.com/p/65e1748a930c
- 春のサポート:https://www.jianshu.com/p/6b60858b7d44