当前位置: 首页 > news >正文

搭建HAproxy----7层负载均衡集群

目录

一、HAproxy的特点

二、环境准备

1、准备4台linux,关闭防火墙、selinux、配置yum源

2、全部的服务器完成时间统一

3、web1 & web2 创建测试页面

4、haproxy主机安装haproxy

 5、域名解析

6、配置HAproxy

7、启动haproxy

三、测试

1.配置域名解析

3.测试结果


一、HAproxy的特点

1.支持tcp / http 两种协议层的负载均衡,使得其负载均衡功能非常丰富。

2.支持8种左右的负载均衡算法,尤其是在http模式时,有许多非常实在的负载均衡算法,适用各种需求。

3.性能非常优秀,基于事件驱动的链接处理模式及单进程处理模式(和Nginx类似)让其性能卓越。

4.处理模式

单进程处理模式:所有客户端连接全部都由同一个服务进程来处理,目标就是等待连接,来一个分配一个,主要消耗cpu

多线程处理模式:多线程模式消耗内存,会限制并发而且多线程需要进程间通信,也会消耗相当多的cpu资源

5.拥有一个功能出色的监控页面,实时了解系统的当前状况。

6.功能强大的ACL支持,给用户极大的方便。

二、环境准备

1、准备4台linux,关闭防火墙、selinux、配置yum源

此步骤参考该链接前两个步骤https://blog.csdn.net/qq_73990369/article/details/142148343?spm=1001.2014.3001.5501

1.Client

192.168.229.11/24 (真实机或虚拟机均可做客户端)

2.HAproxy

192.168.229.12/24

3.web1

192.168.229.13/24

4.web2

192.168.229.14/24

2、全部的服务器完成时间统一

ntpdate 时间服务器ip         date查看时间

ntpdate ntp.aliyun.comdate

3、web1 & web2 创建测试页面

yum install httpd -y

web1

echo web1 > /var/www/html/index.html

web2

echo web2 > /var/www/html/index.html

启动、开机自启动

systemctl start httpdsystemctl enable httpd

测试

输入  http://192.168.229.13:80

输入  http://192.168.229.14:80

4、haproxy主机安装haproxy

yum install epel-release -y
yum install haproxy -y

 5、域名解析

在haproxy主机

vim /etc/hosts

添加以下内容

192.168.229.13 web1
192.168.229.14 web2

6、配置HAproxy

vim /etc/haproxy/haproxy.cfg 

haproxy 配置中分成五部分内容

global: 设置全局配置参数,属于进程的配置,通常是和操作系统相关。

defaults:配置默认参数,这些参数可以被用到frontend,backend,Listen组件;

frontend:接收请求的前端虚拟节点,Frontend可以更加规则直接指定具体使用后端的backend;

backend:后端服务集群的配置,是真实服务器,一个Backend对应一个或者多个实体服务器;

Listen :frontend和backend的组合体。

配置示例:

globallog 127.0.0.1 local3 infomaxconn 4096uid nobody
#       uid 99gid nobody
#       gid 99daemonnbproc 1pidfile /run/haproxy.pid
defaultslog		   globalmode	   httpmaxconn 2048retries 	3option	redispatchcontimeout	5000clitimeout	    50000srvtimeout	    50000
#timeout connect 5000
#timeout client 50000
#timeout server 50000option abortonclosestats uri /admin?statsstats realm Private landsstats auth admin:passwordstats hide-versionfrontend http-inbind 0.0.0.0:80mode httplog globaloption httplogoption httpcloseacl html url_reg  -i  \.html$use_backend html-server if  htmldefault_backend html-serverbackend html-servermode httpbalance roundrobinoption httpchk GET /index.htmlcookie SERVERID insert indirect nocacheserver html-A web1:80 weight 1 cookie 3 check inter 2000 rise 2 fall 5server html-B web2:80 weight 1 cookie 4 check inter 2000 rise 2 fall 5

7、启动haproxy

systemctl start haproxy.service

三、测试

在Client客户端

1.配置域名解析

vim /etc/hosts

添加以下内容

192.168.229.12 haproxy
yum install -y elinks

3.测试结果

elinks --dump http://haproxy/index.html


http://www.mrgr.cn/news/35952.html

相关文章:

  • 【学术会议征稿】第四届人工智能、机器人和通信国际会议(ICAIRC 2024)
  • 数字化转型:国内证书哪个更有用
  • 前端——flex布局
  • 解决错误Cloning failed using an ssh key for authentication
  • 高效职场助手
  • 从零开始学习PX4源码5(遥控器数据)
  • 在Gin框架中实现Token令牌认证
  • 惊艳桌面时钟软件 为你的桌面打造专属时间管理!
  • ECharts设置xAxis轴的name位置
  • 2024中国新科技100强名单出炉!MIAOYUN荣获“2024云原生领航企业奖”
  • 分布式事务(1)
  • 解锁编程潜力,从掌握GitHub开始
  • 分布式事务(2)
  • 数据结构习题
  • Vue74 路由的props配置
  • 父母血型与子女血型对照表
  • AWS账单不支付账号会停用吗?
  • Spring Boot驱动的在线房产租赁服务
  • 【CentOS7】nginx部署前端 gunicorn部署flask后端并使用nginx反向代理
  • 引用reference作为函数返回