简体   繁体   中英

address already in use error in mosquitto

I have installed mosquitto server and client packages in my ubuntu machine. When I run command "mosquitto" to run the mosquitto server I am getting an error "Error:address already in use". Why am I getting this error? How can I resolve this?

I ran into the same problem, and resolved the situation by killing the process that was running mosquitto. First, locate the mosquitto process id:

ps -ef | grep mosquitto

This should reveal to you any mosquitto related process. Say for example the process id was 12345 , then you could kill it with this:

sudo kill 12345

After that the Error:address already in use message was gone and mosquitto was able to run properly again.

The installation on ubuntu automatically starts the broker for you. Try connecting to check it out:

mosquitto_sub -t '$SYS/#' -v

You will need to install the mosquitto-clients package if you haven't done so already.

Just wait for 1 minute and then fire shut down command again. here is what I followed and got it working

step 1: journalctl -u mosquitto

step 2: service mosquitto stop //and not systemctl stop mosquito

Just to check if it successfully close use this Optional - step 3 : systemctl status mosquitto.service

and finally

step 4: service mosquito start

The package installer sets up mosquitto as a systemd service and automatically starts it running for you. It also configures mosquitto to start on a reboot, so you never need to start it manually.

But sometimes it can be helpful to run it in a console window, such as to test a new configuration file, or to watch the output to see clients make and break connections and things like that. In order to do this, you need to stop the background service, and you can use systemctl to do this:

$ systemctl stop mosquitto.service

When you're done with your testing and want to start the background service back up:

$ systemctl start mosquitto.service

To check it, use the status command:

$ systemctl status mosquitto.service 
● mosquitto.service - Mosquitto MQTT Broker
     Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2021-05-10 10:17:41 EDT; 1 day 6h ago
       Docs: man:mosquitto.conf(5)
             man:mosquitto(8)
...
   Main PID: 1110 (mosquitto)
      Tasks: 1 (limit: 76805)
     Memory: 5.3M
     CGroup: /system.slice/mosquitto.service
             └─1110 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

May 10 10:17:41 carter systemd[1]: Starting Mosquitto MQTT Broker...
May 10 10:17:41 carter systemd[1]: Started Mosquitto MQTT Broker.

That shows you that it is running, when it started, the process (Main) PID, and the configuration file that it is using, among other thing.

I've discovered that if you have :

socket_domain ipv4

before :

listener 1883 yourhostname

in your config, it results in "Address already in use", you just have to invert the order...

我确实运行了这个错误,因为我确实同时打开了 1883 端口和 1883 监听器,所以我删除了 1883 端口

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM