High Availability Domoticz Cluster
Posted: Thursday 05 July 2018 20:40
Hello,
I've completed the first version of my own basic High Availability Domoticz Cluster. This cluster is based on two servers (active/passive nodes) synchronized via MQTT. Each server has its own Domoticz instance and is also an MQTT server.
Under normal condition:
- the service is delivered by the main server and its Domoticz instance,
- the backup server monitors the main server (by sending every minute a JSON request to Domoticz) and synchronizes its own Domoticz database.
Failover happens if:
- Domoticz in the main server fails. The Backup Domoticz instance is then used to continue to deliver the service. This is done by republishing the MQTT incoming/outcoming messages between the two servers,
- or the main MQTT server fails (or even the server goes down). In this situation, the backup server becomes the main server by taking the IP address previously used by the main server.
All the stuff is done by only one (nodejs) script running only in the backup server.
The two servers have not to be the same one or even don't have to have the same hardware architecture. Also, the Domoticz versions and the databases structure on the two servers can be different. There is a basic repository within the script where you can declare some attributes for each Domoticz device you want to synchronize under normal condition. These attributes are :
- the device id,
- if it's incoming or outcoming message,
- the device type from a Domoticz perspective. For incoming message, it can be any device type. For outcoming message, it's currently only Light/Switch, SelectorSwitch, Thermostat or Temperature.
In my environment, it's an End to end High Availability solution because all my sensors/actuators are ESP8266. They are polled by scripts from the backup server when they are web server or they are able to reconnect themself to MQTT after the failover is done when they are MQTT client.
I've completed the first version of my own basic High Availability Domoticz Cluster. This cluster is based on two servers (active/passive nodes) synchronized via MQTT. Each server has its own Domoticz instance and is also an MQTT server.
Under normal condition:
- the service is delivered by the main server and its Domoticz instance,
- the backup server monitors the main server (by sending every minute a JSON request to Domoticz) and synchronizes its own Domoticz database.
Failover happens if:
- Domoticz in the main server fails. The Backup Domoticz instance is then used to continue to deliver the service. This is done by republishing the MQTT incoming/outcoming messages between the two servers,
- or the main MQTT server fails (or even the server goes down). In this situation, the backup server becomes the main server by taking the IP address previously used by the main server.
All the stuff is done by only one (nodejs) script running only in the backup server.
The two servers have not to be the same one or even don't have to have the same hardware architecture. Also, the Domoticz versions and the databases structure on the two servers can be different. There is a basic repository within the script where you can declare some attributes for each Domoticz device you want to synchronize under normal condition. These attributes are :
- the device id,
- if it's incoming or outcoming message,
- the device type from a Domoticz perspective. For incoming message, it can be any device type. For outcoming message, it's currently only Light/Switch, SelectorSwitch, Thermostat or Temperature.
In my environment, it's an End to end High Availability solution because all my sensors/actuators are ESP8266. They are polled by scripts from the backup server when they are web server or they are able to reconnect themself to MQTT after the failover is done when they are MQTT client.