ssh load balancing

I looking for any resources about load balancing ssh traffic to 10 raspberry pies the 60 people.
i have found these for haproxy but i would prefer to use nginx because i have a bit of experience with it.
Load-Balancing ssh with HAProxy | Jake Chanenson
Load Balancing SSH – Eugene Petrenko
it also need to be able to handle losing devises the PIs have bean very unreliable.


So a person tries to open an ssh connection and gets a random Pi?

I don’t understand why this would be any more complicated than a few iptables rules and/or properly setup ssh_config stuff, what other requirements do you have?

btw, welcome!

1 Like

I haven’t used with iptables and wasn’t a ware ssh_config could do anything like this. what im looking for is something this will not break when pies go down and will distribute the load between the PIs there are pi 3b x2 pi3b+ x4 and pi3b+ x5 witch is why i was thinking using nginx. im not looking to randomly give pis i looking to give the pi that has the least users currently or most resores avalibal

… will not break when pies go down and will distribute the load

in-flight user sessions will go down regardless.

haproxy has more mature and more varied load balancing options.

failing either, you could also consider building your own.

Is stickyness required. in other words, … if I ssh cluster and land on pi-host-a and then from another terminal window I ssh cluster; would it be required to land on pi-host-a again … or would alternative hosts do.

least users currently or most resores avalibal

If building your own (e.g. ), you can probably plug stuff into some scoring function that you can consult every time you get a new incoming tcp connection and need to determine where to send it.

there’s a bunch of examples you can look at here: Streams — Python 3.10.2 documentation

doing this in python would probably be ok as a first proof of concept for however you decide to pull this off.

1 Like

I am aware what i mean by break is give point someone to pi that is down.

stickyness would be a nice to have but definitely not required.
I will definitely consider making my own but i will look into haproxy first
Thank You for all the help

1 Like

Is there a requirement to preserve the user’s Data if the Pi goes down? Ie if they are logged into a Pi, the session goes down, the get logged into a different Pi, do they need their data to be there too, with command history?

If you don’t need a common home between the PIs, HaProxy will be able to do the load balancing, and with some additional scripting, also dynamically adjust the amount of sessions to the PIs based on their load:

This is what you want to read:

If you feel brave, and want to improve your setup and use common homes, you will need to setup a NAS based boot environment for the raspberries, this is what you want to read to get started:

1 Like

Im using a nfs share for the home Dir so its external from the pis.

1 Like

Correct me if im wrong but this will work with a nfs home dir.

I would love to network boot them but the current network cant support the traffic as it is the just having a nfs home Dir is interesting.

You didn’t say what the users are doing on the pis. Assuming all they need is their files, yes it will work …

Fair the pies are for a class learning arm assembly so all of there work will be in the home dir.

1 Like