前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Haproxy combined with FTP cluster for load balancing

Haproxy combined with FTP cluster for load balancing

作者头像
dogfei
发布2020-07-31 10:16:23
9670
发布2020-07-31 10:16:23
举报
文章被收录于专栏:devops探索devops探索

Haproxy介绍

Haproxy具有以下功能:

  • 第4层(TCP)和第7层(HTTP)负载均衡
  • URL重写
  • 限速
  • GZIP压缩
  • 代理协议支持
  • 健康检查
  • 多线程

Haproxy主要支持以下算法:

  • rr轮询算法,用于短连接
  • lc最少连接数算法,用于长连接
  • source源地址算法,用于SSL集群或者终端服务器集群,直接根据客户端的源IP地址来选择对应服务器
  • uri算法,用于HTTP缓存
  • hdr算法,根据指定的HTTP HEADER内容来选择对应服务器
  • first算法,用于短生命周期的虚拟机

安装与配置

目前的最新稳定版是1.9,后面使用的均是此版本

导入仓库源并下载 sudo add-apt-repository ppa:vbernat/haproxy-1.9 sudo apt-get update sudo apt install haproxy haproxy -v

配置介绍

分为两大部分

  • global配置段,用于设定全局配置参数
  • proxy配置段
    • defaults,用于为其他配置段提供默认参数
    • frontend,用于定义一系列监听的地址和端口信息,用于客户端与之建立连接
    • backend,用于后端服务器,代理会将对应客户端的请求转发至服务器
    • listen,通过关联frontend和backend,定义了一个完整的代理,通常只对TCP流量有用
配置参考
代码语言:javascript
复制
$ cat /etc/haproxy/haproxy.cfg 
global
        log 127.0.0.1   local0   #日志输出配置,所有日志都记录在本机,通过local0输出
        log 127.0.0.1   local1 notice   #定义haproxy的日志级别,[error warnning notice info debug]
        chroot /var/lib/haproxy   
        stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
        stats timeout 30s
        user haproxy
        group haproxy
        daemon  #以后台形式运行

        # Default SSL material locations
        ca-base /etc/ssl/certs
        crt-base /etc/ssl/private

        # Default ciphers to use on SSL-enabled listening sockets.
        # For more information, see ciphers(1SSL). This list is from:
        #  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
        # An alternative list with additional directives can be obtained from
        #  https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy
        ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
        ssl-default-bind-options no-sslv3

defaults
        log     global
        mode    tcp    #有三种[tcp http health],其中health只会返回ok
        option  tcplog   #日志类别
        option  dontlognull   #不记录健康检查日志信息
        retries 2  #两次连接失败认为是服务器不可用
        timeout connect 5000   #连接超时
        timeout client  50000  #客户端超时时间
        timeout server  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

frontend ftp-server
        bind *:21
        default_backend ftp-server-pool

frontend ftp-server-244
        bind *:20001-20500
        default_backend ftp-port-range-244

frontend ftp-server-245
        bind *:20501-30000
        default_backend ftp-port-range-245

frontend ftp-server-246
        bind *:30001-30500
        default_backend ftp-port-range-246

backend ftp-server-pool
        balance roundrobin
        server ftp-port-range-244 10.1.1.244 check port 21 inter 10s rise 1 fall 2  
        server ftp-port-range-245 10.1.1.245 check port 21 inter 10s rise 1 fall 2
        server ftp-port-range-246 10.1.1.246 check port 21 inter 10s rise 1 fall 2
#check inter 10s 是检测心跳频率
#rise 2 是两次正确认为服务器可用
#fall 2 两次失败认为服务器不可用
backend ftp-port-range-244
        server ftp-port-range-244 10.1.1.244 check port 21 inter 10s rise 1 fall 2

backend ftp-port-range-245
        server ftp-port-range-245 10.1.1.245 check port 21 inter 10s rise 1 fall 2

backend ftp-port-range-246
        server ftp-port-range-246 10.1.1.246 check port 21 inter 10s rise 1 fall 2
启动测试
代码语言:javascript
复制
启动之前先检查配置文件是否正确
$ haproxy -f /etc/haproxy/haproxy.cfg -c
Configuration file is valid
启动
$ sudo systemctl restart haproxy

FTP集群部署

参考之前的博客:

ubuntu下部署FTP服务器

centos7下搭建ftp服务器

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-01-13,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Haproxy介绍
  • 安装与配置
    • 配置介绍
      • FTP集群部署
      • ubuntu下部署FTP服务器
      • centos7下搭建ftp服务器
      相关产品与服务
      负载均衡
      负载均衡(Cloud Load Balancer,CLB)提供安全快捷的流量分发服务,访问流量经由 CLB 可以自动分配到云中的多台后端服务器上,扩展系统的服务能力并消除单点故障。负载均衡支持亿级连接和千万级并发,可轻松应对大流量访问,满足业务需求。
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档