HAProxy 配置负载均衡

 

准备条件
 
1. 安装好HAProxy
 
2. 启动两个web应用服务器,这里启动了两个nginx
 
nginx1 端口 8080
 
nginx2 端口 8081
 
都有一个页面 test.html,显示的内容不同,nginx1 里的test.html显示 1,nginx2 里的test.html显示 2
 
目标
 
配置HAProxy做为前端的负载均衡服务器,通过HAProxy访问test.html,动态指向nginx1或nginx2,页面显示 1 或 2,多次刷新页面,应看到不同输出
 
配置文件
 
在HAProxy的安装目录下,新建 conf 目录,在conf目录下新建文件 haproxy.cfg ,内容:
 
global
daemon
maxconn 256
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind *:7000
default_backend neo4j
backend neo4j
server s1 127.0.0.1:8080 maxconn 32 
server s2 127.0.0.1:8081 maxconn 32 
listen admin
bind *:7080
stats enable
 
说明:
 
frontend http-in
bind *:7000
 
这两行指定了HAProxy监听 7000端口
 
server s1 127.0.0.1:8080 maxconn 32 
server s2 127.0.0.1:8081 maxconn 32 
 
这两行指定了两个应用服务器的地址和端口
 
 
启动HAProxy
 
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg
 
访问测试
 
http://服务器地址:7000/test.html
 
多次刷新页面,可以看到交替输出 1 和 2,说明HAProxy已经配置成功,把请求动态分配给了不同的应用服务器
posted on 2018-08-12 00:50 micwin 阅读( ...) 评论( ...)   编辑 收藏

转载于:https://www.cnblogs.com/chinanetwind/articles/9461798.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值