需求:簡單的4層(SSH)和7層(HTTP)反向代理
架設環境:CentOS 8
安裝node
> sudo dnf install haproxy
配置vim
> sudo vim /etc/haproxy/haproxy.cfg # 如下是關鍵修改部分 global ... maxconn 20480 ulimit-n 65535 ... default ... stats uri /haproxy?stats # 查看haproxy的狀態,地址http://<haproxy_ip>/haproxy?stats ... # 定義7層HTTP轉發 frontend sdc bind *:80 # define acl for different streamset data controller server acl sdc1-policy hdr_dom(host) -i sdc1.3rd.pla95929 acl sdc2-policy hdr_dom(host) -i sdc2.3rd.pla95929 # back end for acl use_backend server_sdc1 if sdc1-policy use_backend server_sdc2 if sdc2-policy # send X-Forwarded-For header option forwardfor except 127.0.0.0/8 backend server_sdc1 server srv sdc1:18630 check backend server_sdc2 server srv sdc2:18630 check # sdc1和sdc2在haproxy的/etc/hosts有記錄,也能夠直接寫ip,srv爲自定義的名字 # 定義4層TCP轉發 listen ssh-sdc1 mode tcp option tcplog tcp-request inspect-delay 5s bind *:2201 server node sdc1:22 check listen ssh-sdc2 mode tcp option tcplog tcp-request inspect-delay 5s bind *:2202 # 4層反代不能經過檢查host來配置acl策略,只能使用端口綁定方式實現