Multi-Tenant Node-RED

Multi-Tenant Node-RED

These are steps to have multiple instances of Node-RED on a single host.  This post was inspired from this post “Node-Red multiple instances, RPi”, https://pysselilivet.blogspot.com/2019/04/node-red-multiple-instances-rpi.html
Seriously, buy this person a coffee, https://buymeacoffee.com/metzallo9! Having another instance for testing and evaluation can save headaches with your primary flows.

Create a copy of the primary instance to a new secondary instance.

cd .node-red
mkdir inst-2
cp settings.js ~/.node-red/inst-2/settings.js

Update any firewall policies that restrict access.

sudo vim /home/local/iptables/iptables.up.rules
# Node-RED Instance 2 - Allow
-A INPUT -p tcp -m tcp -s -A INPUT -p tcp -m tcp -s 192.168.0.0/24,192.168.1.100/32,192.168.1.110/32 --dport 1881 -j ACCEPT

# Node-RED Instance 2 - Global Drop
-A INPUT -p tcp -m tcp -s 192.168.1.0/24 --dport 1881 -j DROP

Start the new instance via command line to verify all is working as expected by opening the site’s URL:

http://192.168.0.100:1881

node-red -u ~/.node-red/inst-2/ -p 1881

Exit the command and set it to start as a service.  Copy the primary service to a secondary service.

sudo cp /lib/systemd/system/nodered.service /lib/systemd/system/noderedinst-2.service

Then edit the file /lib/systemd/system/noderedinst-2.service so that the second instance is called.

sudo vim /lib/systemd/system/noderedinst-2.service
ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS -- $NODE_RED_OPTIONS -u ~/.node-red/inst-2/ -p 1881

Save and exit, then enable and start the new secondary Node-RED service.

sudo systemctl daemon-reload
sudo systemctl enable noderedinst-2
sudo systemctl start noderedinst-2

Ensure that the service is running and that access to the URL works:

http://192.168.0.100:1881

sudo systemctl status noderedinst-2

The new secondary instance should have a blank canvas and the nodes available will be unique to it.

Reboot to verify that all is working.  If the second instance ever needs to be removed then perform these steps.

sudo systemctl stop noderedinst-2
sudo systemctl disable noderedinst-2

Then delete the ”noderedinst-2.service” file as well as the “~/.node-red/inst-2/” directory.

Comments are closed.