测试机信息:
cat /proc/version
Linux version 3.10.0-1062.9.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Fri Dec 6 15:49:49 UTC 2019
Step.01 添加EPEL软件库
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
执行结果参考:
Loaded plugins: fastestmirror, langpacks
epel-release-latest-7.noarch.rpm | 15 kB 00:00:00
Examining /var/tmp/yum-root-WVe5CE/epel-release-latest-7.noarch.rpm: epel-release-7-12.noarch
Marking /var/tmp/yum-root-WVe5CE/epel-release-latest-7.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-12 will be installed
--> Finished Dependency Resolution
epel/7/x86_64 | 4.7 kB 00:00:00
epel/7/x86_64/group_gz | 95 kB 00:00:00
epel/7/x86_64/updateinfo | 1.0 MB 00:00:00
epel/7/x86_64/primary_db | 6.8 MB 00:00:00
extras/7/x86_64 | 2.9 kB 00:00:00
extras/7/x86_64/primary_db | 165 kB 00:00:00
mysql-connectors-community/x86_64 | 2.5 kB 00:00:00
mysql-connectors-community/x86_64/primary_db | 53 kB 00:00:00
mysql-tools-community/x86_64 | 2.5 kB 00:00:00
mysql-tools-community/x86_64/primary_db | 69 kB 00:00:00
mysql80-community/x86_64 | 2.5 kB 00:00:00
mysql80-community/x86_64/primary_db | 97 kB 00:00:00
os/7/x86_64 | 3.6 kB 00:00:00
updates/7/x86_64 | 2.9 kB 00:00:00
updates/7/x86_64/primary_db | 7.6 MB 00:00:01
Dependencies Resolved
=================================================================================================================================================================================================== Package Arch Version Repository Size
===================================================================================================================================================================================================Installing:
epel-release noarch 7-12 /epel-release-latest-7.noarch 24 k
Transaction Summary
===================================================================================================================================================================================================Install 1 Package
Total size: 24 k
Installed size: 24 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : epel-release-7-12.noarch 1/1
Verifying : epel-release-7-12.noarch 1/1
Installed:
epel-release.noarch 0:7-12
Complete!
使用 yum repolist all | grep enabled 查看安装结果:
Repository epel is listed more than once in the configuration
epel/7/x86_64 EPEL for redhat/centos 7 - x8 enabled: 13,224
extras/7/x86_64 Qcloud centos extras - x86_64 enabled: 341
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 141
mysql-tools-community/x86_64 MySQL Tools Community enabled: 105
mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 161
os/7/x86_64 Qcloud centos os - x86_64 enabled: 10,097
updates/7/x86_64 Qcloud centos updates - x86_6 enabled: 1,787
Step.02 安装mosquitto
使用 yum list all | grep mosquitto 查找mosquitto安装包:
Repository epel is listed more than once in the configuration
mosquitto.x86_64 1.6.8-1.el7 epel
mosquitto-devel.x86_64 1.6.8-1.el7 epel
使用 yum info mosquitto 查看mosquitto信息:
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
Available Packages
Name : mosquitto
Arch : x86_64
Version : 1.6.8
Release : 1.el7
Size : 283 k
Repo : epel/7/x86_64
Summary : An Open Source MQTT v3.1/v3.1.1 Broker
URL : http://mosquitto.org/
License : BSD
Description : Mosquitto is an open source message broker that implements the MQ Telemetry
: Transport protocol version 3.1 and 3.1.1 MQTT provides a lightweight method
: of carrying out messaging using a publish/subscribe model. This makes it
: suitable for "machine to machine" messaging such as with low power sensors
: or mobile devices such as phones, embedded computers or micro-controllers
: like the Arduino.
使用 yum install mosquitto 安装 mosquitto:
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mosquitto.x86_64 0:1.6.8-1.el7 will be installed
--> Processing Dependency: libwebsockets.so.13()(64bit) for package: mosquitto-1.6.8-1.el7.x86_64
--> Running transaction check
---> Package libwebsockets.x86_64 0:3.0.1-2.el7 will be installed
--> Processing Dependency: libuv.so.1()(64bit) for package: libwebsockets-3.0.1-2.el7.x86_64
--> Running transaction check
---> Package libuv.x86_64 1:1.34.0-1.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================================================================================================== Package Arch Version Repository Size
===================================================================================================================================================================================================Installing:
mosquitto x86_64 1.6.8-1.el7 epel 283 k
Installing for dependencies:
libuv x86_64 1:1.34.0-1.el7 epel 144 k
libwebsockets x86_64 3.0.1-2.el7 epel 118 k
Transaction Summary
===================================================================================================================================================================================================Install 1 Package (+2 Dependent packages)
Total download size: 545 k
Installed size: 1.3 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): libwebsockets-3.0.1-2.el7.x86_64.rpm | 118 kB 00:00:00
(2/3): libuv-1.34.0-1.el7.x86_64.rpm | 144 kB 00:00:00
(3/3): mosquitto-1.6.8-1.el7.x86_64.rpm | 283 kB 00:00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total 1.1 MB/s | 545 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 1:libuv-1.34.0-1.el7.x86_64 1/3
Installing : libwebsockets-3.0.1-2.el7.x86_64 2/3
Installing : mosquitto-1.6.8-1.el7.x86_64 3/3
Verifying : libwebsockets-3.0.1-2.el7.x86_64 1/3
Verifying : mosquitto-1.6.8-1.el7.x86_64 2/3
Verifying : 1:libuv-1.34.0-1.el7.x86_64 3/3
Installed:
mosquitto.x86_64 0:1.6.8-1.el7
Dependency Installed:
libuv.x86_64 1:1.34.0-1.el7 libwebsockets.x86_64 0:3.0.1-2.el7
Complete!
使用 yum list installed | grep mosquitto 查看安装结果:
Repository epel is listed more than once in the configuration
mosquitto.x86_64 1.6.8-1.el7 @epel
Step.03 测试mosquitto
启动mosquitto:
➜ ~ mosquitto
1585704498: mosquitto version 1.6.8 starting
1585704498: Using default config.
1585704498: Opening ipv4 listen socket on port 1883.
1585704498: Opening ipv6 listen socket on port 1883.
开启新终端,输入 mosquitto_sub -t rimelink ;
再开启新终端,输入 mosquitto_pub -t rimelink -h localhost -m "hello, mosquitto" :
之前打开的两个标签将分别出现:
➜ ~ mosquitto
1585704498: mosquitto version 1.6.8 starting
1585704498: Using default config.
1585704498: Opening ipv4 listen socket on port 1883.
1585704498: Opening ipv6 listen socket on port 1883.
1585704563: New connection from ::1 on port 1883.
1585704563: New client connected from ::1 as mosq-PlOYpZg4xJxUaIdsvh (p2, c1, k60).
1585704587: New connection from ::1 on port 1883.
1585704587: New client connected from ::1 as mosq-hmW8Jxc6bPxoibuQFD (p2, c1, k60).
1585704587: Client mosq-hmW8Jxc6bPxoibuQFD disconnected.
和
➜ ~ mosquitto_sub -t rimelink
hello, mosquitto
测试成功
参考链接