Installation and configuration under ubuntu Mosquitto
Eclipse Mosquitto是一个开源消息代理,实现了MQTT协议版本3.1和3.1.1.Mosquitto轻量,适用于低功耗单板计算机到完整服务器的所有设备.
Mosquitto项目还提供了用于实现MQTT客户端的C库以及非常受欢迎的mosquitto_pub和mosquitto_sub命令行MQTT客户端.
This article was last modified date: 2020-03-04 1:10 Wednesday
This article copy from: Tiger brother article Mosquitto set up and configure
herein by reference: Tomb - calm heart if the article subscription mosquitto server status of each topic
The ultra-Code, have been tested on ubuntu server 18.04 LTS, subscribe to the number of clients \ (SYS / broker / clients / active (1.4 version has been canceled), as modified \) SYS / Broker / Clients / expired The (current connection the number of clients)
Other proxy servers to achieve: https://github.com/mqtt/mqtt.github.io/wiki/servers
each operating system installation guidelines: https://mosquitto.org/download/
Mosquitto installation
- Add Repository
sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
- Update Package
sudo apt-get update
- installation
sudo apt-get install mosquitto -y
- Installation command line client
sudo apt-get install mosquitto-clients -y
Configuration
/etc/mosquitto/mosquitto.conf Configuration
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
- Authentication pwfile
Create a file
touch /etc/mosquitto/pwfile
- Open service open
mosquitto_passwd /etc/mosquitto/pwfile 用户名
- Rights Profiles aclfile
nano /etc/mosquitto/aclfile
# user1只能发布以test为前缀的主题,订阅以$SYS开头的主题即系统主题
user user1
topic write test/#
topic read $SYS/#
# user2只能订阅以test为前缀的主题
user user2
topic read test/#
Start the server
#-c:指定特定配置文件启动
#-d:后台运行
mosquitto -c /etc/mosquitto/mosquitto.conf -d
test
Use mosquitto_pub command issued, subscribe to common use mosquitto_sub command parameters introduced:
parameter | description |
---|---|
-h | Server host, the default localhost |
-t | Designated theme |
-u | username |
-P | password |
-i | Client id, the only |
-m | Publish news content |
- subscription
mosquitto_sub -h localhost -t "test/#" -u user2 -P 123456 -i "client1"
- Subscribe system theme
# 订阅客户端存活连接数
mosquitto_sub -h localhost –t '$SYS/broker/clients/expired' -u user1 -P 123456 -i "client2"
- release
mosquitto_pub -h localhost -t "test/abc" -u user1 -P 123456 -i "client3" -m "How are you?"
other
- Project website: https://www.eclipse.org/paho
- Eclipse Project Information: https://projects.eclipse.org/projects/iot.paho
- GitHub:https://github.com/eclipse/paho.mqtt.java
- Use MQTT Java Client: https://www.jianshu.com/p/65e1748a930c
- Spring Support: https://www.jianshu.com/p/6b60858b7d44