mosquitto-client obtain refused connection - linux

I want to use MQTT protocol using mosquitto library.
First of all, I want to do some test installing mosquitto-clients
sudo apt-get install mosquitto-clients
This program provides two "method":
mosquitto_pub
mosquitto_sub
Following this instructions I'm trying to submit new topic:
mosquitto_sub -d -t newtopic/test
using default host/port [localhost/1883].
I obtain:
Error: Connection refused
Is too generic as error.. can anyone help me?
Could be is a firewall problem? In this case, how can I check if is this the problem?
I'm using linux ubuntu ( 3.8.0-42-generic #62~precise1-Ubuntu)
nb same behaviour writing custom program using libmosquitto.

Just edit Mosquitto configuration file ( /etc/mosquitto/conf.d/mosquitto.conf ) adding these lines...
allow_anonymous true
listener 1883 0.0.0.0
... and restart Mosquitto (as service or not).
$ sudo service mosquitto restart
or
$ mosquitto --verbose --config-file /etc/mosquitto/conf.d/mosquitto.conf
As informed here, since v.1.7 allow_anonymous defaulted to false.
It is also useful to check log messages ( /var/log/mosquitto/mosquitto.log ).
Finally, run Mosquitto subscriber/publisher using --host (-h) parameter and the host IP address (get if from ifconfig or ip -color addr command).

The default host:port combination for mosquitto_pub/sub is localhost:1883. If you do not have a broker running on your local computer then it will not be able to connect of course.
The solution is to either run the broker on your local computer, or to tell the utilities where to connect. For example:
mosquitto_sub -t newtopic/test -h test.mosquitto.org

None of the other answers worked for me. In my case, I had upgraded from mosquitto 1.X to mosquitto 2.0, which requires a new configuration to be added to your mosquitto.conf:
listener 1883
For clients other than localhost to connect (ie, via Docker)

For future googlers:
You can use a public host as mentioned above, but to start a local mosquitto broker, first make sure you have installed mosquitto in addition to mosquitto_sub. You can then start up the mosquitto broker by simply running the following:
mosquitto

I experienced the same issue, for me it was in upgrading mosquitto for mqtt v5 support:
$ mosquitto --version
mosquitto version 2.0.14
mosquitto is an MQTT v5.0/v3.1.1/v3.1 broker.
However, the upgraded broker no longer supported anonymous connections:
$ mosquitto_pub -t mytopic -m "Hello World"
Connection error: Connection Refused: not authorised.
Error: The connection was refused.
This is probably a better default, but less friendly when experimenting.
To configure the broker to allow anonymous connections:
$ cat /etc/mosquitto/conf.d/standard.conf
listener 1883
protocol mqtt
allow_anonymous true
$ sudo systemctl restart mosquitto.service
Then, hey presto 🎩🐇:
$ mosquitto_pub -t mytopic -m "Hello World"

This is happening because you have installed only mosquitto clients on your system and not installed mosquitto on your system. please execute below command to install the MQTT Broker.
sudo apt-get install mosquitto
source:
connection attempt failed bytesofgigabytes.com

Be sure Your mosquitto service installed and correctly running.
for install : sudo apt-get install mosquitto
after install : sudo service mosquitto stop , sudo service mosquitto start

I had setup a username and password for my broker. Therefore had to use that while using mosquitto sub:
mosquitto_sub -u username -P password -t newtopic/test -h test.mosquitto.org

Related

Failed to connect to duckling http server. Make sure the duckling server is running and the proper host and port are set in the configuration

I have made workplace on slack and app is registered there from where i get the necessary things like slack token and channel to put it into the credentials.yml file of the rasa. After getting all the credentials i tried to connect between the rasa bot and slack using the command as:
rasa run
and my credentials.yml contains:
slack:
slack_token: "xoxb-****************************************"
slack_channel: "#ghale"
Here i have used the ngrok to expose a web server running on your local machine to the internet
but getting the error :
rasa.nlu.extractors.duckling_http_extractor - Failed to connect to duckling http server. Make sure the duckling server is running and the proper host and port are set in the configuration. More information on how to run the server can be found on github: https://github.com/facebook/duckling#quickstart Error: HTTPConnectionPool(host='localhost', port=8000): Max retries exceeded with url: /parse (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',))
Are you using Duckling? Duckling is a rule-based component to extract entities(docs).
If you are not using it, you can remove it from your NLU pipeline.
If you want to use it, the easiest way to do so is using docker:
docker run -p 8000:8000 rasa/duckling
The command above will run duckling and expose it on port 8000 of your host.
Just to add to #Tobias's answer;
If you are running some other service on port 8000, then you can bind any other port with th container's port and specify that in your pipeline config.
Example:
docker run -p <Desired Port, ex- 1000>:8000 rasa/duckling
Change config file to reflect that. Your pipeline should include
- name: DucklingHTTPExtractor
# https://rasa.com/docs/rasa/nlu/components/#ducklinghttpextractor
url: http://localhost:<Desired Port, 1000>
Retrain your model with changed config.
After training, simply run: rasa run
If you are doing numerical extractions (e.g. six to 6 etc), I presume this will be helpful for form filling on Rasa - you need to install docker and then expose duckling on port 8000
First, install docker (assumes Fedora but you can lookup other distros)
sudo dnf install docker
Second, activate docker
sudo systemctl start docker
Last, activate Rasa's docker
docker run -p 8000:8000 rasa/duckling
Your response should be - Status: "Downloaded newer image for
docker.io/rasa/duckling:latest Listening on http://0.0.0.0:8000"

HiveMQ systemctl service not listening to port

I am trying to set up HiveMQ on my Amazon EC2 instance (ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20170414) using this guide: http://www.hivemq.com/docs/hivemq/latest/#hivemqdocs_installation_for_specific_operating_systems
After installing I can succesfully run HiveMQ using:
Change directory to HiveMQ directory cd /opt/hivemq
Execute startup script ./bin/run.sh
HiveMQ will start running, and listening to port 1883 and I can connect and subscribe to the broker.
When I run HiveMQ as a systemctl service:
For Debian-based linux like Debian, Ubuntu, Raspbian using systemd systemctl enable hivemq
It starts as a service withoutany issues
However, when running netstat -an|grep 1883 it does not show any activity. HiveMQ do not seem to listen to any ports and I can not connect with my MQTT client. What could be the issue?
without any additional information my guess would be an issue with permissions.
chown -R hivemq:hivemq /opt/hivemq (changing the owner of the hivemq folder to the hivemq user)
will resolve this issue

Socket connection into Docker initially succeeds then fails

Running under MacOS I am connecting from a node.js app with net.Socket() into a Docker container running on the same host, which contains a C++ sockets server under Centos. The Docker run command is:
docker run -it --rm -p 14000-14010:14000-14010 -v /Users/me/Development/spdz:/spdz spdz/spdzdev
When the c++ server in docker is not running, I see a successful connection in node followed 3ms later by a socket closed message.
It appears as if a proxy in front of the container is accepting the request, passing it through to Docker where it is rejected. However this leads to erroneous messages in my front end application which thinks the connection was successful, only to find out later it was not.
I would like to see a simple connection declined. Any suggestions as to how this may be remedied or better understood would be helpful.
I am confident that the behaviour is introduced by Docker, as running the components outside Docker gives the expected immediate failure on connection. Also I have tried mapping the exported ports to an external network interface rather than localhost but see the same behaviour.
I suggest that you check that if the error is not coming from your server application.
You can use netcat command line to open a socket on your Docker container
nc -l 14000
This will create a TCP server socket listening on port 14000.
Then, from your host computer (MacOs), open a terminal and try to connect with telnet
telnet -e q localhost 14000

Mongodb Management Service Error, Failure dialing host

I've downloaded MMS by using this command
curl -OL https://mms.mongodb.com/download/agent/monitoring/mongodb-mms-monitoring-agent_latest_amd64.deb
Installed it by using sudo
sudo dpkg -i mongodb-mms-monitoring-agent_latest_amd64.deb
And edited /monitoring-agent.config file which located in
/etc/mongodb-mms
It was working Just fine Until I've started my mongod rplSet by adding --Fork flag, and by using this command
sudo mongod --fork --port 27017 --dbpath /mydbpath --logpath /mylogpath/mongodb.log --replSet Rplname
After starting the services using the above command, my MMS started showing that the host is Unreachable, and that following msg, in all of the members.
Task failure `hostIpAddr`. Err: `Failure determining IPv4 address for `myDnsAdd.cloudapp.net`. Err: `myDnsAdd.cloudapp.net: no such host` at monitoring-agent/components/task.go:221 at monitoring-agent/components/worker.go:153 at monitoring-agent/components/worker.go:224 at monitoring-agent/components/worker.go:236 at pkg/runtime/proc.c:1445`
I've edited the hosts file, and added the hosts ips and hostnames.
Opened the 443 port, and tried to start mmms with --system flag like this
sudo start mongodb-mms-monitoring-agent --system
But still, Host is Unreachable. I got access list on the mongoport (:27017) is it beacuse of this? if so what IP should I add to that access list?
Best,
If your OS is Ubuntu 14.04, then this link should be interesting for you:
https://jira.mongodb.org/browse/MMS-2202
Basically it says that it is a bug in glibc and the solution for this guy was to update Ubuntu to version 14.10.

emailrelay "cannot bind the listening port"

I'm setting up my web server on Amazon's EC2. My site used to run locally and used my ISP's SMTP server to send email, which hasn't been a problem before - but now that the emails are originating from outside my ISP won't accept them.
Therefore, I'm trying the advice here to use EmailRelay to forward emails, adding authentication, via my account on Google.
I've followed the instructions, created the emailrelay.auth file, run the configure, make, make install, but when I try to start the emailrelay service I'm getting this error:
$ emailrelay --as-proxy smtp.gmail.com:587 --client-tls --client-auth /etc/emailrelay.auth
emailrelay: error: cannot bind the listening port: 0.0.0.0:25
emailrelay: exception: cannot bind the listening port: 0.0.0.0:25
I've looked through the user guide, tried using the --interface option thinking this might be the issue - providing various IPs, with no joy - and I don't know what to try next.
(my server is running Oracle Enterprise Linux 5.1)
EDIT:
Since sendmail is running on port 25, I've tried an alternative port. Now I get a new error:
$ emailrelay --as-proxy smtp.gmail.com:587 --client-tls --client-auth /etc/emailrelay.auth --port 8025
emailrelay: error: cannot do tls/ssl: openssl not built in
emailrelay: exception: cannot do tls/ssl: openssl not built in
After killing sendmail, I've retried with port 25 and I get the same error ("cannot do tls/ssl: openssl not built in").
EDIT:
Looks like openssl is not installed:
$ grep ssl config.log
$ ./configure --with-openssl
configure:7373: checking for openssl
conftest.cpp:31:25: error: openssl/ssl.h: No such file or directory
| #include <openssl/ssl.h>
configure:7431: WARNING: ignoring --with-openssl, check config.log and try setting CFLAGS
config.status:719: creating src/gssl/Makefile
The error means that it can't gain exclusive access to port 25 (the default port for SMTP). This is either because it is already in use, or because, as an unprivileged user, you don't have access to ports numbered less than 1024.
There may already be a program running on port 25. Probably sendmail, but possibly postfix or qmail (I don't know what Oracle uses for mail). You will need to shut any such program down.
If you shut down any email software on the computer and run emailrelay as root, you will probably not get that error message.
I got to this question having the same issue on an EC2 instance running Ubuntu.
For Ubuntu:
first sudo apt-get install libssl-dev
then (re-)run ./configure && make && sudo make install
Now either using :25 if clear, or feeding another port to emailrelay --port 12345 it works as expected.

Resources