一、安裝
1、直接安裝mqtt包
$ sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
$ sudo apt-get update
$ sudo apt-get install mosquitto
$ sudo apt-get install mosquitto-clients
2、從github上下載開發包後編譯
二、配置
1、添加配置文件
$ vi /usr/etc/mosquitto/mosquitto.conf
port 1883
listener 9005
protocol websockets
2、啓動
$ mosquitto -c /usr/etc/mosquitto/mosquitto.conf
三、測試
1、測試監聽
$ telnet localhost 9005
$ telnet localhost 1883
2、測試訂閱發佈
$ mosquitto_sub -h localhost -p 1883 -t "topic" -v
$ mosquitto_pub -h localhost -t "topic" -m "test message"