ubuntu中MQTT详细安装教程

下载

http://mosquitto.org/files/source/

解压文件

tar -xvf mosquitto-1.6.2.tar

将mosquitto-1.6.2文件夹中config.mk文件中WITH_SRV:=no注释

  # initialization. See README in service/systemd/ for more information.
    WITH_SYSTEMD:=no
 
  # Build with SRV lookup support.
  #WITH_SRV:=no
                                                                              
  # Build with websockets support on the broker.
  WITH_WEBSOCKETS:=no

安装依赖库文件

sudo apt-get install libssl-dev libc-ares-dev uuid-dev g++ uuid-dev

添加链接

sudo ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1

添加用户

      sudo groupadd mosquitto
      sudo useradd -g mosquitto mosquitto //可以自定义用户组和用户名

MQTT程序配置

mv /etc/mosquitto/mosquitto.conf.example /etc/mosquitto/mosquitto.conf

启动MQTT

mosquitto -c /etc/mosquitto/mosquitto.conf -d

新建窗口1添加订阅服务

mosquitto_sub -t hello_test

另新建窗口2添加发布服务

mosquitto_pub -t hello_test -h localhost -m "hello world!"

会在新建窗口1中出现  hello world!

 

你可能感兴趣的:(嵌入式软硬件技术专栏)