zz22 发表于 2015-9-4 14:00:11

centos6.5 64位上haproxy安装

  haproxy提供高可用性、负载均衡以及基于TCP和HTTP应用的代 理,支持虚拟主机,它是免费、快速并且可靠的一种解决方案。
  下载:目前来看官网是没法下载了只能通过baidu来找寻(nn的google也不能访问了)
  # cdhaproxy-1.4.17
  # make TARGET=linux26 CPU=x86_64 PREFIX=/usr/local/haprpxy
  # make install PREFIX=/usr/local/haproxy
  # mkdir -p /usr/local/haproxy/conf
  # mkdir -p /etc/haproxy
  # cp ~/haproxy-1.4.17/examples/haproxy.cfg /usr/local/haproxy/conf/haproxy.cfg
  # ln -s /usr/local/haproxy/conf/haproxy.cfg /etc/haproxy/haproxy.cfg
  # cp -r ~/haproxy-1.4.17/examples/errorfiles /usr/local/haproxy/errorfiles
  # ln -s /usr/local/haproxy/errorfiles /etc/haproxy/errorfiles
  # mkdir -p /usr/local/haproxy/log
  # touch /usr/local/haproxy/log/haproxy.log
  # ln -s /usr/local/haproxy/log/haproxy.log /var/log/haproxy.log
  # cp ~/haproxy-1.4.17/examples/haproxy.init /etc/rc.d/init.d/haproxy
  # chmod +x /etc/rc.d/init.d/haproxy
  # chkconfig haproxy on
  # ln -s /usr/local/haproxy/sbin/haproxy /usr/sbin

  # cp/usr/local/haproxy/conf/haproxy.cfg   /usr/local/haproxy/conf/haproxy.cfg-bak
  # service haproxy restart
  配置文件
  #vi /usr/local/haproxy/conf/haproxy.cfg
  global
      log 127.0.0.1   local0
      maxconn 65536            #最大连接数
      chroot /usr/local/haproxy
      uid 501
      gid 501
      daemon
      nbproc 1
      pidfile /usr/local/haproxy/logs/haproxy.pid
      #debug
  defaults
      log   global
      log   127.0.0.1       local3
      #mode    http                #如果不单单是http服务在defaults中mode就可以不用http
      retries 2
      maxconn 65536
      contimeout      5000
      clitimeout      50000
      srvtimeout      50000
  listen web_proxy
      bind :80
      mode http
      option httplog
      option httpclose
      option dontlognull
      option forwardfor
      option redispatch
      stats refresh 30s         #统计页面自动刷新时间
      stats uri/stats         #统计页面url
      stats realm baison-test-Haproxy         #统计页面密码框上提示文本
      stats auth admin:admin123         #统计页面用户名和密码设置
      stats hide-version
      acl is_a hdr_beg(host) -i www.example2.com#判断域名是不是www.example2.com,是则给与a服务器集群服务
      acl is_b hdr_beg(host) -i www.example3.com#判断域名是不是www.example3.com,是则给与a服务器集群服务
      acl is_c hdr_beg(host) -i www.example4.com#判断域名是不是www.example4.com,是则给与a服务器集群服务
  use_backend a_server if is_a
      use_backend b_server if is_b
      use_backend b_server if is_c
  backend a_server
      mode http #http 模式
      stats   uri/haproxy
      balance roundrobin
      cookieJSESSIONID prefix
      stats   hide-version
      optionhttpclose
      server web1_192.168.200.148 192.168.200.148:80 cookie app1inst1 check inter 2000 rise 2 fall 5
      server web1_192.168.200.149 192.168.200.149:80 cookie app1inst1 check inter 2000 rise 2 fall 5
  backend b_server
      mode http #http 模式
      stats   uri/haproxy
      balance source
      cookieJSESSIONID prefix
      stats   hide-version
      optionhttpclose
      server tomcat1_192.168.200.148 192.168.200.148:8081 #cookie app1inst1 check #inter 2000 rise 2 fall 5
      server tomcat1_192.168.200.149 192.168.200.149:8081 #cookie app1inst1 check #inter 2000 rise 2 fall 5
  listen monitor_proxy
      bind :10000
      mode tcp
      server monitor1_192.168.200.148192.168.200.148:10000 check inter 2000 rise 2 fall 5
      server monitor1_192.168.200.149192.168.200.149:10000 check inter 2000 rise 2 fall 5
  
页: [1]
查看完整版本: centos6.5 64位上haproxy安装