Haproxy高可用架构

本文介绍了Haproxy的高可用性,并详细阐述了其采用的八种负载均衡算法,包括轮询、权重、最少连接、源IP、URI、URL参数、请求头和TCP请求的cookie哈希。同时,还提到了通过配置Pacemaker实现动静页面分离,以增强服务的可用性和稳定性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

高可用架构由两个核心部分组成,一个是心跳检测,判断服务器是否正常运行;一个是资源转移,用来将公共资源在正常服务器和故障服务器之间搬动。两个结合起来使用,可以实现对高可用架构的自动管理。
整个运行模式就是心跳检测不断的在网络中检测各个指定的设备是否能够正常响应,如果一旦发生设备故障,就由资源转移功能进行应用的切换,以继续提供服务。
corosync提供集群的信息层(messaging layer)的功能,传递心跳信息和集群事务信息,多台机器之间通过组播的方式监测心跳
pacemaker工作在资源分配层,提供资源管理器的功能,并以crmsh这个资源配置的命令接口来配置资源
心跳检测是用来检测服务器是否还在提供服务,只要出现异常不能提供服务了,就认为它挂掉了。
当检测出服务器挂掉之后,就要对服务资源进行转移。
CoroSync是运行于心跳层的开源软件。
PaceMaker是运行于资源转移层的开源软件。
使用corosync监控心跳,pacemaker时先资源转移,crmsh实现集群资源配置
使用fence检查节点健康状况,实行跳电保护

一、Haproxy

server1:172.25.53.2
server2:172.25.53.3
[root@server2 ~]# cd /mnt/
[root@server2 mnt]# ls
 haproxy-1.6.11.tar.gz
[root@server2 mnt]# yum install -y rpm-build     安装rpm包制作工具
[root@server2 mnt]# rpmbuild -tb haproxy-1.6.11.tar.gz 制作rpm包
[root@server2 ~]# cd rpmbuild/RPMS/x86_64/
[root@server2 x86_64]# ls
haproxy-1.6.11-1.x86_64.rpm
[root@server2 x86_64]# rpm -ivh haproxy-1.6.11-1.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:haproxy                ########################################### [100%]
[root@server2 x86_64]# ls
haproxy-1.6.11-1.x86_64.rpm           所制作的rpm包
[root@server2 x86_64]# rpm -qpl haproxy-1.6.11-1.x86_64.rpm   
##查看安装haproxy会生成的文件, 没有主配置文件, 需要将压缩包解压获取
[root@server2 x86_64]# cd
[root@server2 ~]# ls
anaconda-ks.cfg     nginx-1.10.1.tar.gz     nginx-sticky-module-ng.tar.gz
install.log         nginx-1.14.0            rpmbuild
install.log.syslog  nginx-1.14.0.tar.gz
nginx-1.10.1        nginx-sticky-module-ng
[root@server2 ~]# cd /mnt/
[root@server2 mnt]# ls
crmsh-1.2.6-0.rc2.2.1.x86_64.rpm  haproxy-1.6.11.tar.gz
[root@server2 mnt]# tar zxf haproxy-1.6.11.tar.gz 
[root@server2 mnt]# ls
crmsh-1.2.6-0.rc2.2.1.x86_64.rpm  haproxy-1.6.11  haproxy-1.6.11.tar.gz
[root@server2 mnt]# cd haproxy-1.6.11
[root@server2 haproxy-1.6.11]# ls
CHANGELOG     doc       include      Makefile  src      VERDATE
contrib       ebtree    LICENSE      README    SUBVERS  VERSION
CONTRIBUTING  examples  MAINTAINERS  ROADMAP   tests
[root@server2 haproxy-1.6.11]# find -name *.spec   存在.spec文件, 才可以制作rpm包
./examples/haproxy.spec
[root@server2 haproxy-1.6.11]# cd examples/
[root@server2 examples]# ls
acl-content-sw.cfg     debug2html    init.haproxy
auth.cfg               debugfind     option-http_proxy.cfg
check                  errorfiles    seamless_reload.txt
check.conf             haproxy.init  ssl.cfg
content-sw-sample.cfg  haproxy.spec  stats_haproxy.sh
debug2ansi             haproxy.vim   transparent_proxy.cfg
[root@server2 examples]# cp content-sw-sample.cfg /etc/haproxy/haproxy.cfg

##将配置文件模板复制到 /etc/haproxy/haproxy.cfg
##因为在haproxy启动脚本中读取的配置文件是/etc/haproxy/haproxy.cfg
##所以起的名字要一致
[root@server2 examples]# cd /etc/haproxy/
[root@server2 haproxy]# ls
haproxy.cfg
[root@server2 haproxy]# ip addr add 172.25.53.100/24 dev eth0
[root@server
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值