Mosquitto Ubuntu 安裝

參考官網

As of version 11.10 Oneiric Ocelot, mosquitto will be in the Ubuntu repositories so you can install as with any other package. If you are on an earlier version of Ubuntu or want a more recent version of mosquitto, add the mosquitto-dev PPA to your repositories list – see the link for details. mosquitto can then be installed from your package manager.

sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update
If the command “apt-add-repository” is not recognised, it can be installed with:

sudo apt-get install python-software-properties

操作過程

root@iZwz92tbw6nsayzyqcumgdZ:~/download# apt-get install software-properties-common 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
software-properties-common is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
root@iZwz92tbw6nsayzyqcumgdZ:~/download# 
root@iZwz92tbw6nsayzyqcumgdZ:~/download# 
root@iZwz92tbw6nsayzyqcumgdZ:~/download# apt-get install python-software-properties 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-software-properties is already the newest version.


root@iZwz92tbw6nsayzyqcumgdZ:~/download# sudo add-apt-repository ppa:mosquitto-dev/mosquitto-ppa
 More info: https://launchpad.net/~mosquitto-dev/+archive/ubuntu/mosquitto-ppa
Press [ENTER] to continue or ctrl-c to cancel adding it

gpg: keyring `/tmp/tmphm49azto/secring.gpg' created
gpg: keyring `/tmp/tmphm49azto/pubring.gpg' created
gpg: requesting key 262C4500 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmphm49azto/trustdb.gpg: trustdb created
gpg: key 262C4500: public key "Launchpad mosquitto" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK
root@iZwz92tbw6nsayzyqcumgdZ:~/download# 
root@iZwz92tbw6nsayzyqcumgdZ:~/download# sudo apt-get update
Ign http://mirrors.cloud.aliyuncs.com trusty InRelease
Ign http://mirrors.aliyun.com trusty InRelease                           
Get:1 http://mirrors.aliyun.com trusty-security InRelease [65.9 kB]      
Get:2 http://mirrors.cloud.aliyuncs.com trusty-security InRelease [65.9 kB]    
Get:3 http://mirrors.cloud.aliyuncs.com trusty-updates InRelease [65.9 kB]     
Get:4 http://mirrors.cloud.aliyuncs.com trusty-proposed InRelease [65.9 kB]    
Hit http://mirrors.cloud.aliyuncs.com trusty-backports InRelease      
.........................
.............
root@iZwz92tbw6nsayzyqcumgdZ:~/download# 
root@iZwz92tbw6nsayzyqcumgdZ:~/download# sudo apt-get install mosquitto
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libwebsockets3
The following NEW packages will be installed:
................
................

## 安裝完成自動運行


## 客戶端安裝
root@iZwz92tbw6nsayzyqcumgdZ:/etc/mosquitto# sudo apt-get install mosquitto.clients
Reading package lists... Done
Building dependency tree   

測試過程

打開兩個終端,一個發佈,一個訂閱

發佈test


admin@iZwz92tbw6nsayzyqcumgdZ:/data$ mosquitto_pub -h 127.0.0.1 -t test -m 'sfasfds'
admin@iZwz92tbw6nsayzyqcumgdZ:/data$ 

訂閱test

root@iZwz92tbw6nsayzyqcumgdZ:/etc/mosquitto# 
root@iZwz92tbw6nsayzyqcumgdZ:/etc/mosquitto# mosquitto_sub -h 127.0.0.1 -t test
hello MqTT
askdfsld

常用命令

sudo service mosquitto start #啓動
sudo service mosquitto status #查看狀態
sudo service mosquitto restart #重啓
sudo service mosquitto stop #停止

監聽端口(1883)

admin@iZwz92tbw6nsayzyqcumgdZ:/data$ netstat -an |grep 1883
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN     
tcp6       0      0 :::1883                 :::*                    LISTEN     
admin@iZwz92tbw6nsayzyqcumgdZ:/data$ 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章