I am new to mqtt and am trying to simply start a local instance with which I can test.
When executing
docker run -it -p 1883:1883 --restart always -v mosquitto.conf:/home/juliette/mosquito.conf --name mqtt eclipse-mosquitto:2.0.7
I get the following output:
1615963221: mosquitto version 2.0.7 starting
1615963221: Config loaded from /mosquitto/config/mosquitto.conf.
1615963221: Starting in local only mode. Connections will only be possible from clients running on this machine.
1615963221: Create a configuration file which defines a listener to allow remote access.
1615963221: Opening ipv4 listen socket on port 1883.
1615963221: Opening ipv6 listen socket on port 1883.
1615963221: Error: Address not available
1615963221: mosquitto version 2.0.7 running
and cannot connect with a mqtt-client:
mqtt sub --topic test
Server closed connection without DISCONNECT.
From what I've found the error apparently happens when no listener is configured but I did configure one, this is my mosquito.conf:
listener 1883
allow_anonymous true
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
port 1883
I also tried changing the port to 8883 because in one post someone mentioned that a larger port might solve the problem but that also didn't work.
Can someone tell me what I'm doing wrong?
Your startup command is close, but not correct. It should be:
docker run -it \
-p 1883:1883 \
--restart always \
-v /home/juliette/mosquito.conf:/etc/mosquitto/mosquitto.conf \
--name mqtt \
eclipse-mosquitto:2.0.7
The config file is in /etc/mosquitto...unless they have moved it in version 2.
You might also want to add a -p 8333:8333 line for mqtts/TLS connections.
EDIT: I see up in your log file output it says that the config was loaded from /mosquitto/config/mosquitto.conf ...so if the -v /home/juliette/mosquito.conf:/etc/mosquitto/mosquitto.conf line does not work, change it to -v /home/juliette/mosquito.conf:/mosquitto/config/mosquitto.conf
Related
I'm updatet my mosquitto from v1.6.9 to v2.0.12. But now, I'm not able to send mqtt messagtes with this docker container.
docker-container run:
docker run -itd \
--name="mosquitto" \
--restart always \
-p 1883:1883 \
-v /home/pi/.docker/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf \
-v mosquitto_data:/mosquitto/data \
-v mosquitto_data:/mosquitto/log \
eclipse-mosquitto
my config file:
listener 1883
allow_anonymous true
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
The permissions for config file (in docker container): 644 mosquitto:mosquitto
In log I see following output:
0: mosquitto version 2.0.12 starting
0: Using default config.
0: Starting in local only mode. Connections will only be possible from clients running on this machine.
0: Create a configuration file which defines a listener to allow remote access.
0: For more details see https://mosquitto.org/documentation/authentication-methods/
0: Opening ipv4 listen socket on port 1883.
0: Error: Address in use
0: Opening ipv6 listen socket on port 1883.
0: Error: Address not available
If I pub a new message I got an unknown error
# mosquitto_pub -t 'test/topic' -m 'hello, is anybody out there?'
Error: Unknown error.
It seems it doesn't load my config-file. see "0: Using default config".
Or is it something else? Maybe the permissions of the config file?
Thx
Source was that with the newer alpine image, libseccomp2 needed an update on Raspbian.
Details see here: https://github.com/eclipse/mosquitto/issues/2323#issuecomment-927367047
After that, it runs without any further problems.
I'm trying to run mosquitto as docker container in windows 10. Getting below error log Address not available.
1614449526: mosquitto version 2.0.7 starting
1614449526: Config loaded from /mosquitto/config/mosquitto.conf.
1614449526: Starting in local only mode. Connections will only be possible from clients running on this machine.
1614449526: Create a configuration file which defines a listener to allow remote access.
1614449526: Opening ipv4 listen socket on port 1883.
1614449526: Opening ipv6 listen socket on port 1883.
**1614449526: Error: Address not available**
1614449526: mosquitto version 2.0.7 running
Could anyone advise how to solve this error?
Thank you.
I'd the same issue.
My solution was:
Enter to mosquitto container item from portainer.io. then you must loggin by console in mosquitto's container. Select command : /bin/sh for loggin...
Once into command line must to adjust the mosquitto.conf located in : /mosquitto/config
Must change the following parameters: Uncomment and fixed
listener 1883
persistence true
allow_anonymous true
later, exit from command console and restart mosquitto container...and ready !!
check logs!
Hope to help!
i followed Stéphane Trottier's suggestion but ran into issues b/c of the port and an outdated config change:
allow_anonymous true
listener 2883
protocol mqtt
i also used port 2883 instead since it seems 8883 is for tls so i was getting connection refused errors on the client and protocol errors on the server. my docker compose looks like this:
mqtt:
image: eclipse-mosquitto:latest
volumes:
- ./mqtt/config:/mosquitto/config
user: "1000:1000"
ports:
- 1883:2883
I had the same issue yesterday... Generally, some OSs require more permissions to run services on ports lower than 2000. This is how I made it work for me. I'm just running this for a hobby project. For work I would do things differently.
added local mosquitto folder and placed mosquitto.conf file in it.
added allow_anonymous true
changed port to something higher than 2000.
mount local config volume in docker
allow_anonymous true
port 8883
I run it via docker compose file.
version: '3.1'
services:
mosquitto:
image: eclipse-mosquitto
hostname: mosquitto
container_name: mosquitto
ports:
- "8883:8883"
volumes:
- ./mosquitto:/mosquitto/config
networks:
- webnet
networks:
webnet:
The error is gone from my logs and I can connect to it just fine on that port.
1614505908: The 'port' option is now deprecated and will be removed in a future version. Please use 'listener' instead.
1614505908: mosquitto version 2.0.7 starting
1614505908: Config loaded from /mosquitto/config/mosquitto.conf.
1614505908: Opening ipv4 listen socket on port 8883.
1614505908: Opening ipv6 listen socket on port 8883.
1614505908: mosquitto version 2.0.7 running
looks like I'll have to replace port with listener at some point soon.
both azegurelabs and Stéphane Trottier answers worked for me.
but the easier and more accurate solution is to just run image with default provided conf
docker run -it --rm --name mosquitto -p 1883:1883 eclipse-mosquitto:2.0 mosquitto -c /mosquitto-no-auth.conf
or to run image with your config file
docker run -it -p 1883:1883 -v <absolute-path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:<version>
you can read more here: mosquitto docker github page
I am running Mosquitto 1.4.8 on Ubuntu successfully on port 1883 (tested from another machine with mosquitto_sub/mosquitto_pub). However I am encountering issues when attempting to use another port eg.
mosquitto -p 1884 -c moddebug.conf
This works OK if I access it from the same machine e.g.:
mosquitto_pub -h 127.0.0.1 -p 1884
but if I attempt to connect from another machine I get an error:
mosquitto_pub -h IP_ADDRESS -t exmapleTopic -p 1884
Connection timed out
My moddebug.conf file is:
log_type all
log_dest file mosquitto2_log.log
The log does not provide any extra information:
Config loaded from mosdebug.conf.
Opening ipv4 listen socket on port 1884.
Opening ipv6 listen socket on port 1884.
mosquitto version 1.4.8 terminating
I have tried altering the firewall rules (but this did not help):
ufw allow 1884/tcp
Rules updated
Rules updated (v6)
Hello I have installed mosquitto broker on my Raspberry Pi.
I'm trying to activate SSL but when I try to publish a message it returns connection refused.
My conf is:
# MQTT over TLS/SSL
listener 8883
cafile /etc/mosquitto/certs/ca.crt
certfile /etc/mosquitto/certs/hostname.crt
keyfile /etc/mosquitto/certs/hostnmae.key
tls_version tlsv1.2
# WebSockets over TLS/SSL
listener 9883
#protocol websockets
cafile /etc/mosquitto/certs/ca.crt
certfile /etc/mosquitto/certs/hostname.crt
keyfile /etc/mosquitto/certs/hostname.key
tls_version tlsv1.2
When I try:
mosquitto_pub --cafile /etc/mosquitto/certs/ca.crt -h localhost -t "test" -m "message" -p 8883
it return
Error: Connection refused
without logs.
"Connection refused" means that nothing is listening on the port you tried to connect to, 9883.
It's possible the Mosquitto just isn't running, or that it's not actually listening on the port (perhaps it didn't read the correct configuration file, or the configuration file correctly).
You can use lsof to find out what processes are listening on a port, or what ports a process is listening on.
For instance,
lsof -I :9883
will tell you what processes are listening on port 9883. If you don't see any then there's a problem with the Mosquitto server.
lsof -c mosquitto | grep TCP
will show you a what ports Mosquitto is listening on.
ps ax | grep mosquitto
will show you if Mosquitto is actually running.
If Mosquitto is running but port 9883 doesn't show up then it'll need to figure out why it's not picking up your configuration.
If it's not running you'll need to figure out why.
You may need to install lsof. You can do that with
sudo apt-get install lsof
I have installed Mosquitto on a brand new Raspberry Pi. OS is Raspbian.
I followed the instructions on the Owntracks website.
The broker is listening on port 1883 on localhost. Using a username and password I can run mosquitto_sub in one ssh session to the Pi, and receive messages sent by mosquitto_pub from another ssh session.
The broker is also listening on port 8883. I created certificates using the script in the Owntracks repository.
When I run mosquitto_pub on the Pi, using the hostname or IP-address I get an error "Error: Connection refused".
When I use localhost or 127.0.0.1 the error is "A TLS error occurred.".
If I run mosquitto_pub on my desktop computer (which is in the same LAN as the Pi), the error is "Connection refused". The command I run here is
mosquitto_pub -t owntracks/test -m Test -h pi1 --cafile ca.crt
where pi1 is the hostname of the Pi running the broker. The ca.crt file is copied from the Pi to the desktop computer.
The Mosquitto log is not showing why the connections are refused.
The TLS setup in the Mosquitto config looks like this:
listener 1883 127.0.0.1
listener 8883
cafile /etc/mosquitto/ca_certificates/ca.crt
certfile /etc/mosquitto/certs/server.crt
keyfile /etc/mosquitto/certs/server.key
require_certificate false
What is wrong in my setup?
if you try to use TLS with mosquitto
you must add this option to your command "-p 8883" to indicate the port
and you don't need to put "-h localhost or pi " because you use the client command mosquitto_pub in the same machine that run mosquitto broker
then your command we'll be :
"mosquitto_pub -d -u username -P password -t /path/to/the/topic --cafile /path/to/the/certificate -p 8883
don't forgot to comment this line
listener 1883
in your mosquitto.conf
Recreating all certificates solved the problem. Apparently I did something wrong with including local vs. remote IP-addresses and host names.
The TLS error messages are not very informative, but that probably has to do with security precautions.