Credits:The XMQ web site is provided by Linotex.The XMQ and SPTK Windows installers are created with Advanced Installer free Open-Source license.
There were 0 unique visitors to this page

Setting up a Cluster

Setting up a Cluster

Available since XMQ 1.0.0.

A cluster is a set of XMQ nodes that share one storage (Redis) and one accounts database (PostgreSQL or MySQL), so that a client connecting to any node sees the same sessions, the same accounts and the same retained messages. A node joins a cluster when an administrator selects its registered configuration and presses Join cluster. The nodes already share their administrator and cluster accounts; a second confirmation on the target is not required. The selected node is checked over TLS and configured, then its MQTT service is restarted within the same process. The web interface remains available.

The steps below set up two nodes, node-a and node-b, on two hosts. Everything is done from the configuration interface: a cluster is declared by an administrator there, not by editing a file on each node.

Prerequisites
  • XMQ 1.0.0 or newer, installed on both nodes - seeDownload and install binaries.
  • PostgreSQL (or MySQL) reachable from both nodes - the shared configuration and the shared accounts. The table xmq_node holds what an administrator edits: a row is a node, a column is a setting. A node that cannot reach the database does not start.
  • Redis reachable from both nodes - membership, leases, sessions and retained messages. Initial Setup and Settings offer Redis database numbers 0 through 16. Every cluster node must use the same number and credentials; the cluster keeps its keys under cluster: and its sessions undersession_<client_id>.
  • Nothing else. The TLS certificates the nodes link to one another with are created by the nodes themselves, one per node, during the initial setup - there is no certificate to obtain or copy before starting.

Before step 1, create the shared User Database and its SQL user on the PostgreSQL host. This example uses the default database name xmq; both nodes will use this same database:

sudo -u postgres psql -c "CREATE ROLE xmq LOGIN PASSWORD 'yourpassword'"
sudo -u postgres createdb -O xmq xmq

# Verify:
psql "postgresql://xmq:yourpassword@db-host/xmq" -c '\dt'
# (no tables yet - Initial Setup creates them)
1. Install and set up node A

After Initial Setup, use Configuration → Settings to edit the node name or address, MQTT and Web ports, Redis connection, or User Database connection. Test connections before saving. Save and restart MQTT preserves other settings and accounts; stored connection passwords remain masked unless you replace them.

Install the package on the first host, start the server, and open the configuration interface in a browser at https://localhost:18883. A server that has never been set up answers on the loopback address only, and its admin account has no password yet: the interface signs the administrator in by itself, and the Initial Setuppage opens.

# On node-a, after installing the package:
sudo systemctl enable --now xmq_server

# The interface is on the loopback address until a password is set. From the
# host itself, or through a tunnel:  ssh -L 18883:127.0.0.1:18883 node-a
#   -> https://127.0.0.1:18883

The first visit is met with the browser's Your connection is not privatewarning (Chrome: NET::ERR_CERT_AUTHORITY_INVALID). That is expected and not a fault: the interface serves HTTPS with a certificate it issued itself, and no browser trusts a certificate it has never seen. Press Advanced and then Proceed to 127.0.0.1 (unsafe) to carry on - the warning is the browser telling you it cannot verify who is at the other end, which is true of every self-signed certificate, this installation's included.

After the setup page is submitted the warning appears once more: that is the node's own certificate, issued by the setup a moment ago, which the browser has not seen either. Accept it the same way. The certificate is worth replacing with one a certificate authority has signed once the installation stops being a test one - the SSL Keys page installs one. The nodes register their certificates in the shared User Database for peer verification (step 3).

Fill in the Initial Setup page from top to bottom:

  1. Administrator: the username is admin. Enter its new password in Password and repeat it in Repeat password.
  2. This Server: set Node name to node-a. Set Node address to the DNS name or IP address the other nodes use to reach this host, without a scheme or port.
  3. Ports: check MQTT port (1883), MQTT+SSL port (8883), and Web interface port(18883). Change them if needed; all three must differ.
  4. Redis: enter the Redis hostname in Redis host, its port (default 6379), and a database number from 0 to16. If Redis requires authentication, also enter its username and password. Use the same Redis server, database number and credentials on every node.
  5. Accounts Database: the User Database URI row contains a server-type selector, host, and database (default xmq). Select PostgreSQL (or MySQL), enter the shared database hostname and database name, then fill in Database userand Database password below.

The database host may include a port. Database user and Database password are the SQL credentials, separate from the administrator password above. The interface builds the URI from these fields. If the database already holds an admin account with a password, enter that password in the Administrator section. Enter the shared cluster password in the Cluster account section. Configuring the shared database and Redis registers the node for discovery; it does not enable cluster mode or join a cluster. If the enabled admin account has no password yet, Initial Setup assigns the first administrator and cluster passwords together; other user accounts are preserved.

Initial Setup on node A creates the admin and internal cluster accounts in the shared user database. The cluster account is created once for the entire cluster: every node uses that same account. Enter the same cluster password during Initial Setup on every node; an existing account is checked before setup changes are applied. Existing shared accounts are preserved. The credential used for outgoing cluster connections is kept in the accounts database, separately from the account's password hash; it is never written to the node's configuration file.

Press Submit and restart. After the certificate warning described above, sign in as admin with the password you just set.

This page is also where the node's certificate is created: a self-signed certificate of the node's own, made out to the node host entered above, is written to /etc/xmq/certs/node.crt together with its key, and both the configuration interface and the MQTT+SSL listener are pointed at that pair. One certificate per node, never copied between them - it is the node's identity on the cluster's links.

Verify: the interface now answers on the node host, with the new certificate:

openssl s_client -connect node-a:18883 </dev/null 2>/dev/null     | openssl x509 -noout -subject -dates
# subject= ... CN=node-a   (the node host given on the setup page)
2. Install and set up node B

The same on the second host: install, start, open the interface through the loopback or a tunnel, and fill the Initial Setup page with node B's ownNode name (node-b), Node address, and ports. Its certificate is created the same way, made out to its address.

Every node in the cluster must follow these rules:

  • Node name must be unique across the entire cluster. Node B must use node-b, not node A's node-a. Give each additional node a different name.
  • User Database URI must be identical on every node. Use the same database server type, host, database, Database user, and Database password as node A, so that the assembled URI points every node at the same shared accounts and cluster configuration.
  • Redis settings must be identical on every node. Use the same Redis hostname, port, database number, username and password as node A.

Enter these matching values during Initial Setup, and use the administrator password and cluster password set on node A. Node B uses the accounts already created in the shared database in step 1, including the same cluster account.

Verify: the same command against node B returns a certificate namingnode-b. The two nodes now have two different certificates - check with openssl x509 -noout -fingerprint -in /etc/xmq/certs/node.crt on each, and see that the two differ.

3. Verify node and certificate registration

Every node configured with the shared User Database URI registers its own row in xmq_node, including its name, TLS address, and PEM certificate in the certificate column. At startup, a node publishes its current certificate and reads the other nodes' certificates from the same table into its local trusted peer files. A reissued certificate is updated in the shared database on startup.

Cluster links and join requests use these registered certificates for TLS peer verification. There is no manual certificate exchange or separate Trusted Nodes entry to create for each peer.

psql "postgresql://xmq:yourpassword@db-host/xmq"     -c "SELECT name, host_port, length(certificate) AS certificate_length FROM xmq_node ORDER BY name"
# node-a | node-a:8883 | (non-zero length)
# node-b | node-b:8883 | (non-zero length)

Verify: both rows have a non-empty certificate, and the peer certificates are on disk. If node A started before node B registered, restart node A to load node B's certificate from the shared database.

ls /etc/xmq/certs/peers/
# node-b.crt   (on node-a)   /   node-a.crt   (on node-b)
4. Join node B to the cluster

On node A select Cluster mode on the Dashboard and confirm the shared accounts database and Redis storage. This creates the first member. Keep node B in Standalone until you explicitly join it.

On node A's Cluster Configuration page select the registered node-b row and press Join cluster. Confirm the target and MQTT restart. The cluster uses the password configured during Initial Setup; there is no additional password dialog or Accept step on node B.

Before changing anything, the system verifies TLS, the selected UUID, server version, shared database, and Redis membership and capacity. Node B must use the same shared User Database URI. Its clients disconnect while MQTT restarts; local standalone sessions and queued messages are not migrated into the cluster.

5. Verify the join

Acknowledgement means node B accepted the configuration and is restarting MQTT; its row initially says Joining. The page refreshes automatically after the transition: both rows should say Clustered. A failed startup is reported as Failed, with the reason, and the last-good configuration is retained for rollback. The process and its web interface keep running, including when started manually. If MQTT cannot start with the new role, the node tries its previous configuration without restarting the process; the failure remains visible in the node list.

redis-cli -n 0 zrange cluster:members 0 -1
# two GUIDs after node B has restarted and joined
6. Check that the cluster carries traffic

Publish a retained message through one node and read it through the other: a retained message is synchronised across the cluster, so a subscriber on node B receives what was published on node A.

# Through node A:
xmq_pub -h node-a -p 1883 -u admin --password admin -t cluster/test     -m "hello from node-a" -q 1 -r

# Through node B:
xmq_sub -h node-b -p 1883 -u admin --password admin -t cluster/test -C 1 -W 5

If the message arrives, the cluster is whole. A client that then connects to either node for an ordinary session is served by that node, and the other nodes forward to it whatever its subscribers are subscribed to.

7. Leave the cluster without deleting the server configuration

Select the node in the list and press Leave cluster in the action panel on the right. Confirm its name. The selected server drains its cluster traffic, removes its membership, preserves its configuration in xmq_node, and restarts MQTT as Standalone within the same process. The web interface stays available. Other cluster members continue running. Returning to this cluster requires an explicit Join cluster action again.

8. Remove an obsolete server configuration

When Redis has no cluster members, the action panel offers Start clusterfor a selected Standalone node. Once it starts, open that node's Cluster page to join the others. Offline members still belong to an existing cluster: start one of them, enabling Cluster mode on its Dashboard if necessary.

Remove node deletes configuration, not membership. First leave the cluster. If the server still uses this database, select it and press Retire configuration: MQTT stops and the database records that this configuration is no longer to be used. An administrator can then remove the retired row.

If a server has been lost or its database URI was changed manually, UUID and Offline status cannot prove that the old configuration is unused. Use Force remove node only after confirming this explicitly. A removal marker is retained in this database so a server returning with the old UUID cannot silently recreate its configuration. Other databases remain independent. For an unrecoverable Offline member, first power it off or isolate it from Redis. Force removal checks that its lease has expired, removes membership, and blocks automatic rejoin with the old identity. Persisted sessions and queued messages remain available for recovery by existing members or the next cluster started on this Redis. A live member must leave normally; it cannot be force removed.