HAProxy

基本信息

0什麼是HAProxy

  HAProxy提供高可用性、負載均衡以及基於TCP和HTTP應用的代 理,支持虛擬主機,它是免費、快速並且可靠的一種解決方案。HAProxy特別適用於那些負載特大的web站點,這些站點通常又需要會話保持或七層處理。HAProxy運行在當前的硬件上,完全可以支持數以萬計的併發連接。並且它的運行模式使得它可以很簡單安全的整合進您當前的架構中, 同時可以保護你的web服務器不被暴露到網絡上。

1安裝HAProxy

  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

2配置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.1local3
  retries 3
  option redispatch
  maxconn 2000
  contimeout 5000
  clitimeout 50000
  srvtimeout 50000
  listen webinfo :1080
  mode http
  balance roundrobin
  option httpclose
  option forwardfor
  server phpinfo1 192.168.18.2:10000 check weight 1 minconn 1 maxconn 3 check inter 40000
  server phpinfo2 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

3啓動HAProxy

  #啓動haproxy
  /usr/local/haproxy/haproxy -f /usr/local/haproxy/haproxy.cfg
  #查看是否啓動
  [zhangy@BlackGhost haproxy]$ ps -e|grep haproxy
  4859 ? 00:00:00 haproxy
  4860 ? 00:00:00 haproxy

4測試

  [root@BlackGhost haproxy]# /usr/local/bin/webbench -c 100 -t 30 http://localhost:1080/phpinfo.php

5說明

  HAProxy監聽的端口是1080,代理192.168.18.2:10000,127.0.0.1:10000

  統計監聽的是8888端口 http://localhost:8888/haproxy-stats

轉載地址:http://blog.csdn.net/qiume/article/details/7274603

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章