Clustered nodeBB on Apache
-
This would be a typical setup/topology for clustering. This should be fault tolerant for nodebb, however, the DB will also need some HA/clustering later.
-
@adam-poniatowski said in Clustered nodeBB on Apache:
clustering
@Esteban-Constante
NodeBB Utilise clusteringNodeBB is a node app, kindly refer NodeBB documentation for Scalability
https://nodebb.readthedocs.io/en/latest/scaling/index.htmlotherwise run NodeBB with PM2 on cluster mode:
here is the command pm2 start app.js -i 0
The -i or instances option can be:
-
0 to spread the app across all CPUs
-
-1 to spread the app across all CPUs - 1
-
number to spread the app across number CPUs
@Esteban-Constante if you want to choose @Adam-Poniatowski methodology then use some proxy server for load balancing ex. Nginx or Ha-Proxy
-
-
@hariom-vashisth The Apache (or nginx) will act as the proxy/load balancer in this topology. It is a very simple HA/clustering setup, but one can take it further with more load balancers and use round robin DNS, if you want failover/HA for your load balancers. or one can skip apache/nginx and go ahead with just DNS load balancing.
-
@adam-poniatowski just fyi, round robin will not work with NodeBB due to socket.io being incompatible.
-
@hariom-vashisth said in Clustered nodeBB on Apache:
@Esteban-Constante
NodeBB Utilise clusteringNodeBB is a node app, kindly refer NodeBB documentation for Scalability
https://nodebb.readthedocs.io/en/latest/scaling/index.htmlGuide refers to nginx, I wonder if Apache will be able to handle the websockets throughout multiple ports as nginx does
-
@hariom-vashisth said in Clustered nodeBB on Apache:
@Esteban-Constante
NodeBB Utilise clusteringNodeBB is a node app, kindly refer NodeBB documentation for Scalability
https://nodebb.readthedocs.io/en/latest/scaling/index.htmlotherwise run NodeBB with PM2 on cluster mode:
here is the command pm2 start app.js -i 0
The -i or instances option can be:
-
0 to spread the app across all CPUs
-
-1 to spread the app across all CPUs - 1
-
number to spread the app across number CPUs
I tried this, however I keep getting messages saying my connection to the forum dropped out.
-
-
@esteban-constante
I am writing an article on NodeBB deployment that will guide you -
insecure web-sockets doesn't work with secure network(https)
Nginxserver {
listen 443 ssl;
ssl on;
blah blah blah...
location = /socket {
proxy_pass http://socket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_send_timeout 1d;
proxy_read_timeout 1d;
}
}
upstream socket {
server 127.0.0.1:27960;
}Apache
enable these modules:
-
mod_proxy.so
-
mod_proxy_wstunnel.so
Add this in VirtualHost File:
ProxyPass /wss2/ ws://domain.com:port_number/
Use this URL in your JavaSscript call when you want a WSS connection:
var ws = new WebSocket("wss:/socket_url.mydomain.org/wss2/NNN");
Note: Change domain, IP and ports as per your server configuartions.
-
-
@Adam-Poniatowski & @HARIOM-VASHISTH:
I've managed to migrate my NodeBB to Google Cloud and it's running in clustered mode.
However, I'm having issues with traffic spikes which clog my CPU.
Any of you have experience running multiple instances and autoscaling? (or perhaps @julian can give some input here)
Thanks!!!