diff --git a/scripts/nlb/addTargetNode.sh b/scripts/nlb/addTargetNode.sh new file mode 100755 index 000000000..a14eecbc2 --- /dev/null +++ b/scripts/nlb/addTargetNode.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +nodeId=${1:-vm} +nodeIp=${2:-127.0.0.1} +targetPort=${3:-80} + +## haproxy can be replaced + +echo " server ${nodeId} ${nodeIp}:${targetPort} check" | sudo tee -a /etc/haproxy/haproxy.cfg + +## show config +cat /etc/haproxy/haproxy.cfg diff --git a/scripts/nlb/applyConfig.sh b/scripts/nlb/applyConfig.sh new file mode 100755 index 000000000..a07fdb1cf --- /dev/null +++ b/scripts/nlb/applyConfig.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +## haproxy can be replaced + +sudo systemctl restart haproxy +cat /etc/haproxy/haproxy.cfg diff --git a/scripts/nlb/deployNlb.sh b/scripts/nlb/deployNlb.sh new file mode 100755 index 000000000..ba4b23116 --- /dev/null +++ b/scripts/nlb/deployNlb.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +mcisId=${1:-mcis} +listenMode=${2:-tcp} +listenPort=${3:-80} +balanceAlgo=${4:-roundrobin} + +## haproxy can be replaced +sudo apt update > /dev/null +sudo apt install haproxy -y > /dev/null +sudo systemctl enable haproxy +haproxy -v + +## show config +cat /etc/haproxy/haproxy.cfg + +echo " +## define admin page for statistics dashboard +listen admin + bind *:9000 + mode http + stats enable + stats refresh 10s + stats uri / + stats auth default:default" | sudo tee -a /etc/haproxy/haproxy.cfg + +echo " +## define frontend +frontend ${mcisId}.frontend + bind *:$listenPort + mode $listenMode + default_backend ${mcisId}.backend + option forwardfor" | sudo tee -a /etc/haproxy/haproxy.cfg + +echo " +## define backend +backend ${mcisId}.backend + balance ${balanceAlgo}" | sudo tee -a /etc/haproxy/haproxy.cfg + +## show config +cat /etc/haproxy/haproxy.cfg