haproxy架构图
所谓的反向代理是这样子的访问关系路径,这个图仅供参考。
环境
ubuntu 20.04
HA-Proxy version 2.0.13-2ubuntu0.5 2022/03/02
安装
默认是http模式,以下配置已经在生产上使用,访问量不多。主要为了提供内部高可用。
apt update -y
sudo apt install -y haproxy
安装完毕后,以及自动启动服务以及开机自启动
配置
$ cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bk
$ cat /etc/haproxy/haproxy.cfg
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate
ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
frontend example_front_end
bind *:80
# bind *:8728
option forwardfor
default_backend nodejs_servers
backend nodejs_servers
balance roundrobin
server nodejs-app01 172.19.200.100:5001 check
server nodejs-app02 172.19.200.102:5002 check
server nodejs-app03 172.19.200.102:5003 check
# server web-app02 172.19.201.126:8728 check
# server web-app04 172.19.202.6:8728 check
# 下面这些是可选,可以不添加。简单来说就是一个监控来的
listen stats
bind :32600
stats enable
stats uri /
stats hide-version
stats auth admin:admin
让配置生效
#重启
systemctl restart haproxy
# 查看启动的状态
systemctl status haproxy
查看监控
ip:32600,然后输入账号密码吧,admin和admin
本人只是贴出安装以及配置,只是做一个笔记,没有做其他详细解说。