rhtconsulting.haproxy

haproxy

用于安装和配置 HAProxy 的 Ansible 角色,适用于一个或多个负载均衡的应用程序。

该角色认为,用户不应该过多关注 HAProxy 的前端和后端服务器的配置,而是应该专注于配置需要负载均衡的应用程序。因此,使用该角色时,用户只需指定希望负载均衡的应用程序,角色将自动处理 HAProxy 的前端和后端服务器的配置。

要求

运行该角色所需的条件。

软件包

必须安装的软件包:

  • haproxy

服务

必须启用的服务,以便角色可以进行配置:

  • firewalld

角色变量

关于预期角色参数的信息。

参数 必需 默认值 可选项 注释
haproxy_applications 定义需要负载均衡的应用程序的哈希列表

haproxy_applications

haproxy_applications 参数是定义需要负载均衡的应用程序的哈希列表。列表中的每一项可以包含以下参数。

参数 必需 默认值 可选项 注释
name 应用程序的名称,用于定义前端和后端服务器,应该具有描述性,会显示在 HAProxy 统计信息中。必须匹配 /a-zA-Z0-9-_/
domain FQDN,解析到 HAProxy 服务器,以便进行负载均衡的 servers。可以是简单的 FQDN 也可以是匹配域名的正则表达式。
domain_is_regex false true, false 如果给定的 domain 是正则表达式则为 true,否则为 false
expose_http false true, false 如果为 true,则在 http 上暴露此应用程序;如果为 false,则不暴露。
expose_https false true, false 如果为 true,则在 https 上暴露此应用程序;如果为 false,则不暴露。
redirect_http_to_https false true, false 如果为 true,则自动将 http 重定向到 https;如果为 false,则不重定向。
servers 定义需要负载均衡的服务器哈希列表。

servers

haproxy_applications 列表中的每一项必须包含一个 servers 键,值为定义要负载均衡的相应应用程序的服务器哈希列表。列表中的每一项可以包含以下参数。

参数 必需 默认值 可选项 注释
name 用于引用服务器的名称。将显示在 HAProxy 统计信息中。必须匹配 /a-zA-Z0-9-_/
address 要负载均衡的服务器的 FQDN 或 IP 地址。
port_http 80 expose_httptrue 时,负载均衡的服务器在 address 的端口。
port_https 443 expose_httpstrue 时,负载均衡的服务器在 address 的端口。

示例剧本

负载均衡 Ansible Tower

- name: HAProxy
  hosts: haproxy
  roles:
    - role: haproxy
      haproxy_applications:
        - name: ansible-tower
          domain: tower.example.com
          expose_https: True
          redirect_http_to_https: True
          servers:
            - name: tower0002
              address: tower0002.example.com
            - name: tower0003
              address: tower0003.example.com
            - name: tower0004
              address: tower0004.example.com

负载均衡 OpenShift Container Platform (OCP) 主节点和路由

- name: HAProxy
  hosts: haproxy
  roles:
    - role: haproxy
      haproxy_applications:
        - name: ocp-admin
          domain: ocp.example.com
          expose_https: True
          redirect_http_to_https: True
          servers:
            - name: ocp0002-master
              address: ocp0002.example.com
            - name: ocp0003-master
              address: ocp0003.example.com
            - name: ocp0004-master
              address: ocp0004.example.com
        - name: ocp-router
          domain: .*.apps.example.com
          domain_is_regex: True
          expose_https: True
          expose_http: True
          redirect_http_to_https: False
          servers:
            - name: ocp0005-infra
              address: ocp0005.example.com
            - name: ocp0006-infra
              address: ocp0006.example.com
            - name: ocp0007-infra
              address: ocp0007.example.com

作者信息

关于项目

Ansible role for installing and configuring HAProxy for one or many frontend and backend servers.

安装
ansible-galaxy install rhtconsulting.haproxy
许可证
apache-2.0
下载
145.4k