HaProxy简介
HAProxy是一个收费的负载平衡软件,能够运行于大部分支流的Linux操作系统上。
HAProxy提供了L4(TCP)和L7(HTTP)两种负载平衡能力,具备丰盛的性能。HAProxy的社区十分沉闷,版本更新疾速。最要害的是,HAProxy具备媲美商用负载均衡器的性能和稳定性。
HaProxy的外围性能
负载平衡:L4和L7两种模式,反对RR/动态RR/LC/IP Hash/URI Hash/URL\_PARAM Hash/HTTP\_HEADER Hash等丰盛的负载平衡算法
健康检查:反对TCP和HTTP两种健康检查模式
会话放弃:对于未实现会话共享的利用集群,可通过Insert Cookie/Rewrite Cookie/Prefix Cookie,以及上述的多种Hash形式实现会话放弃
SSL:HAProxy能够解析HTTPS协定,并可能将申请解密为HTTP后向后端传输
HTTP申请重写与重定向
监控与统计:HAProxy提供了基于Web的统计信息页面,展示衰弱状态和流量数据。基于此性能,使用者能够开发监控程序来监控HAProxy的状态
HaProxy的要害个性
性能
1 . 采纳单线程、事件驱动、非阻塞模型,缩小上下文切换的耗费,能在1ms内解决数百个申请。并且每个会话只占用数KB的内存。
2 . 大量精密的性能优化,如O(1)复杂度的事件查看器、提早更新技术、Single-buffereing、Zero-copy forwarding等等,这些技术使得HAProxy在中等负载下只占用极低的CPU资源。
3 . HAProxy大量利用操作系统自身的性能个性,使得其在解决申请时能施展极高的性能,通常状况下,HAProxy本身只占用15%的解决工夫,残余的85%都是在零碎内核层实现的。
4 . HAProxy作者在8年前(2009)年应用1.4版本进行了一次测试,单个HAProxy过程的解决能力冲破了10万申请/秒,并轻松占满了10Gbps的网络带宽。
稳定性
在上文中提到过,HAProxy的大部分工作都是在操作系统内核实现的,所以HAProxy的稳定性次要依赖于操作系统,作者倡议应用2.6或3.x的Linux内核,对sysctls参数进行精密的优化,并且确保主机有足够的内存。这样HAProxy就可能继续满负载稳固运行数年之久。
设置主机名
root@hello:~# hostnamectl set-hostname haproxy
root@hello:~#
root@hello:~#
root@hello:~# bash
root@haproxy:~#
装置 haproxy
root@haproxy:~# apt-get install haproxy
root@haproxy:~# cp /etc/haproxy/haproxy.cfg{,.ori}
root@haproxy:~#
root@haproxy:~# vim /etc/haproxy/haproxy.cfg
root@haproxy:~#
配置文件如下
root@haproxy:~# cat /etc/haproxy/haproxy.cfg
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
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
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 no-sslv3 no-tlsv10 no-tlsv11 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 LOADBALANCER-01
bind 0.0.0.0:80
mode http
default_backend WEBSERVERS-01
backend WEBSERVERS-01
balance roundrobin
server node1 192.168.1.10:9200 check inter 2000 rise 3 fall 3 weight 1 maxconn 2000
server node2 192.168.1.11:9200 check inter 2000 rise 3 fall 3 weight 1 maxconn 2000
server node3 192.168.1.12:9200 check inter 2000 rise 3 fall 3 weight 1 maxconn 2000
server node4 192.168.1.13:9200 check inter 2000 rise 3 fall 3 weight 1 maxconn 2000
server node5 192.168.1.14:9200 check inter 2000 rise 3 fall 3 weight 1 maxconn 2000
server node6 192.168.1.15:9200 check inter 2000 rise 3 fall 3 weight 1 maxconn 2000
server node7 192.168.1.16:9200 check inter 2000 rise 3 fall 3 weight 1 maxconn 2000 backup
option httpchk
启动服务
root@haproxy:~#
root@haproxy:~# systemctl start haproxy
root@haproxy:~#
设置开机自启
root@haproxy:~#
root@haproxy:~# systemctl enable haproxy
Synchronizing state of haproxy.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable haproxy
root@haproxy:~#
Linux运维交换社区
Linux运维交换社区,互联网新闻以及技术交换。
40篇原创内容
公众号
本文应用 文章同步助手 同步
发表回复