Load Balancing SSH Connections using Pen, a load balancer for “simple” tcp based protocols such as http or smtp.
It allows several servers to appear as one to the outside and automatically detects servers that are down and distributes clients among the available servers. This gives high availability and scalable performance.
We will use CentOS for this example:
yum install pen
You can also build it from source but this is not in the scope of this tutorial.
Run Pen on Startup
Pen supports a config file located at /etc but in order to use pen for multiple port balancing you will need to launch it manually.
We have created a manual startup command and added it to /etc/rc.d/rc.local
You will need to add this command for every Port you want to balance.
Pen Command Overview
-w - Web export file location -x - Amount of session -l - Log file location -C - Local Port (Make sure it is not used by anything else) -S - Amount of servers -r - Remote Port to balance
Load Balancing SSH using Pen
You can use Pen to load balance Secure Shell sessions – port 22,
To enable on startup – add this command to /etc/rc.d/rc.local:
/usr/bin/pen -w /var/www/html/stats.html -x 500 -l /var/log/pen.log -C 127.0.0.1:10022 -S 4 -r 22 10.0.0.111:22 10.0.0.112:22 10.0.0.113:22 10.0.0.114:22
Pen Web Interface
Pen supports exporting session information to an html page so you can enable httpd and monitor the sessions and servers status:
yum install httpd chkconfig httpd on service httpd start
Create an update script
press “a” to get into edit mode and paste your content.
#!/bin/bash /usr/bin/penctl 127.0.0.1:10022 status > /var/www/html/index.html
use “esc” and then “shit+q” and finally save with “x” press enter.
Schedule script to run periodicity:
use “crontab -e” to edit crontab:
*/1 * * * * root /scripts/penwebd.sh