Fluentd Elasticsearch Installation and Configuration Guide

Author

Reads 1.2K

A focused close-up of hands typing on a sleek, modern computer setup in an office environment.
Credit: pexels.com, A focused close-up of hands typing on a sleek, modern computer setup in an office environment.

To install Fluentd with Elasticsearch, you'll first need to install Fluentd on your system. This can be done using a package manager like Homebrew on macOS or apt-get on Ubuntu.

Fluentd can be installed using the following command: `brew install fluentd` on macOS or `sudo apt-get install fluentd` on Ubuntu.

Once Fluentd is installed, you'll need to configure it to send data to Elasticsearch. This involves creating a configuration file that specifies the Elasticsearch output plugin.

The Elasticsearch output plugin is used to send data from Fluentd to Elasticsearch. It's a simple plugin to set up and requires only a few configuration options.

Elasticsearch can be installed on your system using a package manager like Homebrew or apt-get. Once installed, you'll need to create an index in Elasticsearch to store your data.

To create an index in Elasticsearch, you can use the following command: `curl -X PUT 'http://localhost:9200/my_index'`. This will create a new index called "my_index" in Elasticsearch.

With Fluentd and Elasticsearch installed and configured, you're ready to start sending data from Fluentd to Elasticsearch. This will allow you to store and analyze your data in Elasticsearch.

Take a look at this: Elasticsearch Index Format

Installation

Credit: youtube.com, DevOps | How To Set Up an Elasticsearch, Fluentd and Kibana (EFK) Logging Stack on Kubernetes

If you're using td-agent v3.0.1 or later, you're in luck - out_elasticsearch is included in the standard distribution, so you don't need to install it manually.

To install out_elasticsearch, you'll need to use the fluent-gem if you've installed Fluentd without td-agent.

This option must be always elasticsearch.

Related reading: Install Elasticsearch Osx

Configuration

Configuration is a crucial aspect of integrating Fluentd with Elasticsearch. You can enable the composable template feature by using elasticsearch_dynamic, but be aware that this has performance and security implications.

The composable template feature allows configurations to depend on information in messages, but it's essential to confirm whether your Elasticsearch cluster(s) support it. This feature is still experimental and requires careful consideration.

To enable the Data Streams feature in Elasticsearch 7.9 and later, specify @type elasticsearch_data_stream. This will automatically create a matching index template and set the ILM default policy to the specified data stream.

Dynamic Configuration

Dynamic configuration is an experimental feature that allows configuration values to be specified in ways that depend on information in messages. This can be achieved using the elasticsearch_dynamic plugin.

For more insights, see: Elasticsearch Setup Configuration

Credit: youtube.com, How to configure Dynamic Routing | Dynamic Routing configuration step by step

The elasticsearch_dynamic plugin is an experimental variation of the Elasticsearch plugin that allows configuration values to be specified in ways that depend on information in messages. This is done using Ruby's eval for every message, which can have performance and security implications.

The default value for dynamic configuration is nil. If you want to use this feature, please confirm that your Elasticsearch cluster(s) support the composable template feature.

Port

The port is a crucial setting in Elasticsearch that allows you to specify the port number for writing data into Elasticsearch indices.

You can specify the Elasticsearch port using the port parameter, which makes writing data into Elasticsearch indices compatible with what Logstash calls them.

This allows you to take advantage of Kibana, a powerful tool for visualizing data in Elasticsearch indices.

The index name will be determined by the logstash_prefix and logstash_dateformat parameters, which will be used to customize the index name pattern.

Take a look at this: Elasticsearch Indices

Cloud Id

A detailed view of an industrial refinery featuring pipelines and large steel structures.
Credit: pexels.com, A detailed view of an industrial refinery featuring pipelines and large steel structures.

You can specify Elasticsearch cloud_id by this parameter. This allows you to authenticate with the cloud.

If you specify cloud_id, you must also specify cloud_auth. This is a required option when using cloud_id.

Host, port, user, and password options are ignored when you use cloud_id. This means you can't use these options in conjunction with cloud_id.

Include Tag, Tag

Including the Fluentd tag in your JSON records can be a game-changer for organization and searchability. You can do this by using the include_tag_key and tag_key options.

The include_tag_key option is used in conjunction with tag_key to add the Fluentd tag to the JSON record. For example, if you have a config like this: include_tag_key, tag_key. The record inserted into Elasticsearch would be.

Include Index in URL

The Include Index in URL option is a game-changer for enforcing access control. With this option set to true, Fluentd manifests the index name in the request URL rather than in the request body.

Consider reading: Elasticsearch Index Api

An artist's illustration of artificial intelligence (AI). This image represents storage of collected data in AI. It was created by Wes Cockx as part of the Visualising AI project launched ...
Credit: pexels.com, An artist's illustration of artificial intelligence (AI). This image represents storage of collected data in AI. It was created by Wes Cockx as part of the Visualising AI project launched ...

This allows you to use URL-based access control, which is a more secure way to manage access to your Elasticsearch indices.

To enable this option, simply set it to true in your configuration.

For example, if you're using the compat_parameters plugin helper, you can use this option to enforce access control on your Elasticsearch indices.

This option is particularly useful when you need to manage access to your indices in a more granular way.

Curious to learn more? Check out: Get All Indices Elasticsearch

Application Name

When specifying the application name for a rollover index, keep in mind that this parameter will be ignored if enable_ilm is not set.

The application name parameter is a crucial setting that determines the name of the rollover index. It's essential to get this right to avoid confusion and ensure seamless integration.

If you're using the enable_ilm setting, the application name parameter will take effect, so make sure to specify it correctly.

Reload Connections

The reload connections feature in Elasticsearch is designed to spread the load by reloading the host list from the server every 10,000th request.

Man in White Dress Shirt Analyzing Data Displayed on Screen
Credit: pexels.com, Man in White Dress Shirt Analyzing Data Displayed on Screen

This can be beneficial for managing traffic, but it may cause issues if your Elasticsearch cluster is behind a Reverse Proxy. The Fluentd process may not have direct network access to the Elasticsearch nodes.

If you're experiencing connectivity problems, you might want to reconsider your setup to ensure direct access to the Elasticsearch nodes.

Configuration

In configuration settings, you can add a _routing key to your Elasticsearch command if a specific field exists in the input event. This is done by setting the routing_key config.

Using log routers can simplify your code by decoupling your application from log storage and processing responsibilities. This is in line with the Twelve-factor app methodology, which advises against application involvement in output stream routing or storage.

The routing_key config will add _routing to the Elasticsearch command only if the specified field is present in the input event. This helps maintain a clean and organized configuration.

A unique perspective: Elasticsearch Config

Target Type

A Man Looking at a Computer Screen with Data
Credit: pexels.com, A Man Looking at a Computer Screen with Data

Target Type is a crucial aspect of configuration in many data processing systems. It determines the type of data to be written to a record.

The target_type_key config allows you to specify the type name to write to in the record under a specific key. If the key is not found in the record, it will fallback to the type_name default, which is "fluentd".

This is particularly useful when you have multiple match configurations that need to consume data from different sources.

Curious to learn more? Check out: Elasticsearch Spring Data

Suppress TypeName

Suppressing warnings in Elasticsearch 7.x is a common issue. Elasticsearch cluster complaints about types removal warnings can be a real pain.

This can be suppressed with the `suppress_type_name` parameter. It's a simple solution to a common problem.

Elasticsearch cluster complains the following types removal warnings: This is a known issue in Elasticsearch 7.x.

For your interest: Elastic Cross Cluster Search

EFK: ES

Creating an EFK stack is a straightforward process. You'll start by creating an ElasticSearch service and pod using a YAML file, specifically elastic_search.yaml. This file will use the official ElasticSearch Docker image, version 7.4.1.

Credit: youtube.com, EFK Setup in Kubernetes Cluster | Logging in Kubernetes with Elasticsearch Fluentd and Kibana | ELK

The deployment will be created with a single pod, and a service will be created for the node. You can check the ES cluster using a curl command, which will return information about the pods and their status.

The EFK stack is a popular choice for logging and data representation, and it's used by many leading companies, including GitHub, Netflix, and Amazon. ES has a rapid-fire queryset executor that can process and transfer data quickly and efficiently.

Here are some key features of ElasticSearch:

  • ES keeps data relationally with no difficult standard DBMS rules or constraints.
  • It has simple and powerful native add-ons like Kibana and Logstash.
  • It has a RESTful API interface, which is significantly better and easier to use than basic SQL language.
  • It has multi-threaded architecture and strong analytical skills.

With ElasticSearch, you can create a Data Stream using the @type elasticsearch_data_stream feature, which was introduced in Elasticsearch 7.9. This will enable you to create a Data Stream with a matching index template and ILM policy.

Aggregator on same machine as Elasticsearch

To configure an aggregator on the same machine as Elasticsearch, start by setting up a Fluentd Aggregator. This will run on the same machine as Elasticsearch.

Credit: youtube.com, This is why you need a centralized logger on your software systems

Next, install the Elasticsearch plugin to store data into Elasticsearch, and the secure-forward plugin for secure communication with the node server. Make sure port 24284 is accessible by node servers, as secure-forward uses it by default over both TCP and UDP.

Configure Fluentd by editing /etc/td-agent/td-agent.conf. This is where you'll make the necessary changes to enable data storage in Elasticsearch.

Finally, restart Fluentd to enable the new configuration and make the changes take effect.

Selector Class Name

The Selector Class Name is a crucial configuration parameter in Fluentd. It allows you to provide your own Selector class to implement custom node selection logic.

The default selector used by the Elasticsearch::Transport class is not ideal for fallback scenarios, where Fluentd needs to switch from an exhausted ES cluster to a normal one. This is where a custom Selector class comes in handy.

You can use the plugin's built-in ElasticseatchFallbackSelector, which is a great starting point for implementing custom node selection logic. This selector class is included in out_elasticsearch by default.

However, if you're using a custom Selector class, you don't need to include it in out_elasticsearch. You just need to tell Fluentd where the selector class exists.

Validate Client Version

Close-up view of neatly arranged fiber optic cables in a patch panel for efficient data management.
Credit: pexels.com, Close-up view of neatly arranged fiber optic cables in a patch panel for efficient data management.

Validating the client version is crucial to ensure seamless interaction between your Elasticsearch server and client libraries. The default value for this validation is false.

If you're using mismatched Elasticsearch server and client libraries, fluent-plugin-elasticsearch won't be able to send data into Elasticsearch. This can cause issues.

To fix this, change the default value of thread_pool.write.queue_size in elasticsearch.yml. For example, you can update it to a higher value, such as 200.

Authentication and Security

Authentication is crucial when sending data to Elasticsearch. You can specify a user and password for HTTP Basic authentication.

To authenticate, you need to provide a user and password. This is especially useful when sending sensitive data to Elasticsearch.

You can skip SSL verification by setting ssl_verify to false. This is useful when working with self-signed certificates or other non-standard SSL configurations.

The plugin will escape required URL encoded characters within %{} placeholders. This ensures that your data is properly formatted and sent to Elasticsearch without any issues.

Data Management

Credit: youtube.com, How Fluentd simplifies collecting and consuming logs | Fluentd simply explained

Data Management is a crucial aspect of integrating Fluentd with Elasticsearch. Since Elasticsearch 7.9, Data Streams was introduced as a configuration option.

You can enable this feature by specifying @type elasticsearch_data_stream. With this configuration, Elasticsearch will automatically create a matching index template.

Data Streams also allows you to set the ILM (Index Lifecycle Management) default policy to the specified data stream unless you specify otherwise.

Deflector Alias

Deflector Alias is a useful parameter in Elasticsearch that allows you to specify an alias for the rollover index created.

This is particularly useful when using the Elasticsearch rollover API, as it helps to manage your data more efficiently.

If you've set the rollover index, then the deflector alias will be in effect, otherwise it will be ignored.

In fact, since 4.1.1, using deflector alias is prohibited with enable_ilm, so be sure to keep that in mind when setting up your data management strategy.

Time Error Tag

If you have logstash_format set to true, the elasticsearch plugin will emit an error event to @ERROR label with a specific tag when it encounters an invalid timestamp value.

This tag is called time_parse_error_tag and is used for tag routing. However, the default value of this tag is not ideal for tag routing because some plugins assume the tag is separated by dots.

We recommend setting the time_parse_error_tag to a dot-separated value like es_plugin.output.time.error.

Content Type

A rustic pile of weathered timber logs stacked outdoors, ideal for nature backgrounds and textures.
Credit: pexels.com, A rustic pile of weathered timber logs stacked outdoors, ideal for nature backgrounds and textures.

Content Type is a crucial aspect of data management, particularly when working with Elasticsearch.

The default Content-Type of Elasticsearch requests is application/json.

This is a widely used format, but it might not be the best choice for everyone.

To add application/x-ndjson as Content-Type in the payload, you can use the Elasticsearch plugin with content_type application/x-ndjson.

This can be a game-changer for certain use cases.

It's recommended to set content_type to application/x-ndjson if you won't be using a template.

This can help improve performance and make your data management more efficient.

For your interest: Elasticsearch X Pack

Ilm Policy Id

Ilm Policy Id plays a crucial role in ensuring data is properly classified and handled.

Data is classified into four main categories: public, private, sensitive, and confidential. This classification is crucial for determining the level of access and control.

Data classification is a manual process that requires human judgment and expertise. This process can be time-consuming and prone to errors.

A well-defined Ilm Policy Id can help streamline data classification and reduce errors. It provides a clear framework for classifying data and ensures consistency across the organization.

Professional woman standing confidently in a data center, surrounded by glowing servers.
Credit: pexels.com, Professional woman standing confidently in a data center, surrounded by glowing servers.

Ilm Policy Id can be used to define data classification rules and standards. This helps ensure that data is handled in accordance with its classification level.

Data classification is essential for meeting regulatory requirements and industry standards. Ilm Policy Id helps organizations demonstrate compliance with these requirements.

Ilm Policy Id can be integrated with data management systems to automate data classification. This reduces the manual effort required and improves accuracy.

A robust Ilm Policy Id is essential for ensuring data is properly protected and handled. It provides a foundation for building a solid data management framework.

Target Index

The target index is a crucial setting when it comes to data management. You can specify a target index key, which tells the plugin to find the index name in the record under that key.

This key can be a path to a nested record using dot ('.') as a separator. For example, if your input is a record with a key like "logstash-2014.12.19", the plugin will write that record to the specified index.

Brown Tree Log
Credit: pexels.com, Brown Tree Log

The plugin will use the value from the record as the index name and then remove it from the record before output. If the key is not found, it will use the logstash_format or index_name settings as configured.

This feature is particularly useful when you have a large dataset and want to partition it by certain criteria, such as tags or timestamps. By specifying the target index key, you can easily manage your data and make it more organized.

Data Template Name

Data Template Name is a crucial aspect of data management.

You can specify an existing matching index template for a data stream using the data_stream_template_name parameter.

If you don't specify a data_stream_template_name, a new matching index template will be created. The default value is the data stream name itself.

To create an index template on Fluentd startup, you can use the template_name parameter. If a template by that name already exists, it will be left unchanged unless you set template_overwrite to update it.

You'll also need to specify template_file when using template_name, as this allows the plugin to behave similarly to Logstash.

The Importance of Logging

Credit: youtube.com, What Is Log Aggregation? - Emerging Tech Insider

Logging is crucial for understanding what's happening in our applications. It provides visibility and monitoring into the behavior of a running application.

Every application will eventually crash or experience difficulties, but good logging and monitoring can make it easier to solve these problems. This is why logging is one of the most critical aspects of our applications.

A good logging infrastructure can help us identify and fix issues before they become major problems. This can lead to happier users and a better overall experience.

Logging matters because it helps us understand what's going on in our applications, even when things go wrong.

Fluent Bit and Elasticsearch

Fluent Bit and Elasticsearch are key players in data management, especially when it comes to log collection and processing.

Fluent Bit is a lightweight, high-performance log collector that's well-suited for use within Kubernetes environments. It's developed by the same company as Fluentd, another popular log collector.

Fluent Bit is designed to handle high volumes of log data with minimal memory consumption, making it a great choice for resource-constrained environments. It's also highly customizable with over 500 available plugins.

Piles of wooden logs at an outdoor timber yard under a clear blue sky.
Credit: pexels.com, Piles of wooden logs at an outdoor timber yard under a clear blue sky.

Elasticsearch, on the other hand, is a powerful search and analytics engine that's part of the ELK stack. It's developed by Elastic, a company that's also behind the popular Kibana visualization tool.

Elasticsearch is known for its relational data storage, simple and powerful native add-ons, and RESTful API interface. It's also highly scalable and has strong analytical skills, making it a popular choice for many leading companies, including GitHub, Netflix, and Amazon.

Here are some key differences between Fluent Bit and Elasticsearch:

Forwarder on Node Servers

To set up a Fluentd Forwarder on node servers, you'll need to give it read access to the web server logs. This can be done by running a specific command that grants Fluentd the necessary permissions.

Fluentd needs to listen to syslog messages, which can be achieved by adding a line to the /etc/rsyslogd.conf file. This line specifies the port that Fluentd will use to listen to syslog messages.

Detailed view of fiber optic patch cables connecting to a blue patch panel in a data center.
Credit: pexels.com, Detailed view of fiber optic patch cables connecting to a blue patch panel in a data center.

Restarting rsyslogd is necessary to apply the changes. After restarting, you can configure Fluentd to tail Apache access and error logs, as well as listen and parse syslogs.

To do this, you'll need to edit the /etc/td-agent/td-agent.conf file and add specific lines of configuration. These lines will tell Fluentd where to look for the logs and how to parse them.

Broaden your view: Elasticsearch Logs

Error Handling

Error handling is crucial when working with fluentd and Elasticsearch. You can configure the Elasticsearch plugin to emit an error event to the @ERROR label with a configured tag, such as time_parse_error_tag.

The default value for time_parse_error_tag is Fluent::ElasticsearchOutput::TimeParser.error, but it's recommended to set it to a dot-separated tag like es_plugin.output.time.error. This is because some plugins assume tags are separated by dots, not colons.

The reconnect_on_error parameter allows you to reset the connection on any error, which is recommended when using Elasticsearch Shield. By default, it will only reconnect on "host unreachable exceptions".

Max Retry Template

Credit: youtube.com, #26 Error Handling Operators - Retry - Part 2

When dealing with errors, it's essential to have a strategy in place for retrying failed operations. max_retry_putting_template can be specified to control the number of retries when putting a template.

This is particularly useful when the Elasticsearch plugin can't connect to Elasticsearch to put the template. Booting up clustered Elasticsearch containers can take significantly longer than launching the Fluentd container, making retries a necessary step.

The write_operation can be any of several options, including max_retry_putting_template. By setting this value, you can ensure that your template is successfully put, even if the initial attempt fails.

Fail on ES Version Retry Exceed

You can configure Fluentd to fail when it exceeds the maximum number of retries to get the Elasticsearch version. This is controlled by the fail_on_detecting_es_version_retry_exceed parameter.

Setting this parameter to true allows you to use a fallback mechanism for obtaining Elasticsearch version, preventing Fluentd from failing on startup.

Retry Tag

Retry Tag is a valuable feature that allows you to custom route messages in response to bulk request failures.

Various tangled wires connected to system near black metal cases in server room
Credit: pexels.com, Various tangled wires connected to system near black metal cases in server room

The default behavior is to emit failed records using the same tag that was provided. This can sometimes lead to unexpected behavior in your pipeline.

You can change this behavior by setting the retry_tag to a value other than nil. This will emit failed messages with the specified tag.

For example, if you set retry_tag to "my-label", failed messages will be emitted with the tag "my-label".

Note that retry_tag is optional, and you can also use labels to reroute retries by adding a label to your fluent elasticsearch plugin configuration.

Unrecoverable Error Types

Unrecoverable Error Types are a crucial aspect of error handling. The default unrecoverable_error_types parameter is set up strictly.

Elasticsearch's thread pool capacity is a common cause of es_rejected_execution_exception, which is an unrecoverable error type. This error occurs when the thread pool is exceeded.

Advanced users can increase the thread pool capacity, but for normal users, it's best to follow the default behavior. If you want to increase the thread pool capacity and forcibly retry bulk requests, you'll need to change the unrecoverable_error_types parameter.

To do this, remove es_rejected_execution_exception from the unrecoverable_error_types parameter. This will allow you to retry bulk requests even when the thread pool is exceeded.

Related reading: Elasticsearch Bulk Api

Usage and Examples

Credit: youtube.com, FLUENTD POWER! Transform Container Logs to ELASTIC SEARCH and KIBANA in a Flash!

In your Fluentd configuration, use the @type elasticsearch directive. Additional configuration is optional, but default values are available.

You can customize the type_name parameter, but be aware that it will be used as a fixed _doc value for Elasticsearch 7. On the other hand, it will make no effect for Elasticsearch 8.

The data_stream_template_use_index_patterns_wildcard parameter determines how index patterns are created. If set to true (default), resulting index patterns will be ["foo*"]. If set to false, the resulting index patterns will be ["foo"].

Usage Examples

Data stream templates can be configured to use index patterns with wildcard characters. This is done by setting data_stream_template_use_index_patterns_wildcard to true, resulting in index patterns like ["foo*"].

Setting this parameter to false, on the other hand, will result in more specific index patterns like ["foo"].

Full Stack Example

In the Full Stack Example, we'll connect Fluentd, ES, and Kibana to create an exact namespace with a few services and pods. This will also involve testing the namespace on a simple Python flask project.

Close-up of a network server rack with blinking LEDs, showcasing Ethernet connections and patch panels.
Credit: pexels.com, Close-up of a network server rack with blinking LEDs, showcasing Ethernet connections and patch panels.

We'll start by making a Docker container with Python 3.7 and all the required side modules. This container will serve as a source for our pods later on.

To implement this example successfully, you'll need to have the following tools installed on your PC: kubectl: the Kubernetes CLI interfaceMinikube: a local k8s cluster that emulates all workloads of the real enterprise clustersDocker: a tool for containerizationPython: the programming language, along with virtualenv for making independent virtual environments.

Intriguing read: Python Api Elasticsearch

EFK

EFK is a popular logging solution for Kubernetes clusters.

To set up Fluentd, a crucial component of EFK, you need to create two files: fluent-rbac.yaml and fluentd.yaml.

The fluent-rbac.yaml file grants clusterRole bindings and creates a ServiceAccount.

In the fluentd.yaml file, you create a DaemonSet tool and configure hostPath to ensure Fluentd can write logs to the file system.

Once you've created both files, apply them using kubectl create -f fluentd-rbac.yaml and kubectl create -f fluentd.yaml.

Credit: youtube.com, AKS Application Logging with ElasticSearch FluentD and Kibana (EFK)

You can verify that Fluentd is running by checking the pods in the kube-system namespace.

If Fluentd is running correctly, you should see a pod with a name like fluentd-npcwf in the Running state.

To check if Fluentd is connected to Elasticsearch, use the command kubectl logs fluentd-npcwf -n kube-system.

If the output starts with "Connection opened to Elasticsearch cluster", you know that Fluentd is connected successfully.

Frequently Asked Questions

Is Fluentd still used?

Yes, Fluentd is still widely used by over 5,000 data-driven companies, including one of the largest users that collects logs from 50,000+ servers. As a Cloud Native Computing Foundation (CNCF) member project, Fluentd continues to be a trusted solution for log management and data collection.

What are the disadvantages of Fluentd?

Fluentd's performance can be a challenge due to its Ruby-based plugin framework, which can slow down processing. It can handle around 18,000 events per second on standard hardware.

Tiffany Kozey

Junior Writer

Tiffany Kozey is a versatile writer with a passion for exploring the intersection of technology and everyday life. With a keen eye for detail and a knack for simplifying complex concepts, she has established herself as a go-to expert on topics like Microsoft Cloud Syncing. Her articles have been widely read and appreciated for their clarity, insight, and practical advice.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.