取得key後進行安裝
sudo wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
cd /etc/apt/sources.list.d/
sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list
sudo apt-get update
sudo apt-get install mosquitto
安裝三個 Mosquitto proper 會用到的程式庫
mosquitto – the MQTT broker (or in other words, a server)
mosquitto-clients – command line clients, very useful in debugging
python-mosquitto – the Python language bindings
sudo apt-get install mosquitto mosquitto-clients python-mosquitto
安裝完後mosquitto會立即執行,但還需要進行部分設定,所以先停止
sudo /etc/init.d/mosquitto stop
開啟設定檔案
sudo nano /etc/mosquitto/mosquitto.conf
修改找到 log_dest 列,將後面改為 topic,如下
log_dest topic
並再增加下面六個參數後存檔
log_type error
log_type warning
log_type notice
log_type information
connection_messages true
log_timestamp true
重新啟動mosquitto
sudo /etc/init.d/mosquitto start
進行測試,開啟終端機,輸入下列指令
mosquitto_sub -d -t hello/world
再開啟另一個終端機,輸入下列指令
mosquitto_pub -d -t hello/world -m "Hello from Terminal 2!"
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgm9BQQpDnx0Bc6bQmJzgNz7f190tJtyxp7J4upm9-efPovSyL0MWQTRR99_plo_b_Rt8uhYyupvSocPcFLjSYc4CQQlEd5Evlq9_Llf28dInpEK46_K8S7GNFdokTKnq9I0oZmX1cjRs2K/s400/mqtt2.png) |
會在第一個開啟的終端機看到如上畫面 |
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3pHLDErY1TlxOhOzKdiHfoHsR7rU4ck-pvfaq4A9COIR7yXXh2jyT5krRgEuBXLn4XGqGJUOV8rpkPADA4975FbyxzWTClJe6bC2BLmsSllfu8FwP1J5laKF9i0UgooedvA_c6GGaUgpP/s400/mqtt1.png) |
會在第二個開啟的終端機看到如上畫面 |