HAproxy负载均衡部署

1、安装HAproxy

yum -y install haproxy

2、编辑配置文件

#---------------------------------------------------------------------

# Example configuration for a possible web application.  See the

# full configuration options online.

#

#  http://haproxy.1wt.eu/download/1.4/doc/configuration.txt

#

#---------------------------------------------------------------------

#---------------------------------------------------------------------

# Global settings

#---------------------------------------------------------------------

global

    # to have these messages end up in /var/log/haproxy.log you will

    # need to:

    #

    # 1) configure syslog to accept network log events.  This is done

    #    by adding the '-r' option to the SYSLOGD_OPTIONS in

    #    /etc/sysconfig/syslog

    #

    # 2) configure local2 events to go to the /var/log/haproxy.log

    #  file. A line like the following can be added to

    #  /etc/sysconfig/syslog

    #

    #    local2.*                      /var/log/haproxy.log

    #

    log        127.0.0.1 local2      #定义日志

    chroot      /var/lib/haproxy     #定义haproxy的家目录,

    pidfile    /var/run/haproxy.pid  #定义pid

    maxconn    4000              #设置最大并发连接数

    user        haproxy          #用户名

    group      haproxy          #用户组

    daemon                        #以守护进程模式运行

    # turn on stats unix socket

    stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------

# common defaults that all the 'listen' and 'backend' sections will

# use if not designated in their block

#---------------------------------------------------------------------

defaults  #默认参数

    mode                    http

    log                    global

    option                  httplog

    option                  dontlognull

    option http-server-close

    option forwardfor      except 127.0.0.0/8

    option                  redispatch

    retries                3

    timeout http-request    10s

    timeout queue          1m

    timeout connect        10s

    timeout client          1m

    timeout server          1m

    timeout http-keep-alive 10s

    timeout check          10s

    maxconn                3000

listen stats    #状态信息

    mode http 

    bind *:1080  #绑定端口

    stats enable #开启或者关闭

    stats hide-version #关闭版本信息

    stats uri  /haproxy?admin #web状态界面的url

    stats realm Haproxy\ Statistics #

    stats auth admin:admin  #认证的用户名:密码

    stats admin if TRUE    #如果认证成功开启admin


frontend http-in    #前端配置

  bind *:80        #前端绑定端口

  mode http        #http

  log global      #全局日志

  option httpclose #

  option logasap

  capture request header Host len 20

  capture request header Referer len 60

  default_backend http-server

backend http-server  #后端web服务集群

  balance roundrobin  #调度算法模式

  server web1 192.168.10.150:81  check maxconn 4000  #后端web列表

  server web2 192.168.10.122:80  check maxconn 3000

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在大型系统设计中用代理在负载均衡是最常见的一种方式,而相对靠谱的解决方案中Nginx、HAProxy、LVS、F5...
    欢醉阅读 10,089评论 1 5
  • 互联网架构基础知识 一、网站常见架构 负载层 页面缓存层 web层 数据层 二、运维法则 缓存为王 尽量在前端(缓...
    魏镇坪阅读 10,288评论 0 9
  • FileName: KeepAlived+Haproxy集群.txt Function: Implement th...
    richard520阅读 7,366评论 1 2
  • 参考文档: 1.haproxy:http://www.haproxy.org/ 本文涉及haproxy的安装,并做...
    Netonline阅读 7,046评论 1 51
  • 有的时候,你很爱一个人,其实只是你自己的事,像一出独角戏。到最后,最感动的人,不过是你自己。可是,有什么关系...
    林静姝阅读 1,469评论 0 0