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

[经验分享] 开源负载均衡软件haproxy的学习了解

[复制链接]

尚未签到

发表于 2015-11-20 11:07:41 | 显示全部楼层 |阅读模式
Haproxy学习

1       安装
  源代码:
  1)  拷贝
  2)  解压
  3)  运行 make install 即完成安装,安装路径
  运行程序:/usr/local/sbin/haproxy
  文档:/usr/local/doc/haproxy
  Man:/usr/local/share/man/man1
  
2       初步配置、运行及测试
  1)  在 /usr/local/sbin下建配置文件ha.conf,内容如下:
  global
  daemon
  maxconn 256
  
  defaults
  mode http
  timeout connect 5000ms
  timeout client 50000ms
  timeout server 50000ms
  
  frontend http-in
  bind *:80
  default_backend servers
  
  backend servers
  server server1 127.0.0.1:8080 maxconn 32
  2)  启动tomcat服务,服务端口:8080
  3)  启动haproxy,命令:haproxy  -f ha.conf
  4)  验证:在其它机器上访问http://IP:8080可以打开tomcat首页面
  同样,通过http://IP也可以打开tomcat首页面,表明安装配置成功。
  
3       负载均衡简单测试
  1)  复制并修改tomcat的端口号为8000,启动,测试http 8000端口
  2)  修改8000端口下ROOT下的index.html,Title部分改为Apache Tomcat-8000
  3)  修改haproxy配置文件,增加一行server server2 127.0.0.1:8000 maxconn 32
  4)  重新启动,命令haproxy  –f  ha.conf –st [pid],pid为原来haproxy的进程号
  5)  http://IP多次快速访问验证,两个页面Title会有变化
  
  表明负载均衡在起作用。
4       运行命令
  [iyunv@localhost sbin]# haproxy
  HA-Proxy version 1.4.15 2011/04/08
  Copyright 2000-2010 Willy Tarreau <w@1wt.eu>
  
  Usage : haproxy [-f <cfgfile>]* [ -vdVD ] [ -n <maxconn> ] [ -N <maxpconn> ]
  [ -p <pidfile> ] [ -m <max megs> ]
  -v displays version ; -vv shows known build options.
  -d enters debug mode ; -db only disables background mode.
  -V enters verbose mode (disables quiet mode)
  -D goes daemon
  -q quiet mode : don't display messages
  -c check mode : only check config files and exit
  -n sets the maximum total # of connections (2000)
  -m limits the usable amount of memory (in MB)
  -N sets the default, per-proxy maximum # of connections (2000)
  -p writes pids of all children to this file
  -sf/-st [pid ]* finishes/terminates old pids. Must be last arguments.
  
5       插入cookie持久负载均衡
  配置文件如下:
  global
  daemon
  maxconn 256
  
  defaults
  mode http
  cookie machine insert
  balance rdp-cookie(machine)
  timeout connect 5000ms
  timeout client 50000ms
  timeout server 50000ms
  
  frontend http-in
  bind *:80
  default_backend servers
  
  backend servers
  server server1 127.0.0.1:8080 cookie first maxconn 32
  server server2 127.0.0.1:8000 cookie second maxconn 32
  
  1)  Haproxy接收到浏览器请求,如果没有cookie machine,则顺序抽取一个server请求
  2)  haproxy在回应给浏览器之前,根据内容来自server1还是server2来插入cookie(machine=first 或者machine=second)
  3)  浏览器接收到回应的cookie,再次访问的时候会带上cookie
  4)  Haproxy根据cookie machine的&#20540;来判断应该将请求转到对应的server
6       配置详解
6.1     Global参数
  * 进程管理及安全Process management and security
  - chroot
  - daemon
  - gid
  - group
  - log
  - log-send-hostname
  - nbproc
  - pidfile
  - uid
  - ulimit-n
  - user
  - stats
  - node
  - description
  
  * 性能调优Performance tuning
  - maxconn
  - maxpipes
  - noepoll
  - nokqueue
  - nopoll
  - nosepoll
  - nosplice
  - spread-checks
  - tune.bufsize
  - tune.chksize
  - tune.maxaccept
  - tune.maxpollevents
  - tune.maxrewrite
  - tune.rcvbuf.client
  - tune.rcvbuf.server
  - tune.sndbuf.client
  - tune.sndbuf.server
  
  * 调试Debugging
  - debug
  - quiet
  
  
6.2     Proxies
  ----------
  
  Proxy configuration can be located in a set of sections :
  - defaults <name>
  - frontend <name>
  - backend  <name>
  - listen   <name>
  
  A &quot;defaults&quot; section sets default parameters for all other sections following
  its declaration. Those default parameters are reset by the next &quot;defaults&quot;
  section. See below for the list of parameters which can be set in a &quot;defaults&quot;
  section. The name is optional but its use is encouraged for better readability.
  
  A &quot;frontend&quot; section describes a set of listening sockets accepting client
  connections.
  
  A &quot;backend&quot; section describes a set of servers to which the proxy will connect
  to forward incoming connections.
  
  A &quot;listen&quot; section defines a complete proxy with its frontend and backend
  parts combined in one section. It is generally useful for TCP-only traffic.
  
  

运维网声明 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-141467-1-1.html 上篇帖子: HAproxy 虚拟主机 下篇帖子: linux学习之使用keepalived+haproxy搭建高可用服务器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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