负载均衡: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

相关推荐
SkyWalking中文站5 小时前
认识 Horizon UI · 6/17:Trace 探索器
运维·监控·自动化运维
程序员老赵9 小时前
服务器文件不想 SFTP 上传?Docker 跑个 File Browser,浏览器就能管理
服务器·docker·开源
火车叼位9 小时前
写给初级开发者:SSL、SSH、HTTPS 与证书体系全解析
运维
vivo互联网技术13 小时前
从 10 分钟到 1 秒:ES 深度分页任意跳页的三轮优化实战
服务器·数据库·redis·elasticsearch·深度分页
小猿姐20 小时前
唯品会大规模数据库云原生实践:基于 KubeBlocks 管理数千实例的统一运维之路
运维·elasticsearch·云原生
SkyWalking中文站1 天前
认识 Horizon UI · 5/17:3D 基础设施地图
运维·监控·自动化运维
SkyWalking中文站2 天前
认识 Horizon UI · 1/17:SkyWalking 新一代可观测性控制台
运维·前端·监控
雪梨酱QAQ2 天前
Kubeneters HA Cluster部署
运维
江华森3 天前
Spring Cloud 微服务全栈实战:从 Eureka 到 Docker Compose 一文贯通
运维