Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

ubuntu - MQTT Configuration File Mosquitto on Azure Ubunutu VM

I'm following this tutorial to configure mosquitto.

This means that I'm storing my local configuration in /etc/mosquitto/conf.d/default.conf. However, I've just now realized that I can put any password/username and it will access mosquitto meaning my config file isn't taken into account. I've just now discovered the /etc/mosquitto/mosquitto.conf and its content can be seen below:

# 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

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

The contents of my configuration file that I want to use /etc/mosquitto/conf.d/default.conf can be seen below.

allow_anonymous false
password_file /etc/mosquitto/passwd

listener 1883

listener 8883
certfile /etc/letsencrypt/live/20.56.xxx.xxx/cert.pem
cafile /etc/letsencrypt/live/20.56.xxx.xxx/chain.pem
keyfile /etc/letsencrypt/live/20.56.xxx.xxx/privkey.pem

Using the command sudo pkill mosquitto and then sudo mosquitto -c /etc/mosquitto/conf.d -d I stopped mosquitto and restarted it in the background running the new configuration file. When I first ran it (using the /etc/mosquitto/conf.d/default.conf shown above), I got the Error: Connection Refused. I then modified the /etc/mosquitto/conf.d/default.conf file, killed mosquitto and ran it again using the same techinque. The new config file can be seen below.

allow_anonymous false
password_file /etc/mosquitto/passwd

listener 1883

For this version, the password and username protection works!!

Here are the logs for those operations

1610537764: mosquitto version 1.4.15 (build date Tue, 18 Jun 2019 11:42:22 -0300) starting
1610537764: Config loaded from /etc/mosquitto/mosquitto.conf.
1610537764: Opening ipv4 listen socket on port 1883.
1610537764: Opening ipv6 listen socket on port 1883.
1610537764: Opening ipv4 listen socket on port 8883.
1610537764: Opening ipv6 listen socket on port 8883.
1610537764: Error: Unable to load CA certificates. Check cafile "/etc/letsencrypt/live/20.56.121.212/chain.pem".
1610537909: mosquitto version 1.4.15 (build date Tue, 18 Jun 2019 11:42:22 -0300) starting
1610537909: Config loaded from /etc/mosquitto/mosquitto.conf.
1610537909: Opening ipv4 listen socket on port 1883.
1610537909: Opening ipv6 listen socket on port 1883.
1610537909: Opening ipv4 listen socket on port 8883.
1610537909: Opening ipv6 listen socket on port 8883.
1610537912: New connection from xx.xx.2.13 on port 1883.
1610537912: New client connected from xx.xx.2.13 as mqtt_f1f0a02.f7e396 (c1, k60, u'bigBoiTeam').
1610538010: mosquitto version 1.4.15 terminating

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...