阿里云服务器的安装,虚拟机同理
你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdow。
阿里云配置mqtt
只介绍最简单的安装:
本文参考:
https://blog.csdn.net/qq_29933439/article/details/91307940.
https://blog.csdn.net/weixin_43025071/article/details/82491560.
- 引入仓库;
sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
zhu@ubuntu:~/Downloads$ sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
[sudo] password for zhu:
More info: https://launchpad.net/~mosquitto-dev/+archive/ubuntu/mosquitto-ppa
Press [ENTER] to continue or Ctrl-c to cancel adding it.
Get:1 http://ppa.launchpad.net/mosquitto-dev/mosquitto-ppa/ubuntu focal InRelease [23.8 kB]
Hit:2 http://us.archive.ubuntu.com/ubuntu focal InRelease
- 更新apt依赖;
sudo apt-get update
# 一般不会出错
- 安装mosquitto,跳过第一步也可;
sudo apt-get install mosquitto
zhu@ubuntu:~/Downloads$ sudo apt-get install mosquitto
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libev4 libmosquitto1 libwebsockets15
The following NEW packages will be installed:
libev4 libmosquitto1 libwebsockets15 mosquitto
0 upgraded, 4 newly installed, 0 to remove and 148 not upgraded.
Need to get 545 kB of archives.
After this operation, 1,391 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
- 查看mosquitto服务是否开启;
sudo service mosquitto status
zhu@ubuntu:~/Downloads$ sudo service mosquitto status
● mosquitto.service - Mosquitto MQTT Broker
Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor pre>
Active: active (running) since Tue 2021-07-13 18:22:27 PDT; 1min 23s ago
Docs: man:mosquitto.conf(5)
man:mosquitto(8)
Main PID: 42683 (mosquitto)
Tasks: 1 (limit: 4618)
Memory: 1.3M
CGroup: /system.slice/mosquitto.service
└─42683 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Jul 13 18:22:27 ubuntu systemd[1]: Starting Mosquitto MQTT Broker...
Jul 13 18:22:27 ubuntu systemd[1]: Started Mosquitto MQTT Broker.
状态/停止/开启/重启 mosquitto服务
sudo service mosquitto status
sudo service mosquitto stop
sudo service mosquitto start
sudo service mosquitto restart
- 关闭mosquitto,配置conf文件,参考链接中未配置,本人环境中发现无法连接;
sudo nano /etc/mosquitto/mosquitto.conf
conf文件配置https://blog.csdn.net/weixin_43025071/article/details/82491560.
非常全面
zhu@ubuntu:~/Downloads$ sudo nano /etc/mosquitto/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
#上面的配置是文件自带的,但未设置port,默认是1883,想要成功连接,还需要设置
#绑定ip,不设置就连接不上,默认应该是是127.0.0.1
bind_address 0.0.0.0
#port 1883
#简单测试,开启匿名验证,默认不开启,则需要设置登录账密,且客户端连接需要验证
allow_anonymous true
- 启动mosquitto,查看状态;
- 打开防火墙访问端口,为配置文件中设置的port;
- mqtt服务器配置完成。
本地win系统测试连接mqtt
上方参考文档很详细,不再赘述,参考:https://blog.csdn.net/qq_29933439/article/details/91307940.
本地VM虚拟机配置mqtt服务器,本机环境Ubuntu
正常配置与云端服务器方式一致,此处介绍虚拟机单独配置
- 安装前记得主机与虚拟机互ping,看是否能够成功
- 测试时发现本地虚拟机网络连接设置NAT(共享主机ip)时可以双向ping通,不管选择什么,能ping通即可