Download
Download Mosquitto:
Official Website LinkInstallation
For the Windows version: Install Mosquitto to a directory like C:\Mosquitto or D:\Mosquitto. The installation path must not contain Chinese characters or spaces.
Configuration
The configuration file is located in the installation directory, named: mosquitto.conf
1. Back up this file first to avoid issues if incorrect modifications are made.
2. Open the file and modify the following configuration items as needed.
Search for the configuration item names in the file.
Line numbers cannot be provided as they vary by version.
Attachment: Official configuration file documentation, Link
| Configuration Item | Description |
listener 1883 0.0.0.0 |
This item specifies the Broker's listening port and IP address. Ensure this port is open on the server. If the port is occupied, replace it with another available port. |
allow_anonymous |
This item controls whether the Broker allows anonymous connections. For testing, enable anonymous access [remove the # symbol and set to allow_anonymous true].In production environments, anonymous connections pose security risks. |
plugin |
Authentication plugin for the Broker. If anonymous access is disabled, authentication is required to connect to the Broker. Refer to the next section "Authentication Plugin" to install the plugin and modify this configuration item. |
Authentication Plugin
When clients or devices connect to Mosquitto, authentication (using a username and password) is required unless anonymous access is enabled.
Mosquitto supports two authentication methods:
1. pwfile: Password file. Suitable for testing or small-scale device deployments. The Broker service must be restarted after each modification.
2. plugin: Plugin-based authentication. Suitable for production environments, supporting HTTP, database, Redis, and other authentication methods.
UNI IoT has developed an HTTP-based authentication plugin for Mosquitto. Click here to download.
After downloading, extract the files to the Mosquitto installation directory.
Copy the following configuration items and add them after the #plugin line in mosquitto.conf:
http://192.168.1.100/auth/user/. When a device connects to MQTT,
it will send the username and password to this interface for verification. The HTTP status code returned determines whether the connection is allowed (200 = allowed, others = denied).
※ For database or other authentication methods, the mosquitto-auth-plug plugin is recommended.
Follow the plugin documentation for installation and modify the corresponding configuration items in Mosquitto.conf.
Startup
| Windows Environment |
In a testing environment: Open the command prompt, navigate to the Mosquitto installation directory, and run:mosquitto -c mosquitto.confThis allows you to view the runtime status directly. In a production environment: Install Mosquitto as a Windows service using the command below: mosquitto installAfter installing the service, the following configuration item may prevent the service from starting. Please modify it: Change log_dest stdout (if present) to log_dest stderr.
|
| Linux Environment |
In a testing environment: Run Mosquitto directly in the shell to view the runtime status. In a production environment: Add Mosquitto to the system startup items to ensure it runs automatically on boot. |