设为首页 收藏本站
查看: 1530|回复: 0

[经验分享] 负载均衡工具haproxy安装配置使用

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-4-18 08:50:11 | 显示全部楼层 |阅读模式
  一,什么是haproxy
HAProxy提供高可用性、负载均衡以及基于TCP和HTTP应用的代 理,支持虚拟主机,它是免费、快速并且可靠的一种解决方案。HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保持或七层处理。HAProxy运行在当前的硬件上,完全可以支持数以万计的并发连接。并且它的运行模式使得它可以很简单安全的整合进您当前的架构中, 同时可以保护你的web服务器不被暴露到网络上。
  二,安装haproxy
下载列表地址http://haproxy.1wt.eu
wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.8.tar.gz
 
tar zxvf haproxy-1.4.8.tar.gz
cd haproxy-1.4.8
uname -a           //查看linux内核版本
make TARGET=linux26 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
  三,配置haproxy
  vi /usr/local/haproxy/haproxy.cfg

  • global  
  •         maxconn 5120  
  •         chroot /usr/local/haproxy  
  •         uid 99  
  •         gid 99  
  •         daemon  
  •         quiet  
  •         nbproc  2  
  •         pidfile /usr/local/haproxy/haproxy.pid  
  • defaults  
  •         log     global  
  •         mode    http  
  •         option  httplog  
  •         option  dontlognull  
  •         log 127.0.0.1 local3  
  •         retries 3  
  •         option redispatch  
  •         maxconn 2000  
  •         contimeout      5000  
  •         clitimeout      50000  
  •         srvtimeout      50000  
  •   
  • listen webinfo :1080  
  •        mode http  
  •        balance roundrobin  
  •        option httpclose  
  •        option forwardfor  
  • server localhost 192.168.18.2:10000 check weight 1 minconn 1 maxconn 3 check inter 40000  
  • server localhost 127.0.0.1:80 check weight 1 minconn 1 maxconn 3 check inter 40000  
  •   
  • listen webmb :1081  
  •        mode http  
  •        balance roundrobin  
  •        option httpclose  
  •        option forwardfor  
  • server webmb1 192.168.1.91:10000 weight 1 minconn 1 maxconn 3 check inter 40000  
  • server webmb2 127.0.0.1:10000 weight 1 minconn 1 maxconn 3 check inter 40000  
  •   
  •  listen stats :8888  
  •        mode http  
  •        transparent  
  •        stats uri / haproxy-stats  
  •        stats realm Haproxy \ statistic  
  •        stats auth zhangy:xtajmd  

  三,启动haproxy
#启动haproxy
/usr/local/haproxy/haproxy -f /usr/local/haproxy/haproxy.cfg
#查看是否启动
$ ps -e|grep haproxy
4859 ?        00:00:00 haproxy
4860 ?        00:00:00 haproxy
  四,压力测试
# ab -c 10 -n 10000 http://localhost:1080/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        Apache/2.2.20
Server Hostname:        127.0.0.1
Server Port:            1080

Document Path:          /
Document Length:        177 bytes

Concurrency Level:      10
Time taken for tests:   4.438 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      4530000 bytes
HTML transferred:       1770000 bytes
Requests per second:    2253.38 [#/sec] (mean)
Time per request:       4.438 [ms] (mean)
Time per request:       0.444 [ms] (mean, across all concurrent requests)
Transfer rate:          996.86 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0      10
Processing:     0    4   3.6      4      46
Waiting:        0    4   3.5      3      46
Total:          0    4   3.6      4      46

Percentage of the requests served within a certain time (ms)
  50%      4
  66%      5
  75%      5
  80%      6
  90%      8
  95%     12
  98%     15
  99%     18
 100%     46 (longest request)
说明:haproxy监听的端口是1080,代理192.168.18.2:10000,127.0.0.1:10000
统计监听的是8888端口http://localhost:8888/haproxy-stats

DSC0000.jpg haproxy负载均衡

  说明:
原博客中需要配置相关页面phpinfo.php
 由于没有php页面,我就使用apache服务器的默认页面


  配置说明:
  1.4系列参考配置文件
  http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
  1.3系列参考配置文件
  http://haproxy.1wt.eu/download/1.3/doc/configuration.txt
  转自 http://blog.51yip.com/server/868.html

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-365707-1-1.html 上篇帖子: haproxy(二)配置session粘连 下篇帖子: haproxy(3)Upgrade haproxy to 1.4.25 and Proxy RabbitMQ Cluster
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表