You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

Introduction

The introduction of the container feature into the RouterOS made it possible to run all kinds of servers for all sorts of tasks inside the router. This is especially relevant for people, who want to reduce the number of devices in their network. Instead of running a server on a separate device/machine, why not run it inside the router?

In this guide, we will showcase how to install a basic MQTT broker (or in other words, server) called eclipse-mosquitto. MQTT protocol is a very popular choice, especially in IoT topologies. It is an open OASIS and ISO standard lightweight, publish-subscribe network protocol that transports messages between devices. A typical topology consists of an MQTT publisher (a device that sends information), an MQTT broker (a server where the data is stored), and an MQTT subscriber (a device that listens to the data published on the server).

RouterOS supports MQTT publish feature and, now, we can also run the MQTT broker as well.

The image that we are going to use, can be found by following the hub.docker link.

Summary

Sub-menu: /container

note: container package is required.

Make sure to study our container guide before proceeding with the configuration. Make sure to check the disclaimer and requirements sections to understand all the risks and necessary steps you might be required to do.

You can find supported architectures by following the link.

At the time, when the guide was published, eclipse-mosquitto image was available for ARM32, ARM64, and AMD64 (CHR and x86) devices. In this example, we will run it on an ARM32 architecture device → RB1100AHx4.

Configuration

Container mode

Enable container mode:

/system/device-mode/update container=yes

You will need to confirm the device-mode with a press of the reset button, or a cold reboot, if using container on X86.

Networking

Add veth interface for the container:

/interface/veth/add name=veth2 address=172.19.0.2/24 gateway=172.19.0.1

Create a bridge for containers and add veth to it:

/interface/bridge/add name=msqt
/ip/address/add address=172.19.0.1/24 interface=msqt
/interface/bridge/port add bridge=msqt interface=veth2

Forward TCP 1883 for non-SSL MQTT:

/ip firewall nat add action=dst-nat chain=dstnat dst-address=192.168.88.1 dst-port=1883 protocol=tcp to-addresses=172.19.0.2 to-ports=1883

Getting image

To simplify the configuration, we will get the image from an external library but you can also import it via the .tar file.

Make sure that you have "Registry URL" set accordingly, limit RAM usage (if necessary), and set up a directory for the image.

/container/config/set registry-url=https://registry-1.docker.io tmpdir=disk7/pull

Pull image:

/container/add remote-image=eclipse-mosquitto:latest interface=veth2 root-dir=disk7/mosquitto logging=yes

After running the command, RouterOS should start "extracting" the package. Check "File System" for newly created folders and monitor container status with the command /container/print.

Starting the container

After you make sure that the container has been added and the status changed to status=stopped after using /container/print → you can initiate it:

/container/start 0

If you enabled container logging, you would see something like this in the Logs section:

 11:27:14 container,info,debug 1675416434: mosquitto version 2.0.15 starting
 11:27:14 container,info,debug 1675416434: Config loaded from /mosquitto/config/mosquitto.conf.
 11:27:14 container,info,debug 1675416434: Starting in local only mode. Connections will only be possible from clients running on this machine.
 11:27:14 container,info,debug 1675416434: Create a configuration file which defines a listener to allow remote access.
 11:27:14 container,info,debug 1675416434: For more details see https://mosquitto.org/documentation/authentication-methods/
 11:27:14 container,info,debug 1675416434: Opening ipv4 listen socket on port 1883.
 11:27:14 container,info,debug 1675416434: Opening ipv6 listen socket on port 1883.
 11:27:14 container,info,debug 1675416434: mosquitto version 2.0.15 running
  • No labels