HAProxy: Difference between revisions
Jump to navigation
Jump to search
Line 130: | Line 130: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== | ==Playground== | ||
{| | {| | ||
|valign= | | valign="top" | | ||
<syntaxhighlight lang="bash"> | |||
lxc image info ubuntu:noble --vm|yq .Aliases | |||
lxc image info ubuntu:24.04 --vm|yq .Aliases | |||
| | lxc image info ubuntu:noble |yq .Aliases | ||
lxc image info ubuntu:24.04 |yq .Aliases | |||
</syntaxhighlight> | |||
|valign='top | | colspan="2" | | ||
<syntaxhighlight lang="bash"> | |||
lxc image list ubuntu: os=ubuntu release=noble type=virtual-machine | |||
lxc image list ubuntu: os=ubuntu release=noble type=virtual-machine | |||
lxc image list ubuntu: os=ubuntu release=noble type=container | |||
lxc image list ubuntu: os=ubuntu release=noble type=container | |||
</syntaxhighlight> | |||
|- | |||
| colspan="3" | | |||
---- | |||
|- | |||
| valign="top" | | |||
<syntaxhighlight lang="bash"> | |||
lxc image list ubuntu:24.04 | |||
lxc launch ubuntu:24.04 haproxy | |||
lxc launch ubuntu:40d8df642812 haproxy | |||
</syntaxhighlight> | |||
| colspan="2" | | |||
<syntaxhighlight lang="bash"> | |||
lxc list status=running name=haproxy --format=json |jq -r '.[].state.network.[].addresses' | |||
lxc list status=running name=haproxy --format=yaml |yq -r '.[].state.network.[].addresses' | |||
lxc info haproxy|yq '.Resources.["Network usage"][]["IP addresses"].inet' | |||
</syntaxhighlight> | |||
|- | |||
| colspan="3" | | |||
---- | |||
|- | |||
| valign="top" | | |||
<syntaxhighlight lang="bash"> | |||
sudo ss -tulwn | grep LISTEN | |||
sudo ss -tulpn | grep LISTEN | |||
sudo ss -tulpn | grep LISTEN | grep sshd | |||
</syntaxhighlight> | |||
| colspan="2" | | |||
<syntaxhighlight lang="bash"> | |||
lxc snapshot haproxy base:2.6.7 | |||
lxc publish haproxy/base:2.6.7 --alias haproxy/base:2.6.7 | |||
lxc restore haproxy base:2.6.7 | |||
</syntaxhighlight> | |||
|- | |- |
Revision as of 01:27, 4 February 2025
sudo apt install haproxy sudo apt install --no-install-recommends software-properties-common sudo add-apt-repository ppa:vbernat/haproxy-2.4 -y sudo apt install haproxy=2.4.\* haproxy -v
Load Balancing
frontend chorke-http bind *:80 mode http default_backend chorke-minio backend chorke-minio server minio1 127.0.0.1:1983 mode http
Reverse Proxy
frontend chorke-http bind *:80 mode http acl host-is-chorke hdr(host) -i chorke.local acl path-prefix-is-services path_beg /services/ use_backend chorke-servers if host-is-chorke path-prefix-is-services use_backend chorke-clients if host-is-chorke backend chorke-servers server apache 127.0.0.1:2013 mode http backend chorke-clients server apache 127.0.0.1:3000 mode http |
# acl path-prefix-is-pgadmin4 path_beg /pgadmin4 # acl path-prefix-is-gateway path_beg /data/ OR path_beg /user/ OR path_beg /policy/ # acl path-prefix-is-gateway path_beg /data/ && path_beg /user/ && path_beg /policy/ # use_backend chorke-servers if host-is-chorke path-prefix-is-gateway # use_backend chorke-servers if path-prefix-is-pgadmin4 frontend chorke-http bind *:80 mode http acl path-prefix-is-minio path_beg /minio/ use_backend chorke-minio if path-prefix-is-minio backend chorke-minio server minio1 127.0.0.1:9801 mode http |
HTTP Rewrite
frontend academia
bind *:80
mode http
acl host-is-academia-flow hdr(host) -i flow.academia.local
acl host-is-academia hdr(host) -i academia.local
acl is-insurance path_beg /services/insurance/
acl is-policy path_beg /services/policy/
acl is-quote path_beg /services/quote/
acl is-audit path_beg /services/audit/
acl is-data path_beg /services/data/
acl is-user path_beg /services/user/
acl is-tds path_beg /services/tds/
use_backend academia-insurance if host-is-academia is-insurance
use_backend academia-policy if host-is-academia is-policy
use_backend academia-quote if host-is-academia is-quote
use_backend academia-audit if host-is-academia is-audit
use_backend academia-data if host-is-academia is-data
use_backend academia-user if host-is-academia is-user
use_backend academia-tds if host-is-academia is-tds
use_backend academia-flow if host-is-academia-flow
use_backend academia-admin if host-is-academia
default_backend academia-apache
backend academia-apache
server apache 127.0.0.1:2013
mode http
backend academia-insurance
http-request set-path "%[path,regsub(^/services/insurance/,/)]"
server tomcat 127.0.0.1:16002
mode http
backend academia-data
http-request set-path "%[path,regsub(^/services/data/,/)]"
server tomcat 127.0.0.1:16001
mode http
backend academia-user
http-request set-path "%[path,regsub(^/services/user/,/)]"
server tomcat 127.0.0.1:16001
mode http
backend academia-flow
server tomcat 127.0.0.1:16001
mode http
backend academia-policy
http-request set-path "%[path,regsub(^/services/policy/,/)]"
server tomcat 127.0.0.1:9002
mode http
backend academia-quote
http-request set-path "%[path,regsub(^/services/quote/,/)]"
server tomcat 127.0.0.1:9001
mode http
backend academia-audit
http-request set-path "%[path,regsub(^/services/audit/,/)]"
server tomcat 127.0.0.1:9003
mode http
backend academia-tds
http-request set-path "%[path,regsub(^/services/tds/,/)]"
server tomcat 127.0.0.1:9000
mode http
backend academia-admin
server nodejs 127.0.0.1:3000
mode http
Playground
lxc image info ubuntu:noble --vm|yq .Aliases
lxc image info ubuntu:24.04 --vm|yq .Aliases
lxc image info ubuntu:noble |yq .Aliases
lxc image info ubuntu:24.04 |yq .Aliases
|
lxc image list ubuntu: os=ubuntu release=noble type=virtual-machine
lxc image list ubuntu: os=ubuntu release=noble type=virtual-machine
lxc image list ubuntu: os=ubuntu release=noble type=container
lxc image list ubuntu: os=ubuntu release=noble type=container
| |
| ||
lxc image list ubuntu:24.04
lxc launch ubuntu:24.04 haproxy
lxc launch ubuntu:40d8df642812 haproxy
|
lxc list status=running name=haproxy --format=json |jq -r '.[].state.network.[].addresses'
lxc list status=running name=haproxy --format=yaml |yq -r '.[].state.network.[].addresses'
lxc info haproxy|yq '.Resources.["Network usage"][]["IP addresses"].inet'
| |
| ||
sudo ss -tulwn | grep LISTEN
sudo ss -tulpn | grep LISTEN
sudo ss -tulpn | grep LISTEN | grep sshd
|
lxc snapshot haproxy base:2.6.7
lxc publish haproxy/base:2.6.7 --alias haproxy/base:2.6.7
lxc restore haproxy base:2.6.7
| |
| ||