Difference between revisions of "Haproxy"

From UVOO Tech Wiki
Jump to navigation Jump to search
 
Line 1: Line 1:
 
https://www.haproxy.com/blog/haproxy-ssl-termination/
 
https://www.haproxy.com/blog/haproxy-ssl-termination/
 +
 +
https://www.haproxy.org/download/2.6/doc/configuration.txt
  
 
https://www.haproxy.com/blog/how-to-run-haproxy-with-docker/
 
https://www.haproxy.com/blog/how-to-run-haproxy-with-docker/

Latest revision as of 20:50, 25 July 2022

https://www.haproxy.com/blog/haproxy-ssl-termination/

https://www.haproxy.org/download/2.6/doc/configuration.txt

https://www.haproxy.com/blog/how-to-run-haproxy-with-docker/

https://github.com/haproxytech/haproxy-lua-cors/blob/master/docker-compose.example.yml

https://www.haproxy.com/blog/enabling-cors-in-haproxy/

https://github.com/haproxytech/haproxy-lua-cors

https://medium.com/trabe/multiple-ssl-configurations-in-the-same-ip-port-with-haproxy-349c7dc9a170

https://infohubblog.com/important-haproxy-sticky-sessions-tutorial.html

https://superuser.com/questions/1193917/how-to-view-haproxy-status-on-the-command-line-using-a-socket

https://www.haproxy.com/blog/exploring-the-haproxy-stats-page/

https://github.com/yeasy/docker-compose-files/blob/master/haproxy_web/haproxy/haproxy.cfg

Master CLI

Hitless reload

frontend stats
    bind *:8404
    stats enable
    stats uri /stats
    stats refresh 10s
    stats admin if LOCALHOST
    mode http
    # stats auth admin:admin
    # acl network_allowed src 10.x.x.x 1.1.1.1 2.2.2.2 10.0.0.0/8
    # stats admin if network_allowed
#!/usr/bin/env python3
# This creates a http server for getting stats.                                                                                                                                    
# You could easily write a simple loop to pump telemetry data somewhere via http post
# You could setup cache to limit queries to proxy data.

import json
from flask import Flask
from haproxystats import HAProxyServer                                                                                                                                             
haproxy = HAProxyServer('127.0.0.1:8404/stats')                                                                                                                                   app = Flask(__name__)


from flask import Flask
app = Flask(__name__)


@app.route("/")                                                                                                                                                                             @app.route("/")
def stats():
    json_data = haproxy.to_json()
    json_data = json.loads(json_data)
    json_data = json.dumps(json_data, indent=4, sort_keys=True)
    return json_data

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=3333)

Let's look at some data from the above

import requests
r = requests.get("http://127.0.0.1:3333")
data = r.json() 
data['10.x.x.x']['backends'][2]['listeners'][1]['name']  # o: haptest2
data['10.x.x.x']['backends'][2]['listeners'][1]['status']  # o: UP

More fun

for x in  data['127.0.0.1']['backends']:
    for y in x['listeners']:
        print(y['name'], y['status'])
#!/usr/bin/env python3
import time
from haproxystats import HAProxyServer
haproxy = HAProxyServer('10.64.4.51:8404/stats')
while True:
    json = haproxy.to_json()
    time.sleep(5)
    print(json)
from haproxystats import HAProxyServer
haproxy = HAProxyServer('10.64.4.51:8404/stats')

for b in haproxy.backends:
    print('%s: %s' % (b.name, b.status))

haproxy.to_json()

SaltStack