当前位置:网站首页>一文带你了解HAProxy
一文带你了解HAProxy
2022-07-17 05:02:00 【小新爱编程】
负载均衡-HAProxy
HAProxy提供高可用性、负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费、快速并且可靠的一种解决方案,包括Twitter,Reddit,StackOverflow,GitHub在内的多家知名互联网公司在使用。HAProxy实现了一种事件驱动、单一进程模型,此模型支持非常大的并发连接数。
安装HAProx
haproxy—主要是做负载均衡的7层,也可以做4层负载均衡
apache也可以做7层负载均衡,但是很麻烦。实际工作中没有人用;
负载均衡是通过OSI协议对应的;
7层负载均衡:用的7层http协议;
4层负载均衡:用的是tcp协议加端口号做的负载均衡;
//下载依赖包
yum install gcc vim wget
//上传haproxy源码包
//解压
tar -zxvf haproxy-1.6.5.tar.gz -C /usr/local
//进入目录、进行编译、安装
cd /usr/local/haproxy-1.6.5
make TARGET=linux31 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
mkdir /etc/haproxy
//赋权
groupadd -r -g 149 haproxy
useradd -g haproxy -r -s /sbin/nologin -u 149
haproxy
//创建haproxy配置文件
mkdir /etc/haproxy
vim /etc/haproxy/haproxy.cfg```
## 配置HAProxy
配置文件路径:/etc/haproxy/haproxy.cfg
```java
#logging options
global
log 127.0.0.1 local0 info
maxconn 5120
chroot /usr/local/haproxy
uid 99
gid 99
daemon
quiet
nbproc 20
pidfile /var/run/haproxy.pid
defaults
log global
mode tcp
option tcplog
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5s
clitimeout 60s
srvtimeout 15s
#front-end IP for consumers and producters
listen rabbitmq_cluster
bind 0.0.0.0:5672
mode tcp
#balance url_param userid
#balance url_param session_id check_post 64
#balance hdr(User-Agent)
#balance hdr(host)
#balance hdr(Host) use_domain_only
#balance rdp-cookie
#balance leastconn
#balance source //ip
balance roundrobin
server node1 127.0.0.1:5673 check inter
5000 rise 2 fall 2
server node2 127.0.0.1:5674 check inter
5000 rise 2 fall 2
listen stats
bind 172.16.98.133:8100
mode http
option httplog
stats enable
stats uri /rabbitmq-stats
stats refresh 5s
启动HAproxy负载
ha-proxy是一款高性能的负载均衡软件。因为其专注于负载均衡这一些事情,因此与nginx比起来在负载均衡这件事情上做的更好,更专业。
/usr/local/haproxy/sbin/haproxy -f
/etc/haproxy/haproxy.cfg
//查看haproxy进程状态
ps -ef | grep haproxy
访问如下地址对mq节点进行监控
http://172.16.98.133:8100/rabbitmq-stats
代码中访问mq集群地址,则变为访问haproxy地址:5672
总结:
HAProxy实现了一种事件驱动, 单一进程模型,此模型支持非常大的并发连接数。多进程或多线程模型受内存限制 、系统调度器限制以及无处不在的锁限制,很少能处理数千并发连接。事件驱动模型因为在有更好的资源和时间管理的用户空间(User-Space) 实现所有这些任务,所以没有这些问题。此模型的弊端是,在多核系统上,这些程序通常扩展性较差。这就是为什么他们必须进行优化以 使每个CPU时间片(Cycle)做更多的工作。
边栏推荐
- 【Lipschitz】基于matlab的Lipschitz李氏指数仿真
- 常用postgresql数据操作备忘(不定时更新)
- OLTP Load Performance Optimization Practice
- [fuel cell] simulation of fuel cell system control strategy based on Simulink
- TiDB 性能分析和优化
- ThinkPHP official website tutorial
- Overview of CKS core knowledge points
- Notes on Advanced Mathematics: second derivative of composite function and curvature of solving parametric equation
- Easyexcel easy to use
- Constraints on MySQL tables (Basics)
猜你喜欢

TiDB 性能分析和优化

Wildfly: how to call EJBs from EJBs located in another application

Extreme video compression using the pellet toolbox

力扣刷题02(三数之和+最大子序和+二叉树最近公共祖先)

thinkphp 官网教程

Simple UI funny text conversion Emoji expression wechat applet supports sentence word conversion_ Source code

邮箱发送邮件(包含附件,网易、QQ)

Hightec new aurix tc37x demo project
![Fudan micro fmql (domestic zynq) [PS of IAR bare metal development] - non byte aligned access](/img/e7/8349da2c240ac8f51524e5e51bd4d6.png)
Fudan micro fmql (domestic zynq) [PS of IAR bare metal development] - non byte aligned access

服务端接口测试-接口测试的测试点【杭州多测师】【杭州多测师_王sir】
随机推荐
Kettle5.4 problem record
masm32写程序
模板类的声明和定义
Project structure of wechat applet
MySQL one line to many lines (split according to specific symbols)
[unity] interactive double click
UE plug-in electronicnodes 5.0.0/4.23-4.27
Demo analysis of sliding conflict external interception method
thinkphp 官网教程
NPM installation tutorial
Fudan micro fmql (domestic zynq) [PS of IAR bare metal development] - non byte aligned access
高等数学笔记:伍月习题选集
mysql8.026-- 视图(下)
Rearrange data according to date JS
邮箱发送邮件(包含附件,网易、QQ)
Summary of black screen problems in unity UMP packaging
Deleting snapshot: error deleting snapshot: Dictionary problem
摄像头切换
ThreadLocal线程安全示例及其原理
Using everything to clean up junk files