From 17d1e901c0d6bf3d012b73da25e4a6ee5eb435a6 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Wed, 28 Feb 2024 22:46:37 +0800 Subject: [PATCH] Bootstrap config upgrade - only IPVS for access, no docker's portforwarding - generate random password - generate config for collectd's curl_json --- docker-compose/docker-compose.yml | 3 +- docker-compose/start-loadbalancer.sh | 66 +++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml index 2cc1a1c3..681ecd96 100644 --- a/docker-compose/docker-compose.yml +++ b/docker-compose/docker-compose.yml @@ -4,7 +4,6 @@ services: bootstrap: image: pybitmessage/bootstrap:latest build: .. - ports: - - 127.0.0.1::8444 + env_file: .env deploy: replicas: $THREADS diff --git a/docker-compose/start-loadbalancer.sh b/docker-compose/start-loadbalancer.sh index 7e763076..82c4a84c 100755 --- a/docker-compose/start-loadbalancer.sh +++ b/docker-compose/start-loadbalancer.sh @@ -1,10 +1,19 @@ #!/bin/bash -apt -y install curl jq ipvsadm +apt -y install curl jq ipvsadm libyajl2 EXTIP=$(curl -s telnetmyip.com|jq -r .ip) -THREADS=$(nproc --all) -echo "THREADS=$THREADS" > .env +if [ ! -e .env ]; then + THREADS=$(nproc --all) + PASSWORD=$(tr -dc a-zA-Z0-9 < /dev/urandom | head -c32 && echo) + cat > .env << EOF +THREADS=$THREADS +USER=pybitmessage +PASSWORD=$PASSWORD +EOF +else + . .env +fi ipvsadm -C ipvsadm -A -t ${EXTIP}:8444 -s rr @@ -12,13 +21,46 @@ ipvsadm -A -t ${EXTIP}:8080 -s rr docker compose up -d -for i in `seq 1 $THREADS`; do - cont="pybitmessage-bootstrap-${i}" - IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $cont 2>/dev/null) - [ -z "$IP" ] && continue - echo "Adding $IP" - ipvsadm -a -t ${EXTIP}:8444 -r ${IP}:8444 -m - ipvsadm -a -t ${EXTIP}:8080 -r ${IP}:8444 -m -done +CF=/etc/collectd/collectd.conf.d/curl_json.conf -ipvsadm -l +echo "LoadPlugin curl_json" > $CF +echo "" >> $CF + +for i in `seq 1 $THREADS`; do + cont="pybitmessage-bootstrap-${i}" + IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $cont 2>/dev/null) + [ -z "$IP" ] && continue + echo "Adding $IP" + ipvsadm -a -t ${EXTIP}:8444 -r ${IP}:8444 -m + ipvsadm -a -t ${EXTIP}:8080 -r ${IP}:8444 -m + INSTANCE=$(echo $cont|tr - _) + cat >> $CF << EOF + + Plugin "pybitmessagestatus" + Instance "$INSTANCE" + User "pybitmessage" + Password "$PASSWORD" + Post "{\"jsonrpc\":\"2.0\",\"id\":\"id\",\"method\":\"clientStatus\",\"params\":[]}" + + Type "gauge" + Instance "networkconnections" + + + Type "counter" + Instance "numberofpubkeysprocessed" + + + Type "counter" + Instance "numberofmessagesprocessed" + + + Type "counter" + Instance "numberofbroadcastsprocessed" + + +EOF +done +echo "" >> $CF +systemctl restart collectd + +ipvsadm -l -n