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

相关推荐
web2u9 分钟前
Docker入门及基本概念
java·运维·服务器·spring·docker·容器
元气满满的热码式1 小时前
Docker实战-使用docker compose搭建博客
运维·docker·容器
Anna_Tong1 小时前
阿里云如何协助解决操作系统兼容性问题
linux·服务器·ubuntu·阿里云·centos·云计算·系统迁移
HaoHao_0101 小时前
如何将MySQL数据库迁移至阿里云
服务器·数据库·阿里云·云计算·云服务器·迁移
不良人天码星2 小时前
Linux的基础指令和环境部署,项目部署实战(下)
linux·运维·服务器
火一线3 小时前
【ASP .NET Core】ASP .NET Core介绍
服务器·游戏·.netcore
EasyNVR3 小时前
基于WebRTC与AI大模型接入EasyRTC:打造轻量级、高实时、强互动的嵌入式音视频解决方案
运维·服务器·微信·小程序·webrtc·p2p·智能硬件
技术小齐3 小时前
网络运维学习笔记 022 HCIA-Datacom新增知识点03园区网典型组网架构及案例实战
运维·网络·学习
Java潘老师4 小时前
Automa 浏览器自动化编排 实现自动化浏览器操作
运维·自动化
waves浪游4 小时前
Linux基本指令(上)
linux·运维·服务器