Difference between revisions of "Haproxy"
Jump to navigation
Jump to search
(15 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | 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 | ||
+ | - https://cbonte.github.io/haproxy-dconv/2.0/management.html | ||
+ | |||
+ | ## Hitless reload | ||
+ | |||
+ | - https://opendev.org/opendev/system-config/commit/df23d48949d6b27165fb1f3885f6e307a4c37b00 | ||
+ | - https://www.haproxy.com/blog/hitless-reloads-with-haproxy-howto/ | ||
+ | |||
+ | |||
+ | |||
``` | ``` | ||
frontend stats | frontend stats | ||
Line 28: | Line 62: | ||
haproxy = HAProxyServer('127.0.0.1:8404/stats') app = Flask(__name__) | haproxy = HAProxyServer('127.0.0.1:8404/stats') app = Flask(__name__) | ||
− | |||
− | |||
− | |||
− | |||
from flask import Flask | from flask import Flask | ||
app = Flask(__name__) | app = Flask(__name__) | ||
− | + | ||
− | def | + | @app.route("/") @app.route("/") |
+ | def stats(): | ||
json_data = haproxy.to_json() | json_data = haproxy.to_json() | ||
json_data = json.loads(json_data) | json_data = json.loads(json_data) | ||
Line 55: | Line 86: | ||
data['10.x.x.x']['backends'][2]['listeners'][1]['status'] # o: UP | 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']) | ||
+ | ``` | ||
``` | ``` | ||
Line 77: | Line 113: | ||
haproxy.to_json() | haproxy.to_json() | ||
``` | ``` | ||
+ | |||
+ | # SaltStack | ||
+ | |||
+ | - https://www.digitalocean.com/community/tutorials/saltstack-infrastructure-creating-salt-states-for-haproxy-load-balancers | ||
+ | - https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.haproxyconn.html | ||
+ | - https://docs.oracle.com/en/operating-systems/oracle-linux/6/admin/section_sm3_svy_4r.html |
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://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
- https://opendev.org/opendev/system-config/commit/df23d48949d6b27165fb1f3885f6e307a4c37b00
- https://www.haproxy.com/blog/hitless-reloads-with-haproxy-howto/
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
- http://10.x.x.x:8404/stats
- http://10.x.x.x:8404/stats?stats;csv;norefresh
- https://github.com/bcicen/haproxy-stats
#!/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()