ubuntu 16.4 安装MQTT

root@ros-OptiPlex-3050:~# sudo apt-add-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/tmpdwr_iinr/secring.gpg' created
gpg: keyring `/tmp/tmpdwr_iinr/pubring.gpg' created
gpg: requesting key 262C4500 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpdwr_iinr/trustdb.gpg: trustdb created
gpg: key 262C4500: public key "Launchpad mosquitto" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
OK

root@ros-OptiPlex-3050:~# sudo apt-get update

root@ros-OptiPlex-3050:~# sudo apt-get install mosquitto

root@ros-OptiPlex-3050:~# sudo apt-get install mosquitto-dev

root@ros-OptiPlex-3050:~# sudo apt-get install mosquitto-clients

root@ros-OptiPlex-3050:~# sudo service mosquitto status
● mosquitto.service - Mosquitto MQTT v3.1/v3.1.1 Broker
Loaded: loaded (/lib/systemd/system/mosquitto.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:mosquitto.conf(5)
man:mosquitto(8)

#打开一个终端,执行以下命令订阅主题"mqtt"
mosquitto_sub -h localhost -t "mqtt" -v

#打开另外一个终端,发布消息到主题 “mqtt”
mosquitto_pub -h localhost -t "mqtt" -m "Hello MQTT"

#现在你会看到消息被显示在前一个终端上了.

#通过以下命令,可以定于到官放所有测试的mqtt信息,当然你发布的信息别人也能订阅到
mosquitto_sub -h test.mosquitto.org -t "#"   -v

#也可以在官方mqtt服务下发布自己专属的信息
mosquitto_sub -h test.mosquitto.org -t  "myxyz123"  -v

#订阅自己的信息
mosquitto_pub -h test.mosquitto.org -t "myxyz123"  -m  "hello mqtt"
配置用户名
添加配置
root@test-OptiPlex-3050:/etc/mosquitto# nano mosquitto.conf

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

# 其他配置
include_dir /etc/mosquitto/conf.d

# 禁止匿名访问
allow_anonymous false
listener 1883 0.0.0.0
# 认证配置
password_file /etc/mosquitto/pwfile
# 权限配置
#acl_file /etc/mosquitto/aclfile
系统正常运行之后,添加用户hett1
添加用户
root@test-OptiPlex-3050:/etc/mosquitto# mosquitto_passwd pwfile hett1
Password:
Reenter password:
root@test-OptiPlex-3050:/etc/mosquitto#

使用mqttfx连接服务

 

 

 

 

 

 





posted @ 2019-12-17 16:19  李悠然  阅读(1051)  评论(0编辑  收藏  举报