1. 编译安装haproxy

官网: http://www.haproxy.org

1.1 下载haproxy

# wget http://www.haproxy.org/download/1.6/src/haproxy-1.6.14.tar.gz

1.2 解压haproxy

# .tar.gz

1.3 查看编译方法

# less README

下面选自README
To build haproxy, you have to choose your target OS amongst the following ones
and assign it to the TARGET variable :

  - linux22     for Linux 2.2
  - linux24     for Linux 2.4 and above (default)
  - linux24e    for Linux 2.4 with support for a working epoll (> 0.21)
  - linux26     for Linux 2.6 and above
  - linux2628   , .x, and above (enables splice and tproxy)
  - solaris      or  (others untested)
  - freebsd      to  (others untested)
  - netbsd      for NetBSD
  - osx         for Mac OS/X
  - openbsd     for OpenBSD 3.1 and above
  - aix51       for AIX 5.1
  - aix52       for AIX 5.2
  - cygwin      for Cygwin
  - generic     for any other OS or version.
  - custom      to manually adjust every setting

By default, the DEBUG variable is set to '-g' to enable debug symbols. It is
not wise to disable it on uncommon systems, because it's often the only way to
get a complete core when you need one. Otherwise, you can set DEBUG to '-s' to
strip the binary.

For example, I use this to build  :

    $ 

And I build it this way on OpenBSD or FreeBSD :

    $ gmake TARGET=freebsd USE_PCRE= USE_OPENSSL= USE_ZLIB=

And on a classic Linux with SSL and ZLIB support (eg: Red Hat .x) :

    $  USE_OPENSSL= USE_ZLIB=

And on a recent Linux >=  with SSL and ZLIB support :

    $  USE_OPENSSL= USE_ZLIB=

In order to build a -bit binary on an x86_64 Linux system with SSL support
without support for compression but when OpenSSL requires ZLIB anyway :

    $  ADDLIB=-lz

1.4 安装:

#  USE_OPENSSL= USE_ZLIB=
安装方法是根据自己内核版本来了,具体查看内核的方法:
# uname -a

# make install PREFIX=/usr/local/haproxy

2. haproxy最简单的配置

2.1 拷贝配置文件

# mkdir -p /usr/local/haproxy/conf/
# cp -a examples/content-sw-sample.cfg /usr/local/haproxy/conf/
# mv /usr/local/haproxy/conf/content-sw-sample.cfg /usr/local/haproxy/conf/http_haproxy.conf

配置配置文件如下

# cat http_haproxy.conf | grep -v "#"

global
        maxconn
        log             127.0.0.1 local0
        uid
        gid
        chroot          /usr/local/haproxy/var
        daemon

frontend public
        bind             name clear
        mode            http
        default_backend dynamic
        timeout client  30s

backend dynamic
        mode            http
        timeout connect 5s
        timeout server  30s
        timeout queue   30s
        balance         roundrobin
        server          server_01  minconn  maxconn  check inter
        server          server_02  minconn  maxconn  check inter
# 

2.2 检查语法

# ./haproxy -f /usr/local/haproxy/conf/http_haproxy.conf -c
Configuration file is valid
#

2.3 测试访问

# netstat -tulnp | grep haproxy
tcp                          /./haproxy
#

# curl -I http://192.168.31.243:81/
HTTP/ OK
Server: nginx/
Date: Mon,  Jan  :: GMT
Content-Type: text/html
Content-Length:
Last-Modified: Tue,  Dec  :: GMT
ETag: "5c1898d6-27c"
Accept-Ranges: bytes

# curl -I http://192.168.31.243:80
HTTP/ OK
Server: nginx/
Date: Mon,  Jan  :: GMT
Content-Type: text/html
Content-Length:
Last-Modified: Tue,  Dec  :: GMT
Connection: keep-alive
ETag: "5c1898d6-27c"
Accept-Ranges: bytes

# 

3. 出现的问题和解决的办法

3.1 haproxy 默认log不输出的问题

在haproxy配置文件中,指定了 log 输出为 local0 之后,同时也在 /etc/rsyslog.conf 配置了

local0.*                                                /var/log/haproxy.log

发现还是不行,最后发现UDPServer未开启导致的,

# cat /etc/rsyslog.conf | grep "UDPServerRun"
$UDPServerRun
#

UDPServerRun 514 需要打开
验证是否打开
# netstat -tulnp | grep 514
udp        0      0 0.0.0.0:514                 0.0.0.0:*                               2772/rsyslogd
udp        0      0 :::514                      :::*                                    2772/rsyslogd
# 

 

负载均衡器之 Haproxy的更多相关文章

  1. 软件级负载均衡器(LVS/HAProxy/Nginx)的特点简介和对比

    本文出自 “抚琴煮酒” 博客,出处http://andrewyu.blog.51cto.com/1604432/697466   现在网站发展的趋势对网络负载均衡的使用是随着网站规模的提升根据不同的阶 ...

  2. Haproxy原理(1)

    一.四层和七层负载均衡的区别 所谓的四层就是ISO参考模型中的第四层.四层负载均衡也称为四层交换机,它主要是通过分析IP层及TCP/UDP层的流量实现的基于IP加端口的负载均衡.常见的基于四层的负载均 ...

  3. 关于haproxy

    高性能负载均衡软件 haproxy 一.四层和七层负载均衡的区别: 所谓的四层就是OSI参考模型中的第四层,四层负载均衡也称为四层交换机,他主要是通过分析IP层及TCP/UDP层的流量实现的基于IP加 ...

  4. PXC5.7(Percona XtraDB Cluster)+HAproxy+Keepalived 集群部署

    Percona-XtraDB-Cluster+Haproxy 搭建集群环境 环境准备及服务器信息: 配置防火墙 firewall-cmd --add-port=3306/tcp --permanent ...

  5. HAProxy详解(一):HAProxy介绍【转】

    一.高性能负载均衡软件HAProxy介绍: 随着互联网业务的迅猛发展,大型电商平台和门户网站对系统的可用性和可靠性要求越来越高,高可用集群.负载均衡集群成为一种热门的系统架构解决方案.在众多的负载均衡 ...

  6. HAProxy从零开始到掌握

    转自:https://www.jianshu.com/p/c9f6d55288c0 目录: HAProxy是什么 HAProxy的核心能力和关键特性 HAProxy的安装和运行 使用HAProxy搭建 ...

  7. 1、代理服务器及haproxy基础

    1.web站点架构 前端一台主机提供app server,当用户请求到达时,如果要存储结构化数据,就需要找一台主机做database server.当业务达到一定程度时,要把web server.存储 ...

  8. [转]Haproxy原理(1)

    本文出处:https://www.cnblogs.com/skyflask/p/6970151.html 目录 一.四层和七层负载均衡的区别二.HAProxy与LVS的异同三.快速安装HAProxy集 ...

  9. Haproxy基础知识 -运维小结

    开源软件负载均衡器 现在常用的三大开源软件负载均衡器分别是Nginx.LVS.Haproxy. 在之前的文章中已经对比了这三个负载均衡软件, 下面根据自己的理解和使用经验, 再简单说下这三个负载均衡软 ...

随机推荐

  1. windows 下用命令来操作定时任务

    cmd下定时执行命令可以使用 at 命令 或者 schtasks命令.at 语法:at +时间+运行程序schtasks语法:schtasks /creat /tn 设定定时运行的名字 /tr “运行 ...

  2. aop原理及理解

    概念 Aspect Oriented Programming,面向切面编程,实际上它是一个规范.一种设计思路,总之是抽象的. 先上图 使用目的 从项目结构上来说 对业务逻辑的各个部分进行隔离,降低业务 ...

  3. tensorflow安装和初使用

    本文的目的是为了复习并帮助刚开始起步使用机器学习的人员 1.安装准备 为了方便就在window上安装,我的是window10 的笔记本,首先准备python 因为tensorflow在仅仅支持wind ...

  4. C# 截取两个指定字符串中间的字符串列表

    /// <summary> /// 截取两个指定字符串中间的字符串列表(开始和结束两个字符串不能相同!) /// </summary> /// <param name=& ...

  5. Python学习笔记6函数和代码复用

    1.函数 (1)定义: (2)函数调用 (3)函数的参数传递 参数传递的两种方式:函数调用时,参数可以按照位置或名称的方式传递 (4)函数的返回值 (5)局部变量和全局变量 (6)lambda函数 2 ...

  6. 解决npm ERR! Unexpected end of JSON input while parsing near的方法

    这两天执行 npm install 时会报错误: npm ERR! Unexpected end of JSON input while parsing near 清除cache npm cache ...

  7. opencv关于Mat类中的Scalar()---颜色赋值

    这个 CvScalar就是一个可以用来存放4个double数值的数组(O'Reilly的书上写的是4个整型成员):一般用来存放像素值(不一定是灰度值哦)的,最多可以存放4个通道的. typedef s ...

  8. VSCode的使用

    前后端分离的,先打开vs,打开你的项目,在项目根目录中找到.vs文件加,找到.vs\config\applicationhost.config,然后打开找到你项目的IIS Express配置,例如:& ...

  9. 为什么text的值改变后onchange没有反应?

    onchange发生在元素失去焦点后,而不是想象中的元素的值发生改变的时候.其实它的作用就跟onblur(失去焦点事件)差不多,只不过onchange是失去焦点且值发生了改变.要想实现目的,可以改用o ...

  10. 使用react-handsontable

    新建一个项目 create-react-app myProject cd myProject npm install handsontable 或者 npm install handsontable- ...