# yum -y install epel-release
# yum -y install haproxy
# rpm -ql haproxy
# yum info haproxy
# cat /usr/lib/systemd/system/haproxy.service
# cat /etc/sysconfig/haproxy
# cat /etc/haproxy/haproxy.cfg
##############################################################################
global
? log? ? ? ? 127.0.0.1 local2
? maxconn? ? 50000
? daemon
? stats socket /var/run/haproxy.sock mode 600 level admin
? stats timeout? 2m
defaults
? mode? ? ? ? ? ? ? ? ? ? tcp
? log? ? ? ? ? ? ? ? ? ? global
? option? ? ? ? ? ? ? ? ? dontlognull
? timeout connect 5000ms
? timeout client? 360000ms
? timeout server? 360000ms
? maxconn? ? ? ? 50000
listen statistics
? mode http
? bind *:8888
? stats enable
? stats hide-version
? stats uri? ? /admin?stats
? stats realm? Haproxy\ Statistics
? stats auth? ? admin:Admin@123
? stats admin if TRUE
# 長(zhǎng)連接
frontend? persistent_connection_12345
? bind *:12345
? mode tcp
? default_backend? persistent_connection_servers
backend? persistent_connection_servers
? balance leastconn
? server? persistent_connection_192.168.1.101 192.168.1.101:12345 check port 12345? rise 1 fall 2 maxconn 50000
? server? persistent_connection_192.168.1.102 192.168.1.102:12345 check port 12345? rise 1 fall 2 maxconn 50000
# 短連接
frontend non-persistent_connection_23456
? bind *:23456
? mode tcp
? default_backend non-persistent_connection_servers
backend non-persistent_connection_servers
? balance leastconn
? server non-persistent_connection_192.168.1.101 192.168.1.101:23456 check port 23456 rise 1 fall 2 maxconn 50000
? server non-persistent_connection_192.168.1.102 192.168.1.102:23456 check port 23456 rise 1 fall 2 maxconn 50000
##############################################################################
參考
HTTP長(zhǎng)連接和短連接
https://www.cnblogs.com/0201zcr/p/4694945.html
我們是如何優(yōu)化HAProxy以讓其支持200萬(wàn)個(gè)并發(fā)SSL連接的两芳?
https://cloud.tencent.com/developer/article/1031614
HAProxy高并發(fā)
https://www.cnblogs.com/zjz20/p/12809856.html