haproxy 笔记

安装

sudo apt-get install haproxy

#版本建议 > 1.4.24
hu@ubuntu:~$ haproxy -vv
HA-Proxy version 1.4.24 2013/06/17
Copyright 2000-2013 Willy Tarreau <w@1wt.eu>

Build options :
  TARGET  = linux2628
  CPU     = generic
  CC      = gcc
  CFLAGS  = -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2
  OPTIONS = USE_PCRE=1

Default settings :
  maxconn = 2000, bufsize = 16384, maxrewrite = 8192, maxpollevents = 200

Encrypted password support via crypt(3): yes

Available polling systems :
     sepoll : pref=400,  test result OK
      epoll : pref=300,  test result OK
       poll : pref=200,  test result OK
     select : pref=150,  test result OK
Total: 4 (4 usable), will use sepoll.

配置文件

配置文件:/etc/haproxy/haproxy.conf

global#全局配置段
        log 0.0.0.0 local0 info
        chroot /var/lib/haproxy   #改变当前工作目录
        user haproxy         #所属用户
        group haproxy        #所属组
        daemon                #以守护进程方式运行haproxy

#------------------------------------------------------------
defaults
        log global
        mode    http    #默认的模式mode { tcp|http|health }
        option  httplog  #启用记录HTTP请求、会话状态和计时器的功能
        option  dontlognull #保证HAProxy不记录上级负载均衡发送过来的用于检测状态没有数据的心跳包。
        contimeout 5000      #客户端超时时间,
        clitimeout 50000  #设置连接客户端发送数据时的成功连接最长等待时间
        srvtimeout 50000 #设置服务器端回应客户度数据发送的最长等待时间
        errorfile 400 /etc/haproxy/errors/400.http
        errorfile 403 /etc/haproxy/errors/403.http
        errorfile 408 /etc/haproxy/errors/408.http
        errorfile 500 /etc/haproxy/errors/500.http
        errorfile 502 /etc/haproxy/errors/502.http
        errorfile 503 /etc/haproxy/errors/503.http
        errorfile 504 /etc/haproxy/errors/504.http

#------------------------------------------------------------
listen admin_stats  #统计页面配置
        bind 0.0.0.0:8888
        option httplog
        stats refresh 20s
        stats uri /stats #统计页面url  http://0.0.0.0:8888/stats 
        stats realm Haproxy Manager
        stats auth admin:admin   #统计页面用户名和密码设置
#------------------------------------------------------------
#代理配置:
#        default: 默认配置----->所有在backend、frontend、linsten中相同内容可以在此定义;
#        frontend:前段配置----->定义前端套接字,接受客户端请求;
#        backend: 后端配置----->定义后端分配规则,与后端服务器交互;
#        listen:  绑定配置----->直接将指定的客户端与后端特定服务器绑定到一起;
listen test2 :8222 #定义一个绑定配置
       #option httpclose  
       option forwardfor  #启用X-Forwarded-For,在requests头部插入客户端IP发送给后端的server,使后端server获取到客户端的真实IP
        server 54 10.10.100.54:80 check weight 1 minconn 1 maxconn 3 check inter 40000        #s1:为后端服务器所设置的内部名称,  10.10.100.54:80 后端服务器的IP地址, weight:分发的权>
重 check:接受健康监测、inter:监测的间隔时长
        server 53 10.10.100.53:80 check weight 1 minconn 1 maxconn 3 check inter 40000 
#------------------------------------------------------------ 
frontend  server1
        mode http
        bind 0.0.0.0:8333
        default_backend real_server3
backend real_server3
        mode http
        balance roundrobin #负载均衡算法(#banlance roundrobin 轮询,balance source 保存session值,支持static-rr,leastconn,first,uri等参数)
       server A 10.10.100.53:80 weight 1  check inter 1000
       server B 10.10.100.54:80 weight 1 check inter 1000
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值