2023-07-22-【记录】GOST-进行-SOCKS5-的负载均衡.md 3.0 KB


title: 【记录】GOST 进行 SOCKS5 的负载均衡 urlname: -ji-lu-GOST-jin-xing-SOCKS5-de-fu-zai-jun-heng date: 2023-07-22 20:22:32 index_img: https://api.limour.top/randomImg?d=2023-07-22 20:22:32 tags: ['gost', 'socks5']

excerpt: 这段文本主要是关于准备工作、负载均衡、健康检查和定时检查的内容。首先是创建一个名为"cswitch"的docker网络,并使用alpine/curl容器测试SOCKS5转QUIC的连接。然后是设置负载均衡,创建一个名为"gost"的容器,并将其映射到8580端口,使用ginuerzh/gost镜像,并配置连接到hysteria01和hysteria02的SOCKS5代理。接下来是健康检查,创建一个名为Health_check.sh的脚本,用于定期检查连接到hysteria01的健康状态,并在失败时重新启动。最后是定时检查,设置定时任务来运行Health_check.sh脚本,并重新配置postfix以接收通知邮件。

准备工作

  • SOCKS5 转 QUIC

    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
    

    负载均衡

    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
    
    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
    

健康检查

nano Health_check.sh
# chmod +x Health_check.sh 
# dos2unix Health_check.sh 
/home/limour/app/hysteria01/Health_check.sh
#!/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

定时检查

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
#!/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