wojons / cloudflare-lb

Use cloudflare as a load balancer
MIT License
46 stars 13 forks source link

cloudflare-lb

Use cloudflare as a load balancer!!! This is a very simple roundrobin load balancer using the cloudflre api to add and remove nodes from a pool. This code base does support a healthcheck to make sure the node is avaiable but your milage may varr depending on the type of aviaablity checking you need.

Requirments

Setup

HOSTS    = [
            ['127.0.0.1', 'A'], 
            ['127.0.0.2', 'A'], 
            ['127.0.0.3', 'A'], 
            ['127.0.0.4', 'A'], 
            ['127.0.0.5', 'A']
           ] # Your A/AAAA value, i.e. 192.168.1.10
PROTO    = 'http'                 # http or https
PORT     = 80                     #Defaults to port 80
API      = ''                     # Your CloudFlare client API key found at https://www.cloudflare.com/my-account
EMAIL    = 'example@example.com'  # Your CloudFlare email address
RECORD   = 'lb'                   # where you want the load balancer
DOMAIN   = 'example.com'          # Use DOMAIN if this is for the root domain
TTL      = 1                      # Set TTL
RECS     = []                     # RECORDS
INTERVAL = 60                     #how long we wait between runs

Running

$ python cloudflare-lb.py

That will kick the script off it does log things to stdout. You may wanna just point it to /dev/null if you dont care or a file or something for your records. It does not run as a service but if you use a processes manaager like supervsor. If you want to run this in crontab. Set INTERVAL = 0. This will cause the program to not run in a loop.

Issues