bimdata.fluentd

Ansible 角色 Fluentd

此角色用于安装和配置 Fluentd。

要求

  • 此角色仅在 Debian 12.x(Bookworm)上测试。

角色变量

此角色尽量保持与手动安装 Fluentd 时相同的默认配置。 您可以在 Fluentd 文档 中找到有关每个选项的更多信息。

用于安装的变量:

变量 默认值 描述
fluentd_prerequisites ['apt-transport-https', 'curl', 'gnupg'] 安装 Fluentd 之前需要安装的包列表。
fluentd_major_version 5 您想要安装的 Fluentd 主要版本。
fluentd_apt_key_url https://packages.treasuredata.com/GPG-KEY-td-agent Fluentd 包的 APT 密钥。
fluentd_apt_repos_url "https://packages.treasuredata.com/{{ fluentd_major_version }}/{{ ansible_distribution lower }}/{{ ansible_distribution_release
fluentd_apt_repos_suites "{{ ansible_distribution_release lower }}"
fluentd_apt_repos_components ['contrib'] APT 仓库组成部分。
fluentd_pkg_name fluent-package Fluentd APT 包名。
fluentd_pkg_version: "" 安装特定版本的包。
fluentd_pkg_version_hold "{{ fluentd_pkg_version default(False)
fluentd_svc_name fluentd 启动/停止守护进程的 Fluentd 服务名称。

用于删除遗留内容的变量(例如,如果在重命名 td-agent 为 fluentd 之前安装):

变量 默认值 描述
fluentd_apt_cleanup_legacy false 如果为 true,则删除旧密钥和旧 APT 来源。
fluentd_apt_key_legacy_id BEE682289B2217F45AF4CC3F901F9177AB97ACBE 要从密钥环中删除的旧 GPG 密钥 ID。
fluentd_naming_cleanup_legacy false 删除名为 td-agent 的旧服务/配置/APT。
fluentd_pkg_name_legacy td-agent 将被遗留清理器删除的包名。
fluentd_svc_name_legacy td-agent 将被遗留清理器删除的服务名称。
fluentd_conf_directory_legacy /etc/td-agent/ 将被遗留清理器删除的配置目录。

用于通用配置的变量:

变量 默认值 描述
fluentd_plugins [] 要安装的插件列表。
fluentd_gem_exec_path /usr/sbin/fluent-gem 安装 Fluentd 插件的 Gem 二进制路径。
fluentd_system {} Fluentd 系统配置。
fluentd_conf_directory "/etc/fluent" Fluentd 配置目录。
fluentd_conf_file_path "{{ fluentd_conf_directory }}/fluentd.conf" Fluentd 配置文件路径。
fluentd_include_directory 未定义 可用于包含其他配置文件。在配置中将添加 @include {{ fluentd_include_directory }}*.conf

对于 fluentd_system,每个键都用作配置选项名称,值用作值。 您可以在 Fluentd 文档 中查看所有可用选项。

fluentd_plugins 是一个将由 fluentd_gem_exec_path 安装的插件列表。 您可以为每个插件指定所需的版本:

fluentd_plugins:
  - name: fluent-plugin-prometheus
    version: 2.0.0

用于日志处理的变量:

变量 默认值 描述
_fluentd_sources: "{{ lookup('template', './lookup/get_sources.j2') }}" 定义所有源配置的字典列表。
_fluentd_filters: "{{ lookup('template', './lookup/get_filters.j2') }}" 定义所有过滤器配置的字典列表。
_fluentd_labels: "{{ lookup('template', './lookup/get_labels.j2') }}" 定义所有标签配置的字典列表。
_fluentd_matches: "{{ lookup('template', './lookup/get_matches.j2') }}" 定义所有匹配配置的字典列表。

在大多数情况下,您不应修改这些变量。 模板化用于与其他变量构建这些列表。

  • _fluentd_sources 将聚合所有名称匹配此正则表达式的变量:^fluentd_.+_source(s)?$
  • _fluentd_filters 将聚合所有名称匹配此正则表达式的变量:^fluentd_.+_filter(s)?$
  • _fluentd_labels 将聚合所有名称匹配此正则表达式的变量:^fluentd_.+_label(s)$
  • _fluentd_matches 将聚合所有名称匹配此正则表达式的变量:^fluentd_.+_match(es)?$

每个匹配这些正则表达式的变量必须是:

  • 定义一个源/过滤器/标签/匹配的字典
  • 定义一个或多个源/过滤器/标签/匹配的字典列表。

每个字典用于定义 Fluentd 配置文件中的一个 <source><filter><label><match> 部分。每个配置部分通过键/值对进行配置,因此字典的键用作配置键,值用作值。

某些键具有特殊行为:

  • type 将替换为 @type
  • id 将替换为 @id
  • label 将替换为 @label
  • log_level 将替换为 @log_level
  • _section_args 是一个特殊键,用于定义会被配置匹配的标签等内容。
  • 对于标签配置(与 ^fluentd_.+_label(s)$ 匹配的变量),键 name 用于定义标签的名称,如 <label @my_name>
  • 字典不能有重复键,因此每个需要重复的键可以以匹配此正则表达式 ^[0-9]+__ 的前缀开始。生成配置时前缀将被删除。

例如:

fluentd_default_forward_source:
  type: forward
  id: forward
  bind: 0.0.0.0
  port: 24224

fluentd_systemd_filters:
  - _section_args: "systemd.**"
    type: systemd_entry
    id: parse_systemd
    field_map: '{"_HOSTNAME": "host"}'
    field_map_strict: "false"
    fields_lowercase: "true"
    fields_strip_underscores: "true"
  - _section_args: "systemd.unknown"
    type: record_modifier
    id: parse_unknown
    record:
      comm: unknown

fluentd_archive_label:
  name: archive
  filter:
    _section_args: "**"
    type: record_modifier
    whitelist_keys: host, message
  0__match:
    _section_args: "syslog.*.4 syslog.*.10"
    type: file
    id: archives_syslog_auth
    path: /logs/archives/${host}/auth-%Y%m%d
  1__match:
    _section_args: "**"
    type: "null"
    id: archives_drop

将产生:

<source>                                                                                                  
  @type forward                                                                                           
  @id forward                                                                                             
  bind 0.0.0.0                                                                                            
  port 24224                                                                                              
</source>

<filter systemd.**>                                                                                       
  @type systemd_entry                                                                                     
  @id parse_systemd                                                                                       
  field_map {"_HOSTNAME": "host"}                                                                         
  field_map_strict false                                                                                  
  fields_lowercase true                                                                                   
  fields_strip_underscores true                                                                           
</filter>                                                                                                 
<filter systemd.unknown>                                                                                  
  @type record_modifier                                                                                   
  @id parse_unknown                                                                                       
  <record>                                                                                                
    comm unknown                                                                                          
  </record>                                                                                               
</filter>

<label @archive>
  <filter **>
    @type record_modifier
    whitelist_keys host, message
  </filter>
  <match syslog.*.4 syslog.*.10>
    @type file
    @id archives_syslog_auth
    path /logs/archives/${host}/auth-%Y%m%d
  </match>
  <match **>
    @type null
    @id archives_drop
  </match>
</label>

它允许您在多个 group_vars 中定义变量,并在多个组中的主机之间累积它们,而无需重写完整列表。

依赖关系

没有

许可证

BSD

作者信息

BIMData.io

关于项目

This role installs and configures Fluentd.

安装
ansible-galaxy install bimdata.fluentd
许可证
mit
下载
1.1k
拥有者