首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何快速在Ubuntu Linux服务器上安装一台MQTT服务器?

说起物联网,目前就笔者看来最有前途的应该是MQTT协议,MQTT(MQ Telemetry Transport,消息队列遥测传输)是近年来出现的一种新型协议,物联网领域会将其作为标准协议。MQTT 原本是IBM 公司开发的协议,现在则开源了,被人们不断开发着。MQTT 是一种能实现一对多通信(人们称之为发布或订阅型)的协议。它由3 种功能构成,分别是中介(broker)、发布者(publisher)和订阅者(subscriber),是一款轻量级的,节省通信流量的机器和机器间的通讯协议。

在笔者的另外一篇文章《三分钟弄懂物联网流行协议——MQTT》提到了MQTT协议,里面指出目前有很多的厂商或者开源产品支持MQTT协议的实现,其中就有目前最为流行的Mosquitto服务器。那么Mosquitto服务太牛掰了,几乎支持市面上你能想到,也想不到的操作系统平台,君请看。

Windows

Mac

Arch Linux

CentOS

Debian

Fedora

FreeBSD

Gentoo

Mandriva

openSUSE

OpenWrt

Raspberry Pi

Redhat Enterprise Linux

Slackware

SUSE Linux Enterprise Server

Ubuntu

Other Linux

QNX

iPhone

下面以在Ubuntu的Linux操作系统安装Mosquitto服务器为例子,和大家分享一下快速安装的方法。

Ubuntu的操作系统,并在拥有一个跟用户(Root)的权限的账号,下面是具体的步骤。

打开Ubuntu的终端,并运行下面的命令

sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa

当你输入密码之后,你将会看到下面的类似输出(临时文件的名字可能不太一样)

gpg: icedust `/tmp/tmpj3a50p1p/secring.gpg' created

gpg: icedust `/tmp/tmpj3a50p1p/pubring.gpg' created

gpg: /tmp/tmpj3a50p1p/trustdb.gpg: trustdb created

gpg: key 262C4500: public key "Launchpad mosquitto" imported

gpg: Total number processed: 1

gpg: imported: 1 (RSA: 1)

OK

紧接着运行下面的命令去更新Ubuntu的最新安装包,其会把Mosquitto的仓库地址加入到操作系统中来。

sudo apt-get update

你将会看到下面的类似输出。

Get:1 http://ppa.launchpad.net/mosquitto-dev/mosquitto-ppa/

ubuntu xenial InRelease [23,8 kB]

Get:5 http://ppa.launchpad.net/mosquitto-dev/ mosquittoppa/

ubuntu xenial/main amd64 Packages [2.048 B]

Get:7 http://ppa.launchpad.net/mosquitto-dev/ mosquittoppa/

ubuntu xenial/main i386 Packages [2.048 B]

Get:8 http://ppa.launchpad.net/mosquitto-dev/mosquitto-ppa/

ubuntu xenial/main Translation-en [1.292 B]

Fetched 29,2 kB in 1s (21,5 kB/s)

Reading package lists... Done

现在时候运行下面的命令去安装Mosquitto服务了。

sudo apt-get install mosquito

你将会看到下面的类似输出.

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following additional packages will be installed:

libev4 libuv1 libwebsockets7

The following NEW packages will be installed:

libev4 libuv1 libwebsockets7 mosquitto

0 upgraded, 4 newly installed, 0 to remove and 299 not upgraded.

8 not fully installed or removed.

Need to get 274 kB of archives.

After this operation, 714 kB of additional disk space will be used.

Do you want to continue? [Y/n]

这个时候请输入Y,让安装继续。之后,将会出现下面类似的界面,这个时候已经在安装和配置Mosquitto了。

Setting up mosquitto (1.4.10-0mosquitto3) ...

Processing triggers for libc-bin (2.23-0ubuntu3) ...

Processing triggers for systemd (229-4ubuntu7) ...

Processing triggers for ureadahead (0.100.0-19) ...

通过上面的步骤,Mosquitto其实已经被安装完了,如果想继续安装Mosquitto的客户端的话,可以运行下面的命令:

sudo apt-get install mosquitto-clients

其输出可能类似于下面:

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following additional packages will be installed:

libc-ares2 libmosquitto1

The following NEW packages will be installed:

libc-ares2 libmosquitto1 mosquitto-clients

0 upgraded, 3 newly installed, 0 to remove and 299 not upgraded.

Need to get 138 kB of archives.

After this operation, 332 kB of additional disk space will be used.

Do you want to continue? [Y/n]

当要求你继续的时候,请输入Y。

输入Y之后,将会显示下面类似的信息,其表示正在安装Mosquitto的客户端。

Setting up libmosquitto1:amd64 (1.4.10-0mosquitto3) ...

Setting up mosquitto-clients (1.4.10-0mosquitto3) ...

Processing triggers for libc-bin (2.23-0ubuntu3) ...

sudo service mosquitto status

如果出现了Active: active (running)等关键字,则表示Mosquitto已经启动。

因为MQTT服务器的默认端口是1883,运行下面的Linux命令,也能确认Mosquitto是否已经启动。

netstat -an | grep 1883

下面的输出显示了Mosquitto已经成功启动。

tcp 0 0 0.0.0.0:1883 0.0.0.0:* LISTEN

tcp6 0 0 :::1883 :::* LISTEN

如果你想继续深入的话,请给我在文末留言,如果大于10人我将继续深入下去。

如果你有任何疑问需要探讨,欢迎在文章末尾留言,我尽量在第一时间个大家回复。

【部分图片来源于网络,如有侵权,请留言联系删除,谢谢】

  • 发表于:
  • 原文链接http://kuaibao.qq.com/s/20180222A0ERFL00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券