Haproxy

Haproxy是一款专注于负载均衡的高性能软件,支持TCP/HTTP协议,并提供多种负载均衡算法,如roundrobin、static-rr和leastconn。其特点包括优秀的性能、实时监控页面和强大的ACL支持。本文将介绍Haproxy在HTTP和HTTPS配置中的负载均衡应用。
摘要由CSDN通过智能技术生成

一、Haproxy概述

haproxy是一款高性能的负载均衡软件。因为其专注于负载均衡这一些事情,因此与nginx比起来在负载均衡这件事情上做更好,更专业。

haproxy的特点

  • 支持tcp / http 两种协议层的负载均衡,使得其负载均衡功能非常丰富。
  • 支持8种左右的负载均衡算法,尤其是在http模式时,有许多非常实在的负载均衡算法,适用各种需求。
  • 性能非常优秀,基于单进程处理模式(和Nginx类似)让其性能卓越。
  • 拥有一个功能出色的监控页面,实时了解系统的当前状况。
  • 功能强大的ACL支持,给用户极大的方便。

haproxy算法:

  • 1.roundrobin
    基于权重进行轮询,在服务器的处理时间保持均匀分布时,这是最平衡,最公平的算法.此算法是动态的,这表示其权重可以在运行时进行调整.

  • 2.static-rr
    基于权重进行轮询,与roundrobin类似,但是为静态方法,在运行时调整其服务器权重不会生效.不过,其在后端服务器连接数上没有限制

  • 3.leastconn
    新的连接请求被派发至具有最少连接数目的后端服务器.

haproxy官网

二、Haproxy负载均衡http

环境说明:

主机名 ip 职责
item 192.168.91.134 Haprosy
task1 192.168.91.135 web界面
task2 192.168.91.137 web界面
item 准备工作
// 关闭防火墙和selinux
[root@item ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@item ~]# setenforce 0
task1 准备工作
// 关闭防火墙和selinux
[root@task1 ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@task1 ~]# setenforce 0

// 启动httpd,添加web内容
[root@task1 ~]# yum -y install httpd
[root@task1 ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@task1 ~]# echo "amu" > /var/www/html/index.html
[root@task1 ~]# curl 127.0.0.1
amu
task2准备工作
// 关闭防火墙和selinux
[root@task2 ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@task2 ~]# setenforce 0

// 启动httpd,添加web内容
[root@task2 ~]# yum -y install httpd
[root@task2 ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@task2 ~]# echo "gf" > /var/www/html/index.html
[root@task2 ~]# curl 127.0.0.1
gf
安装haproxy
// 安装编译工具以及依赖包
[root@item ~]# yum -y install make gcc pcre-devel bzip2-devel openssl-devel systemd-devel vim

// 创建一个服务用户
[root@item ~]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值