【记录】GOST 进行 SOCKS5 的负载均衡

Last updated on January 20, 2024 pm

准备工作

1
2
3
sudo docker network create cswitch
sudo docker run --rm --net=cswitch alpine/curl --socks5-hostname hysteria01:1580 https://myip.ipip.net
sudo docker run --rm --net=cswitch alpine/curl --socks5-hostname hysteria02:1580 https://myip.ipip.net

负载均衡

1
2
3
mkdir -p ~/app/gost && cd ~/app/gost && nano docker-compose.yml
sudo docker-compose up -d && sudo docker-compose logs
sudo docker run --rm --net=cswitch alpine/curl --socks5-hostname gost:8580 https://myip.ipip.net
1
2
3
4
5
6
7
8
9
10
11
12
13
version: '3.3'
services:
gost:
restart: unless-stopped
ports:
- '8580:8580'
image: ginuerzh/gost
command: -L=:8580 -F=socks5://localhost:1580?ip=hysteria01:1580,hysteria02:1580

networks:
default:
external: true
name: cswitch

健康检查

1
2
3
4
nano Health_check.sh
# chmod +x Health_check.sh
# dos2unix Health_check.sh
/home/limour/app/hysteria01/Health_check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash

COMPOSE_FILE=/home/limour/app/hysteria01/docker-compose.yml

while true; do
output=$(sudo docker run --rm --net=cswitch alpine/curl -fs --socks5-hostname hysteria01:1580 https://www.google.com/robots.txt)
if [ $? -eq 0 ]; then
echo "Health check successful"
else
echo "Health check failed"
sudo docker-compose -f $COMPOSE_FILE restart
fi
sleep 300
done

定时检查

1
2
3
4
5
6
7
8
9
10
nano Health_check.sh
# chmod +x Health_check.sh
# dos2unix Health_check.sh
/home/limour/app/hysteria01/Health_check.sh
crontab -e
* * * * * /usr/bin/sudo /home/limour/app/hysteria01/Health_check.sh
* * * * * /usr/bin/sudo /home/limour/app/hysteria02/Health_check.sh
crontab -l
# sudo dpkg-reconfigure postfix
tail /var/spool/mail/limour
1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash

COMPOSE_FILE=/home/limour/app/hysteria02/docker-compose.yml

output=$(sudo docker run --rm --net=cswitch alpine/curl -fs --socks5-hostname hysteria02:1580 https://www.google.com/robots.txt)
if [ $? -eq 0 ]; then
echo "Health check successful"
else
echo "Health check failed"
sudo docker-compose -f $COMPOSE_FILE restart
fi

【记录】GOST 进行 SOCKS5 的负载均衡
https://hexo.limour.top/-ji-lu-GOST-jin-xing-SOCKS5-de-fu-zai-jun-heng
Author
Limour
Posted on
July 22, 2023
Updated on
January 20, 2024
Licensed under