When a HiveMQ node is started in cluster mode it will automatically move the contents of its existing data folder to the cluster-backup folder, effectively starting up the node without any data.
This is done on purpose. The logic behind this is that a running cluster always has the more relevant and consistent data than a restarted node. Even if the data present on the node is only a few minutes old it is likely that the persisted data for MQTT clients has changed a lot.
During specific scenarios such as maintenance windows or disaster recovery it can be useful or necessary to start up a HiveMQ node in cluster mode with persistent data.
Instructions
HiveMQ provides a specific run script called recovery.sh
that can be utilized for starting a HiveMQ node in cluster mode with persistent data
Startup via using the start up script
- Execute the the recovery.sh file in the
HIVEMQ_HOME/bin
folder.
Start up HiveMQ as a service (init.d)
Open the HiveMQ init.d start script
vi /etc/init.d/hivemq
Change the startup to using
recovery.sh
instead ofrun.shat line 19... failure $"HiveMQ start" echo; else echo -n Starting HiveMQ server su $HIVEMQ_USER -c "$HIVEMQ_HOME/bin/recovery.sh >/dev/null 2>&1 &" ### Create the lock file ### touch /var/lock/subsys/hivemq success $"HiveMQ server started" ...
Start the HiveMQ Service
/etc/init.d/hivemq start
- Make sure to revert the changes from step 2
Start up HiveMQ as a service (Debian based, using init.d)
Open the HiveMQ init.d start script
vi /etc/init.d/hivemq
Change the startup to using
recovery.sh
instead ofrun.shat line 19... BASEDIR=/opt/hivemq NAME=hivemq DESC="MQTT Broker" DAEMON=/opt/hivemq/bin/recovery.sh DAEMON_USER=hivemq DAEMON_GROUP=hivemq PID_FILE="/var/run/${NAME}.pid" ...
Start the HiveMQ Service
/etc/init.d/hivemq start
- Make sure to revert the changes from step 2
Start up HiveMQ as a service (systemd)
Open the HiveMQ systemd script
vi /etc/systemd/system/hivemq.service
Change the startup to using
recovery.sh
instead ofrun.shat line 12... ExecStart=/opt/hivemq/bin/recovery.sh ...
Start the HiveMQ Service
systemctl start hivemq
- Make sure to revert the changes from step 2
Related articles