负载均衡:HAProxy

**1.**安装:

root @haproxy \~ # yum -y install ntpdate.x86_64
root @haproxy \~ # yum -y install ntp
root @haproxy \~ # ntpdate cn.ntp.org.cn
13 Aug 19 : 39 : 27 ntpdate 1955 : adjust time server
120.197.116.202 offset 0.059032 sec
root @haproxy \~ # systemctl start ntpd
root @haproxy \~ # systemctl enable ntpd
root @haproxy \~ # yum -y install haproxy18.x86_64

**2.**配置

root@haproxy \~# vim /etc/haproxy18/haproxy.cfg
63 frontend main *: 80
64 acl url_static path_beg - i / static
/ images / javascript / stylesheets
65 acl url_static path_end - i .jpg .gif
.png .css .js
66
67 # use_backend static if url_static
68 default_backend web
......
77 #----------------------------------------------------
----------------- 3. 重启,设置开机启动
78 # round robin balancing between the various backends
79 #-----------------------------------------------------

80 backend web
81 balance roundrobin
82 server web01 10.1.1.200 : 80 check
83 server web02 10.1.1.201 : 80 check
84

**3.**重启,设置开机启动:

root @haproxy \~ # systemctl restart haproxy
root @haproxy \~ # systemctl enable haproxy

4.测试:

5.添加统计页面:

在配置文件vim /etc/haproxy18/haproxy.cfg 中添加:

# 定义web管理界面

listen statistics
bind *:9090 #定义监听端口
mode http #默认使用协议
stats enable #启用stats
stats uri /hadmin?stats #自定义统计页面的url
stats auth admin:admin #统计页面的账号密码
stats hide-version #隐藏在统计页面上的haproxy版本信息
stats refresh 30s #统计页面自动刷新时间
stats admin if TRUE #如果认证通过就做管理功能,可以管理>后端服务器
stats realm hapadmin #统计页面密码框上提示文件,默认haproxy\statistics

相关推荐
MuMuMu12236 小时前
工业园区 VOCs 绿岛集中治理:越华环保集团项目技术方案与工程实践
大数据·运维
sxstj7 小时前
Ubuntu 完整安装并启用 Flatpak 教程
linux·运维·ubuntu
国际云,接待7 小时前
Nginx 后面接负载均衡,502/504 到底该先查哪里?
运维·nginx·负载均衡
Sylvia33.7 小时前
从轮询到推送:足球数据API架构演进与火星数据技术拆解
java·服务器·网络·python·websocket·架构
刘某的Cloud8 小时前
Galera Cluster部署 mariadb 节点down机,log sequence number恢复
linux·运维·数据库·负载均衡·mariadb·集群·高可用
小此方9 小时前
Re:Linux系统篇(五十四)线程篇 · 七:互斥锁的底层实现原理:从硬件上下文、原子交换指令(Swap)到并发封装实战
linux·运维·驱动开发
程序员老陆10 小时前
说一说FFmpeg6在Linux平台的编译
linux·运维·服务器·ffmpeg
玫幽倩10 小时前
2026黄河流域公安院校-电子物证单项赛(程序逆向分析+服务器取证)
运维·服务器·python·电子取证·逆向·程序分析·服务器取证
赵民勇11 小时前
systemd-cgtop命令详解
linux·运维
Zhu75812 小时前
在docker环境部署frp
运维·docker·容器