网站首页 > 技术文章 正文
场景描述
后端服务有三个节点(node1,node2,node3),需要通过haproxy实现负载均衡,服务器具采用ubuntu操作系统。
部署步骤
1、安装haproxy
apt-get install haproxy
2、修改配置文件
vi /etc/haproxy/haproxy.cfg
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
# An alternative list with additional directives can be obtained from
# https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy
ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
listen stats
bind 0.0.0.0:1080
stats refresh 30s
stats uri /stats
stats realm Haproxy Manager
stats auth admin:admin
frontend main
bind 0.0.0.0:80
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .gif .png .css .js
default_backend webservice
backend webservice
balance leastconn
server web1 node1:80 check
server web2 node2:80 check
server web3 node3:80 check
3、加载配置文件使生效
/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg
配置说明:
- 1、frontend main
bind 0.0.0.0:80
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .gif .png .css .js
default_backend webservice
这里default_backend webservice需要和后端backend 保持一致
- 2、backend webservice
balance leastconn
server web1 node1:80 check
server web2 node2:80 check
server web3 node3:80 check
HAProxy还提供了其他类型的负载均衡:
oleastconn:每次将服务转发至连接数最少的服务器。
osource:对源IP地址进行哈希处理,用运行中服务器的总权重除以哈希值,即可决定哪台服务器将接收请求。
ouri:URI的左边部分(问号前面)经哈希处理,用运行中服务器的总权重除以哈希值。所得结果决定哪台服务器将接收请求。
ourl_param:变量中指定的URL参数将在每个HTTP GET请求的查询串中进行查询。你基本上可以将使用蓄意制作的URL(crafted URL)的请求锁定于特定的负载均衡节点。
ohdr(name):HTTP头<name> 将在每个HTTP请求中进行查询,被定向到特定节点。
这里配置后端服务,端口可在具体每个server 上再用nginx做反向代理
- 上一篇: 服务器错误是怎么回事
- 下一篇: 常见的62种http响应代码整理
猜你喜欢
- 2025-06-17 Jmeter之HTTP请求与响应
- 2025-06-17 Jetty 运行的时候出现 503 异常的原因
- 2025-06-17 寝室洗澡热水价格高?湖南一高校通报
- 2025-06-17 山东本科二次征集志愿录取线一分未降 三万多考生志愿白填了
- 2025-06-17 网站访问中常见的错误代码404,403,500
- 2025-06-17 常见的62种http响应代码整理
- 2025-06-17 服务器错误是怎么回事
- 2025-06-17 如何选择正确的HTTP状态码?
- 2025-06-17 http常见状态码
- 2025-06-17 错误代码解析500、501、502、503、504
- 06-22Python开发工程师必会的3个设计模式(工厂、单例、适配器)
- 06-22创建型设计模式——工厂模式和抽象工厂模式
- 06-221. 工厂模式详解
- 06-22工厂模式详解
- 06-22设计模式问题:说一说简单工厂模式?
- 06-22深入设计模式:工厂方法
- 06-22C++设计模式——简单工厂模式
- 06-22什么是工厂模式?工厂模式有哪些类型?如何使用它们?
- 最近发表
- 标签列表
-
- axure 注册码 (25)
- exploit db (21)
- mutex_lock (30)
- oracleclient (27)
- think in java (14)
- javascript权威指南 (19)
- nfs (25)
- componentart (17)
- yii框架 (14)
- springbatch (28)
- oracle数据库备份 (25)
- iptables (21)
- 自动化单元测试 (18)
- mvc模式 (13)
- python编写软件 (14)
- dir (26)
- connectionstring属性尚未初始化 (23)
- output (32)
- panel滚动条 (28)
- centos 5 4 (23)
- sql学习 (33)
- dfn (14)
- http error 503 (21)
- pop3服务器 (18)
- 图表组件 (17)