• Stars
    star
    452
  • Rank 96,441 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple socks5 proxy load balance and transparent proxy

socks5lb,简单的 Socks5 代理负载均衡

socks5lb

有时候我们在使用 Socks5 Proxy 无法联通的情况,这有可能是因为网络或者线路的调整和波动,这时候往往需要我们自己手工的切换节点,非常的麻烦。

这个工具就是为了解决上述问题而编写的,它简单的说就是个针对 Socks5 Proxy 的前置负载均衡,能够提供经过检验的稳定可靠的 Socks Proxy 节点。

如果是针对 Linux 系统下同时能够提供透明代理以及针对 Socks5 协议的转换,而且方便搭配 ipset 以及 iptables 使用。

目前实现的部分特性有:

  • 能够提供 Socks5 Proxy 的负载均衡(轮询机制)同时提供健康检查;
  • 针对 Linux 提供透明代理以及 Socks5 的协议转换;
  • 使用 Golang 编写,跨平台部署(例如部署到各种路由器上)和配置方便。

更新记录

  • 20220716 修复部分链接的性能问题,增加 HTTP 管理接口
  • 20220706 完成针对 Linux 的透明网关功能
  • 20220620 完成基本功能

编译

建议使用 docker-compose 编译生成镜像文件,直接执行 docker-compose build 即可。

配置

首先是针对 socks5lb 的基本配置,例如以下的配置配置了三个 Socks5 Proxy 同时暴露到本地的 1080 端口,针对 Linux 的透明代理暴露在 8848 端口。

server:
  http:
    addr: ":8080"
  socks5:
    addr: ":1080"
  tproxy:
    addr: ":8848"
backends:
  - addr: 192.168.100.254:1086
    check_config:
      check_url: https://www.google.com/robots.txt
      initial_alive: true
      timeout: 3
  - addr: 10.1.0.254:1086
    check_config:
      check_url: https://www.google.com/robots.txt
      initial_alive: false
      timeout: 30
  - addr: 172.16.100.254:1086
    check_config:
      check_url: https://www.google.com/robots.txt
      initial_alive: true
      timeout: 3

环境变量

  • SELECT_TIME_INTERVAL 自动切换代理的时间,单位为秒(默认 300 秒,五分钟)
  • CHECK_TIME_INTERVAL 健康检查的轮询时间,单位为秒(默认一分钟、60 秒)
  • DEBUG 是否打开 debug 模式

部署

首先,以下是 docker-compose 相关的配置,建议使用 network_mode: 'host' 方式,防止 DOCK 的 iptables 造成网络联通错误

version: "3"
services:
  socks5lb:
    image: ghcr.io/mingcheng/socks5lb:latest
    restart: always
    dns:
      - 8.8.8.8
      - 8.8.4.4
    environment:
      TZ: "Asia/Shanghai"
      CHECK_TIME_INTERVAL: 3600
    network_mode: "host"
    privileged: true
    volumes:
      - ./socks5lb.yml:/etc/socks5lb.yml:ro

然后配置(供参考)iptable 参数,将所有的流量都通过 8848 代理端口转发(注意 redrock 链没有定义,请自行配置)。

iptables -t nat -I PREROUTING -p tcp -m set --match-set redrock dst -j REDIRECT --to-ports 8848
iptables -t nat -I OUTPUT -p tcp -m set --match-set redrock dst -j REDIRECT --to-ports 8848

Web 管理

自 1.1.0 版本实现了个简单的 Web 管理接口,用于动态的添加和删除代理服务器的配置,简单的说明如下:

GET /version

目前运行的版本、编译时间以及运行时间

GET /api/all

显示目前配置的代理服务器列表,如果加 healthy=true 参数,则只显示目前健康的代理节点

PUT /api/add

增加代理,这里说明下 Put 的 Body 为 JSON 数组,同时配置和代理的配置对应,例如

[
  {
    "addr": "192.168.1.254:1086",
    "check_config": {
      "check_url": "https://www.taobao.com/robots.txt"
    }
  },
  {
    "addr": "192.168.1.254:1087",
    "check_config": {
      "initial_alive": true
    }
  }
]

然后返回的是已经加入的代理节点数量(整型数)。如果已经有配置的代理节点,则需要先删除以后再加入。

示例 CURL 如下:

curl -X "PUT" "<your-address>/api/add" \
     -H 'Content-Type: text/plain; charset=utf-8' \
     -d $'[
  {
    "addr": "192.168.1.1:1086",
    "check_config": {
      "check_url": "https://www.taobao.com/robots.txt"
    }
  }
]'

DELETE /api/delete

删除指定的代理地址,参数 addr 指定参数名称。

curl -X "DELETE" "http://localhost:8080/api/delete?addr=192.168.1.1:1086"

常见问题

如果我不想针对某个节点健康检查呢(强制使用)?

那么可以配置节点 check_url 参数为空,然后默认 initial_alivetrue 即可,例如:

backends:
  - addr: 127.0.0.1:10860
    check_config:
      initial_alive: true

在其他非 Linux 系统下可以使用 tproxy_listen 这个配置吗?

不好意思,透明代理只针对 Linux 平台,所以如果是非 Linux 平台,请留空对应的配置。

有没有类似功能的项目?

More Repositories

1

php-readability

Back the fun of reading - PHP Port for Arc90′s Readability
PHP
521
star
2

chrome-plugin-to-replace-fuck-flash-player

将中国大陆主流视频网站的 Flash 播放器替换为 HTML5 播放器
JavaScript
490
star
3

AQI

Air Quality Index (AQI) history database for mainland China
PHP
199
star
4

dell-optiplex-9020m-hackintosh

Hackintosh for Dell OptiPlex 9020m, including configures and tools.
167
star
5

Tracker

在 Android 手机中记录 GPS 轨迹并显示、统计、和输出
Java
146
star
6

iZhihu

随时随地获得「知乎」每日最新精选内容!(停止维护)
Java
116
star
7

deploy-k8s-within-aliyun-mirror

使用阿里云镜像快速部署 Kubernetes 集群
100
star
8

lenovo-thinkcentre-m93p-hackintosh

Mixed configurations and tools for Lenovo M93P Hackintosh
93
star
9

Rainville

Rain Noise for Android
Java
83
star
10

pornhub-dl

NFSW: A minimalistic command-line application to download videos from PornHub.
Go
47
star
11

Presentation

读图时代,从「花瓣」(huaban.com)上阅读每日更新的数据图
Java
47
star
12

Gojuon

Material 风格的日语五十音助记软件
Java
42
star
13

obsync

国内主流云对象存储服务同步工具
Go
22
star
14

prometheus-on-phicomm-n1

在 Phicomm(斐讯)N1 上部署 Prometheus 和 Grafana
18
star
15

chrome-plugin-simple-qr-generator

Chrome 小插件,简单 QR 码生成器:生成当前页面的 QR 码
JavaScript
16
star
16

my-vertx-scaffold

基于 Vert.x 的简单脚手架,整合使用了 gRPC、RxJava 等库
Java
9
star
17

icurl

Online cURL debug proxy
PHP
8
star
18

android-bluetooth-gps-provider

Connect to an external bluetooth NMEA compatible GPS device.
8
star
19

prometheus-smart-exporter

Simple S.M.A.R.T disk export for Prometheus
Shell
8
star
20

genpasswd

A simple password generator written in golang.
Go
6
star
21

resource-compiler

Online CSS, Javascript compiler tool
PHP
6
star
22

raspberry-pi3-syncthing

Syncthing(including discovery & relay server) Docker image for Raspberry Pi3 (arm32v7) platform.
Dockerfile
6
star
23

pidfile

This package provides structure and helper functions to create and remove PID file.
Go
6
star
24

creole-wiki-parser

Creole Wiki Parser // Creole Wiki 语法解析器
PHP
5
star
25

upyun-cli

基于又拍云 Python SDK https://github.com/upyun/python-sdk 的命令行工具
Python
5
star
26

NOKIA5110-LCD

Arduino library for Nokia 5110 Graphic LCD(PCD854) with tiny foot.
C++
5
star
27

simplyddns

根据指定的 IP 地址,动态更新对应的 DNS 记录。
Go
4
star
28

ghoul

Tiny sqlite blog platform with some nice apis.
PHP
4
star
29

url-zipper

A tool for batch short url quickly and easily
PHP
3
star
30

php-emojify

PHP Emojify - The PHP Port of Emojify
PHP
3
star
31

boot-arch-on-32bit-efi

Boot 64bit Linux(eg. Arch) on 32bit EFI / 在 32 位 EFI 上启动 64 位的 Linux
2
star
32

lenovo-p310-e3-rx560-hackintosh

A Hackintosh for Xeno E3-1231
2
star
33

motion.js

Tiny & simiple javascript motion toolkit
JavaScript
2
star
34

apcupsd_guarder

跨平台的 APC UPS 守护和监控进程
Go
1
star
35

Invoke-Golang

针对 Windows 的 Golang 多版本管理工具
PowerShell
1
star
36

i3wm.conf

明城的 i3wm 配置,以及相关的环境配置文件和脚本
1
star
37

north-korea

朝鲜行,普通人眼中的朝鲜
HTML
1
star