haproxy安装、配置

1、官网
http://www.haproxy.org/
2、安装
下载tar包进行安装,或通过yum进行安装
版本:1.5.18-8.el7

yum list |grep haproxy
yum install haproxy

3、目录结构

/etc/rc.d/init.d/haproxy
/etc/haproxy  #配置文件目录
/etc/logrotate.d/haproxy
/etc/sysconfig/haproxy
/var/lib/haproxy
/usr/share/haproxy
/usr/sbin/haproxy #命令

4、启动

systemctl start haproxy
systemctl status | stop haproxy

5、配置—全局配置

# 全局参数的设置
global      
      # 全局的日志配置,使用log关键字,
      #指定使用127.0.0.1上的syslog服务中的local0日志设备,记录日志等级为info的日志
      log            127.0.0.1   local2                      
      chroot         /var/lib/haproxy        #改变当前工作目录
      pidfile        /var/run/haproxy.pid    #当前进程id文件
      maxconn        4000                    #最大连接数
      user           haproxy                 #所属用户
      group          haproxy                 #所属组
      daemon                              #以守护进程方式运行haproxy
      stats socket   /var/lib/haproxy/stats #基于本地的文件传输

6、配置—default参数配置

defaults
    mode                    http                  #默认使用协议,可以为{http|tcp|health} http:是七层协议 tcp:是四层 health:只返回OK
    log                     global                #全局日志记录
    option                  httplog               #详细记录http日志
    option                  dontlognull           #不记录空日志
    option http-server-close                      #启用http-server-close
    option forwardfor       except 127.0.0.0/8    #来自这些信息的都不forwardfor
    option                  redispatch            #重新分发,ServerID对应的服务器宕机后,强制定向到其他运行正常的服务器
    retries                 3                      #3次连接失败则认为服务不可用
    timeout http-request    10s                    #默认http请求超时时间
    timeout queue           1m                     #默认队列超时时间
    timeout connect         10s                    #默认连接超时时间
    timeout client          1m                     #默认客户端超时时间
    timeout server          1m                     #默认服务器超时时间
    timeout http-keep-alive 10s                    #默认持久连接超时时间
    timeout check           10s                    #默认检查时间间隔
    maxconn                 3000                   #最大连接数

7、配置—监听统计

listen admin_stats  
  bind            0.0.0.0:8709 #监听端口  
  option         httplog #采用http日志格式  
  stats          refresh 30s #统计页面自动刷新时间  
  stats uri      /haproxy #统计页面url  
  stats realm Haproxy Manager #统计页面密码框上提示文本  
  stats auth      admin:admin #统计页面用户名和密码设置  
  stats hide-version #隐藏统计页面上HAProxy的版本信息  

8、配置—front前端配置

9、配置—backend后端配置

10、日志处理
vi /etc/rsyslog.conf
添加配置:

local0.* /var/log/haproxy.log
local1.* /var/log/haproxy.log 

vi /etc/sysconfig/rsyslog
#SYSLOGD_OPTIONS="-c 5" #注释掉默认配置

SYSLOGD_OPTIONS="-c 2 -r -m 0" #添加新配置

#重启系统日志服务
service rsyslog restart

11、cfg配置参考
https://github.com/HariSekhon/HAProxy-configs

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值