LinuxCommandLibrary

mosquitto

Run a lightweight MQTT message broker

TLDR

Start Mosquitto

$ mosquitto
copy

Specify a configuration file to use
$ mosquitto [[-c|--config-file]] [path/to/file.conf]
copy

Listen on a specific port
$ mosquitto [[-p|--port]] [8883]
copy

Daemonize by forking into the background
$ mosquitto [[-d|--daemon]]
copy

SYNOPSIS

mosquitto [options]

PARAMETERS

-c config_file
    Specify a path to a configuration file. This is the primary way to configure Mosquitto.

-d
    Run Mosquitto in the background as a daemon.

-v
    Enable verbose logging, printing more information to stdout/stderr.

-p port
    Listen on the specified port instead of the default 1883 (or 8883 for SSL/TLS).

-h
    Display help information and exit.

-k keepalive_interval
    Set the maximum amount of time in seconds that a client can be idle before it is disconnected.

-q queue_size
    Set the maximum number of queued messages for a client.

-r
    Disable `retain` functionality for messages.

-u user
    Run the broker as the specified user. Recommended for security.

-V
    Display version information and exit.

-x
    Disable the use of `syslog` for logging.

DESCRIPTION

The mosquitto command initiates the Mosquitto MQTT broker, a crucial component for enabling Machine-to-Machine (M2M) and Internet of Things (IoT) communication. It implements the MQTT protocol versions 5.0, 3.1.1, and 3.1, providing a lightweight publish/subscribe messaging transport suitable for low-power devices and high-latency networks.

Mosquitto acts as a central hub where clients (publishers) send messages to specific topics, and other clients (subscribers) receive messages from those topics. Its efficiency and small footprint make it ideal for embedded systems and cloud-based IoT solutions. Beyond the broker, the Mosquitto project also provides command-line client utilities, mosquitto_pub and mosquitto_sub, for publishing and subscribing to MQTT messages respectively, facilitating quick testing and scripting. The broker supports various features including authentication, authorization, TLS/SSL encryption, persistence, and message bridging to other MQTT brokers.

CAVEATS

By default, Mosquitto runs with minimal security (no authentication/authorization), making it unsuitable for production environments without proper configuration. It is highly recommended to configure authentication, authorization, and TLS/SSL encryption using a configuration file (via -c) before deployment. Running the broker directly from the command line is generally for testing; in production, it's typically managed as a system service.

CONFIGURATION FILES

Mosquitto's behavior is primarily controlled through its configuration file, typically located at /etc/mosquitto/mosquitto.conf or a similar path depending on the installation. This file allows you to define listeners, authentication methods (e.g., password file, PAM, LDAP), access control lists (ACLs), persistence settings, bridge connections, and more. Understanding and customizing this file is essential for secure and robust deployments.

RUNNING AS A SERVICE

On most Linux distributions, Mosquitto is installed as a system service (e.g., using systemd). This allows it to start automatically on boot, run in the background, and be managed easily. You can typically start, stop, enable, or check the status of the Mosquitto service using commands like sudo systemctl start mosquitto or sudo systemctl status mosquitto.

HISTORY

Mosquitto was originally developed by Roger Light. It gained significant popularity due to its efficiency and simplicity, becoming a cornerstone for many IoT projects. In 2017, Mosquitto became an official project under the Eclipse Foundation, specifically as part of the Eclipse Paho project, which aims to provide open-source client implementations for MQTT and MQTT-SN. This move solidified its position as a community-driven, vendor-neutral broker solution for the evolving IoT landscape. Its continuous development ensures compatibility with the latest MQTT specifications and robust performance.

SEE ALSO

Copied to clipboard