Updating Mosquitto MQTT from 1.x to v2.0+

As part of my setup, I have a Mosquitto MQTT broker running in a Docker container. This has been an excellent setup, but a couple of days ago, it failed completely - turns out the image tag ‘latest’ had switched to 2.0.9 from 1.6.x, and there were some breaking changes!

The fix was relatively simple in the end, but took me a while to figure out, so I thought I’d document it here in case anyone else faces the same.

Important note - I don’t have any type of authentication in my MQTT network - this is done for simplicity when messing around with other devices, and because it’s in an isolated sub-net - if you use security, you’ll likely need some additional lines as well.

The failure symptom was that my broker and all MQTT devices went offline - with the broker throwing the error below:

io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: /ip_address:1883

To fix, you need to add a couple of lines to the mosquitto.conf file in your broker:

persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
listener 1883
allow_anonymous true
#user root is needed if installing direct - doesn't appear to be needed if in docker
user root

The reason these are needed is documented here.

Hope this is helpful to someone!


I also had to add

user root

since the user rights are with v2 dropped to user “nobody" and default 1.x config has no access to its files by this

Nice one - thank you! Is your Mosquitto installed in a Docker container, or direct? I wonder if that might be the difference there?

Direct on rpi4

Nice one - thank you. I’ve updated the post to include this.