参考链接:

https://www.cnblogs.com/Richardzhu/p/3344676.html

https://blog.csdn.net/sj349781478/article/details/78862315

https://www.cnblogs.com/paul8339/p/8042776.html

 

附上我的配置

[root@node1 ~]# cat /etc/haproxy/haproxy.cfg 
#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD\_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2

chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon

# turn on stats unix socket
stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode tcp
log global
option tcplog
option dontlognull
option http-server-close
option forwardfor
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000

#---------------------------------------------------------------------
# haproxy监听图形化界面
#---------------------------------------------------------------------

listen admin_stats
stats enable
bind *:888 #监听端口
mode http
option httplog #采用http日志格式
log global
maxconn 10
stats refresh 30s #统计页面自动刷新时间
stats uri /stats #统计页面url
stats realm Haproxy Manager #统计页面密码框上提示文本
stats auth admin:password #统计页面用户名和密码设置
stats hide-version #隐藏统计页面上HAProxy的版本信息
stats admin if TRUE
#---------------------------------------------------------------------
# 需要代理的端口和服务
#---------------------------------------------------------------------
frontend http *:80
default_backend web_server_http

frontend http2 *:88
default_backend web_server_http2

frontend https *:443
default_backend web_server_https
#---------------------------------------------------------------------
# 后端负载均衡服务器列表
#---------------------------------------------------------------------
backend web_server_http
balance roundrobin
server web1 182.148.157.242:8000

backend web_server_http2
balance roundrobin
server web1 182.148.157.242:8800

backend web_server_https
balance roundrobin
server web1 182.148.157.242:44300