How to set up multiple brokers using different ports using mosquitto snap

Hi , i’m using ubuntu core version 16 and a mosquittto snap version 2.0.14 stable Mosquitto Version, i would like to know how to set up multiple brokers that uses different ports using mosquitto snap.

Thank you Much help appreciated!

You can use parallel installs to set up multiple instances of a snap: https://snapcraft.io/docs/parallel-installs Each instance is managed independently.

Hi @mborzecki , Thanks for the Reply.

Currently i have already tested your method, but when i enter the command to install 2 of the same snap but with different names such as the example below, i can’t download the first but it will download the second snap name instead. Such as if i key in this example, it will install hello-world_foo 6.3 instead of the first one.

image

Thanks and much help appreciated!

I don’t think I understand. What you’re saying is that only one instance is installed? I tried this just now and install works as expected:

$ snap list |grep hello-world
$ snap install hello-world hello-world_foo
hello-world 6.4 from Canonical✓ installed
hello-world_foo 6.4 from Canonical✓ installed
$ snap list |grep hello-world
hello-world                    6.4                         29     latest/stable     canonical*            -
hello-world_foo                6.4                         29     latest/stable     canonical*            -

@mborzecki I used the command snap to install mosquitto snap and re-name the other duplicate snap as something else , such as mosquitto_2 but apparently it only installs mosquitto_2 instead the first mosquitto snap. Thus resulting only one being installed

Thank you.

I don’t understand, the command does not rename anything. It installs a snap with a given name. If you run snap install hello-world_foobar it will install hello-world_foobar, where hello-world is the snap name, and foobar is just an instance name.

Hi @mborzecki, i tested the example below and it works, but I’m not sure why it doesn’t work for Mosquitto snap, this is the snap here. Even though i tried with the example from the Link you have sent, it only installs one instead of both.

Appericate it, Thank you!

Aah, I see. Mosquitto sets a bunch of aliases, which is very unfortunate. If you install both in a single command it fails:

$ snap install mosquitto_foo mosquitto_bar
error: cannot perform the following tasks:
- Set automatic aliases for snap "mosquitto_foo" (cannot enable aliases "mosquitto_passwd", "mosquitto_rr", "mosquitto_pub", "mosquitto_sub" for "mosquitto_foo", already enabled for "mosquitto_bar")

However, you can pass --unaliased and install them one by one:

$ snap install --unaliased mosquitto_foo
mosquitto_foo 2.0.14 from Mosquitto Team (mosquitto✓) installed
$ snap install --unaliased mosquitto_bar
mosquitto_bar 2.0.14 from Mosquitto Team (mosquitto✓) installed
$ snap install --unaliased mosquitto_baz
mosquitto_baz 2.0.14 from Mosquitto Team (mosquitto✓) installed
$ snap list|grep mosquitto
mosquitto_bar                  2.0.14                      704    latest/stable     mosquitto*            -
mosquitto_baz                  2.0.14                      704    latest/stable     mosquitto*            -
mosquitto_foo                  2.0.14                      704    latest/stable     mosquitto*            -

The downside is that none of the snaps provides mosquitto_{pub,sub,rr} commands now, as they are accessible as eg. mosquitto_foo.pub and so on. However, there is a mosquitto broker service provided by each snap, which can be managed independently of other instances.

If you need the command line tools to be available under their usual names, you can either install mosquitto snap, or play with snap alias to enable aliasese from one of the snaps.

Hi @mborzecki, Thank you for your solution, it worked i am able to install mosquitto snap but with different instances name. But as mention, the Mosquitto_{pub,sub,rr} commands are disabled , i tried using the suggestion you gave which is to play with snap alias to enable the aliases for one of the Snaps , i followed this Link here. But currently is not working to enable aliasese for one of the snaps.

Thank you, Much help appreciated!

Let’s say I have mosquitt_foo and mosquitto_baz installed, both were installed with --unaliased

$ snap aliases
Command                      Alias             Notes
lxd.lxc                      lxc               -
mosquitto_baz.passwd         mosquitto_passwd  disabled
mosquitto_baz.pub            mosquitto_pub     disabled
mosquitto_baz.rr             mosquitto_rr      disabled
mosquitto_baz.sub            mosquitto_sub     disabled
mosquitto_foo.passwd         mosquitto_passwd  disabled
mosquitto_foo.pub            mosquitto_pub     disabled
mosquitto_foo.rr             mosquitto_rr      disabled
mosquitto_foo.sub            mosquitto_sub     disabled
openstackclients.aodh        aodh              -

Then to add an alias:

$ snap alias mosquitto_baz.pub mosquitto_pub
Added:
  - mosquitto_baz.pub as mosquitto_pub

which now shows up:

$ snap aliases mosquitto_baz
Command               Alias             Notes
mosquitto_baz.passwd  mosquitto_passwd  disabled
mosquitto_baz.pub     mosquitto_pub     manual,override
mosquitto_baz.rr      mosquitto_rr      disabled
mosquitto_baz.sub     mosquitto_sub     disabled

and if you look at the symlink it’s pointing to mosquitto_baz:

$ ls -l /snap/bin/mosquitto_pub 
lrwxrwxrwx 1 root root 17 04-22 09:02 /snap/bin/mosquitto_pub -> mosquitto_baz.pub
1 Like

Also my bad for bombarding you with questions, how do you change the MQTT port Number for mosquitto snap.

Thank you!

When the broker service starts, it prints this message:

Copying example config to /var/snap/mosquitto/common/mosquitto_example.conf
You can create a custom config by creating a file called /var/snap/mosquitto/common/mosquitto.conf
Using default config from /snap/mosquitto/704/default_config.conf

For instances that path would be eg. /var/snap/mosquitto_foo/common/mosquitto.conf

Actually I think that the launcher script that this snap uses is buggy and will misbehave when instances are in use. See the log from mosquitto_bar:

Copying example config to /root/snap/mosquitto_bar/common/mosquitto_example.conf
You can create a custom config by creating a file called /root/snap/mosquitto_bar/common/mosquitto.conf
Using default config from /snap/mosquitto/704/default_config.conf

So it’s probably best to use /root/snap/mosquitto_bar/common for now, and file a bug with the publisher (snap info lists https://mosquitto.org/ as the contact point) that it misbehaves when using parallel installs.

@mborzecki , Thanks for the help, Do you know where can i find the Mosquitto snap config file?

Thank You!

The example? It’s at /snap/mosquitto/704/default_config.conf, just copy it to the location I mentioned earlied and edit to your liking.

@mborzecki for the configuration file , is there a way to edit the the configuration file. As my file is Readonly.

Thank you!