Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/umputun/rlb
Redirecting Load Balancer
https://github.com/umputun/rlb
http-proxy http-redirect load-balancer
Last synced: 14 days ago
JSON representation
Redirecting Load Balancer
- Host: GitHub
- URL: https://github.com/umputun/rlb
- Owner: umputun
- License: mit
- Created: 2018-10-07T19:32:59.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-01T00:17:15.000Z (3 months ago)
- Last Synced: 2024-10-16T09:20:33.278Z (25 days ago)
- Topics: http-proxy, http-redirect, load-balancer
- Language: Go
- Homepage:
- Size: 3.25 MB
- Stars: 40
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RLB - Redirecting Load Balancer
[![Build Status](https://github.com/umputun/rlb/workflows/build/badge.svg)](https://github.com/umputun/rlb/actions) [![Coverage Status](https://coveralls.io/repos/github/umputun/rlb/badge.svg)](https://coveralls.io/github/umputun/rlb) [![Go Report Card](https://goreportcard.com/badge/github.com/umputun/rlb)](https://goreportcard.com/report/github.com/umputun/rlb) [![Docker Automated build](https://img.shields.io/docker/automated/jrottenberg/ffmpeg.svg)](https://hub.docker.com/r/umputun/rlb/)This service redirects incoming `GET` and `HEAD` requests (with 302) to the upstream servers.
Servers picked up randomly, unhealthy boxes excluded dynamically._Note: This is not a replacement for reverse proxy. All it does is HTTP redirect, not the real network proxying._
To visualise the redirected content popularity statistics, you can use [rlb-stats](https://github.com/umputun/rlb-stats).
## Install
1. Copy provided `docker-compose.yml`
1. Make `rlb.yml` config for your service(s) (see `rlb-sample.yml` below in [Config file format](#config-file-format) section).
1. Start container with `docker-compose up -d`This will start rlb on port `:7070` by default and requests like `http://host/api/v1/jump/service1?url=/files/blah.mp3` will be redirected to the one of upstreams.
## API
* GET|HEAD `/api/v1/jump/?url=/blah/blah2.mp3` – returns 302 redirect to destination server
* GET|HEAD `/?url=/blah/blah2.mp3` – same as above## Failback support (optional)
This allow to check the upstreams health for the requested resource and failback to a predefined servers if request fails. `failback` defined in the config file and in case if non-empty will add an additional `HEAD` request to the final URL. If request returns 200, the request will be passed to the upstream, if not - the result will be assembled from the `failback` + resource. I.e. if `failback` is `http://failback.com/` and resource is `/files/blah.mp3` then the final URL will be `http://failback.com/files/blah.mp3`.
## Config file format
```yaml
# top level services
service1:
n1: # node id
server: http://n1.radio-t.com # base url
ping: /rtfiles/rt_podcast480.mp3 # ping url to check node's health
method: HEAD # ping method, uses HEAD if nothing defined
weight: 1 # relative weight of the node [1..n]n2:
server: http://n2.radio-t.com
ping: /rtfiles/rt_podcast480.mp3
method: HEAD
weight: 1n3:
server: http://n3.radio-t.com
ping: /rtfiles/rt_podcast480.mp3
method: HEAD
weight: 5 # this node will get 5x hits comparing to n1 and n2service2:
n1:
server: http://n1.radio-t.com
ping: /rtfiles/rt_podcast480.mp3
method: GET
weight: 1n2:
server: http://n2.radio-t.com
ping: /rtfiles/rt_podcast480.mp3
method: GET
weight: 3n3:
server: http://n3.radio-t.com
ping: /rtfiles/rt_podcast480.mp3
method: GET
weight: 1failback: http://archives.radio-t.com/media
```## Stats
RLB does not implement any statistics internally but supports external service for requests like this:
```go
type LogRecord struct {
ID string `json:"id,omitempty"` // uniuque id
FromIP string `json:"from_ip"` // source ip
TS time.Time `json:"ts,omitempty"` // timestamp
Fname string `json:"file_name"` // requested file name
Servcie string `json:"service"` // requested service
DestHost string `json:"dest"` // picked destination node
}
```If stats url defined in command line or environment, each redirect will also hit stats url (`POST`) with `LogRecord` in body.
## Parameters```
Usage:
main [OPTIONS]Application Options:
-p, --port= port (default: 7070) [$PORT]
-c, --conf= configuration file (default: rlb.yml) [$CONF]
-r, --refresh= refresh interval (default: 30) [$REFRESH]
-t, --timeout= HEAD/GET timeouts (default: 5) [$TIMEOUT]
-s, --stats= stats url [$STATS]
--dbg debug mode [$DEBUG]```
## Status
RLB runs in production for several years and serves downloads from [radio-t](https://radio-t.com)