mosquitto是一个支持Linux以及Windows平台的mqtt服务器。在项目中用于实现对单台或多台仪器的远程控制,下面记录使用过程中的几个要点
-
只能本机客户端访问,无法远程访问
解决方法:需要手动配置一下监听端口,然后启动的时候指定配置文件。 -
常用配置
- 默认的配置文件为安装目录下的:mosquitto.conf
- 打开配置文件,设置监听端口号2005,默认为1883
# listener port-number [ip address/host name/unix socket path]
listener 2005
- 配置访问的用户名密码,关闭匿名访问
# Defaults to false, unless there are no listeners defined in the configuration
# file, in which case it is set to true, but connections are only allowed from
# the local machine.
allow_anonymous false
- 设置用户名密码存储的文件,这里采用默认的文件pwfile.example
# See the TLS client require_certificate and use_identity_as_username options
# for alternative authentication options. If an auth_plugin is used as well as
# password_file, the auth_plugin check will be made first.
password_file pwfile.example
- 设置用户名密码,打开Windows超级终端power shell,进入到安装目录。通过mosquitto_passwd.exe来配置用户名密码,分别指定存储文件以及用户名,回车以后设置两次密码。打开安装目录下的pwfile.example可以看到刚才添加的用户名
.\mosquitto_passwd.exe -c .\pwfile.example croxs
- 启动服务器,进入到安装目录 -v可以将日志显示到命令框
.\mosquitto.exe -c .\mosquitto.conf -v