tinybalancer is a reverse proxy load balancer that supports http and https.
- It currently supports four algorithms, namely
round-robin
,random
,the power of 2 random choice
andconsistent hash
. - tinybalancer will periodically perform
healthcheck
on all proxy sites. When the site is unreachable, it will be automatically removed from the balancer. However, tinybalancer will still performhealthcheck
on unreachable sites. When the site is reachable, it will automatically add it to the balancer.
First download the source code of balancer:
> git clone https://github.com/zehuamama/tinybalancer.git
compile the source code:
> cd ./tinybalancer
> go build
Balancer needs to configure the config.yaml
file, the content is as follows:
# Copyright 2022 <mzh.scnu@qq.com>. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# The load balancing algorithms supported by the balancer are:
# `round-robin` ,`random` ,`p2c`,`consistent-hash`,
# Among these,`p2c` refers to the power of 2 random choice.
schema: http # support http and https
port: 8089 # port for balancer
ssl_certificate:
ssl_certificate_key:
tcp_health_check: true
location: # route matching for reverse proxy
- pattern: /
proxy_pass: # URL of the reverse proxy
- "http://127.0.0.1:1012"
- "http://127.0.0.1:1013"
balance_mode: round-robin # load balancing algorithm
and now, you can execute tinybalancer
, the balancer will print the ascii diagram and configuration details:
> ./tinybalancer
___ _ _ _ _ _ ___ ____ _ ____ _ _ ____ ____ ____
| | |\ | \_/ |__] |__| | |__| |\ | | |___ |__/
| | | \| | |__] | | |___ | | | \| |___ |___ | \
Schema: http
Port: 8089
Location:
Route: /
ProxyPass: [http://127.0.0.1:1012 http://127.0.0.1:1013]
Mode: round-robin