Logstash config advise

Hi Team,

I'm new to ELK and have deployed the ELK stack (Elasticsearch, Logstash, and Kibana) in Kubernetes and exposed Logstash via a Traefik ingress route to allow external servers to send logs. However, I am encountering an issue with configuring Filebeat to send logs to Logstash, as it is not working and I don’t see any errors in the containers. I would appreciate any advice regarding common pitfalls in configuring Logstash in a Kubernetes environment, ensuring that Filebeat can communicate with Logstash effectively through the Traefik ingress, and troubleshooting methods to identify why logs are not being sent or received.

My primary goal is to collect logs from external servers reliably using this setup, so any recommendations from the experts would be greatly appreciated!

this is the config , used to deploy the logstash

logstashConfig:
  logstash.yml: |
    http.host: "0.0.0.0"
    xpack.monitoring.enabled: false
    pipeline.ordered: "auto"
    path.data: "/usr/share/logstash/data"
    path.logs: "/usr/share/logstash/logs"
    queue.type: "memory"

logstashPipeline:
  logstash.conf: |
    input {
      beats {
        port => 5044
        codec => "json"
        ssl => true
        ssl_certificate => "/usr/share/logstash/config/certs/tls.crt"
        ssl_key => "/usr/share/logstash/config/certs/tls.key"
      }
    }

    filter {
      json {
        source => "message"
        target => "parsed_json"
      }
    }

    output {
      elasticsearch {
        hosts => ["https://elastic.default.svc.cluster.local:9200"]
        user => "elastic"
        password => "passwod"
        index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
        ssl => true
        ssl_certificate_verification => false
        manage_template => false
      }
    }

What is your Filebeat configuration?

I do not use Kubernetes, but is this exposed as a TCP service or HTTP/HTTPS? The beats input uses TCP, not HTTP or HTTPS, if your ingress is working for HTTP/HTTPS then it will not work for Logstash.

Not sure if this is the correct documentation, but it says:

Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster.

And a little further on the page:

An Ingress does not expose arbitrary ports or protocols. Exposing services other than HTTP and HTTPS to the internet typically uses a service of type Service.Type=NodePort or Service.Type=LoadBalancer.

Hi @leandrojmp
Thanks for the your response.

current filebeat configuration is as follow

output.logstash: The Logstash hosts hosts: ["https://logstash.example.local:443"] ssl.enabled: true ssl.certificate_authorities: ["/logstash/crts/logstash.crt"]

I believe that since Logstash only supports TCP ports, I need to expose Logstash as a LoadBalancer service type.

The beats input works on TCP, not on http, so you need to expose it in a way that it will work with TCP connections.

This is wrong, as mentioned the beats input does not use http, so it needs to be just logstash.example.local:port.

When I configured Filebeat using the recommended method, I encountered the following error. Could you please advise me on this?

output.logstash:
  The Logstash hosts
  hosts: ["https//192.168.56.141:5044"]
  ssl.enabled: true
  ssl.certificate_authorities: ["/logstash/crts/logstash.crt"]
  protocol: "https"

st pipelines or are using Logstash pipelines, you can ignore this warning.","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"error","@timestamp":"2024-10-09T12:55:54.942+0100","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/cmd/instance.handleError","file.name":"instance/beat.go","file.line":1360},"message":"Exiting: index management requested but the Elasticsearch output is not configured/enabled","service.name":"filebeat","ecs.version":"1.6.0"}
Exiting: index management requested but the Elasticsearch output is not configured/enabled

Logstash does not use http, it needs to be just 192.168.56.141:5044, check the previous answer.

You need to disable the settings related to managing templates because it needs to talk with Elasticsearch and will not work with the Logstash output, please share your entire filebeat.yml to see what settings are enabled.

here is my config file.

###################### Filebeat Configuration Example #########################

# This file is an example configuration file highlighting only the most common
# options. The filebeat.reference.yml file from the same directory contains all the
# supported options with more comments. You can use it as a reference.
#
# You can find the full configuration reference here:
# https://www.elastic.co/guide/en/beats/filebeat/index.html

# For more available modules and options, please see the filebeat.reference.yml sample
# configuration file.

# ============================== Filebeat inputs ===============================

filebeat.inputs:

# Each - is an input. Most options can be set at the input level, so
# you can use different inputs for various configurations.
# Below are the input-specific configurations.

# filestream is an input for collecting log messages from files.
- type: filestream

  # Unique ID among all inputs, an ID is required.
  id: my-filestream-id

  # Change to true to enable this input configuration.
  enabled: false

  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - /var/log/*.log
    #- c:\programdata\elasticsearch\logs\*

  # Exclude lines. A list of regular expressions to match. It drops the lines that are
  # matching any regular expression from the list.
  # Line filtering happens after the parsers pipeline. If you would like to filter lines
  # before parsers, use include_message parser.
  #exclude_lines: ['^DBG']

  # Include lines. A list of regular expressions to match. It exports the lines that are
  # matching any regular expression from the list.
  # Line filtering happens after the parsers pipeline. If you would like to filter lines
  # before parsers, use include_message parser.
  #include_lines: ['^ERR', '^WARN']

  # Exclude files. A list of regular expressions to match. Filebeat drops the files that
  # are matching any regular expression from the list. By default, no files are dropped.
  #prospector.scanner.exclude_files: ['.gz$']

  # Optional additional fields. These fields can be freely picked
  # to add additional information to the crawled log files for filtering
  #fields:
  #  level: debug
  #  review: 1

# ============================== Filebeat modules ==============================

filebeat.config.modules:
  # Glob pattern for configuration loading
  path: ${path.config}/modules.d/*.yml

  # Set to true to enable config reloading
  reload.enabled: false

  # Period on which files under path should be checked for changes
  #reload.period: 10s

# ======================= Elasticsearch template setting =======================

setup.template.settings:
  index.number_of_shards: 1
  #index.codec: best_compression
  #_source.enabled: false


# ================================== General ===================================

# The name of the shipper that publishes the network data. It can be used to group
# all the transactions sent by a single shipper in the web interface.
#name:

# The tags of the shipper are included in their field with each
# transaction published.
#tags: ["service-X", "web-tier"]

# Optional fields that you can specify to add additional information to the
# output.
#fields:
#  env: staging

# ================================= Dashboards =================================
# These settings control loading the sample dashboards to the Kibana index. Loading
# the dashboards is disabled by default and can be enabled either by setting the
# options here or by using the `setup` command.
#setup.dashboards.enabled: false

# The URL from where to download the dashboard archive. By default, this URL
# has a value that is computed based on the Beat name and version. For released
# versions, this URL points to the dashboard archive on the artifacts.elastic.co
# website.
#setup.dashboards.url:

# =================================== Kibana ===================================

# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
# This requires a Kibana endpoint configuration.
setup.kibana:
  host: "https://mydashboard-kibana:443"
  username: "$USERNAME"
  password: "$PASSWORD"

  # Kibana Host
  # Scheme and port can be left out and will be set to the default (http and 5601)
  # In case you specify and additional path, the scheme is required: http://localhost:5601/path
  # IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
  #host: "localhost:5601"

  # Kibana Space ID
  # ID of the Kibana Space into which the dashboards should be loaded. By default,
  # the Default Space will be used.
  #space.id:

# =============================== Elastic Cloud ================================

# These settings simplify using Filebeat with the Elastic Cloud (https://cloud.elastic.co/).

# The cloud.id setting overwrites the `output.elasticsearch.hosts` and
# `setup.kibana.host` options.
# You can find the `cloud.id` in the Elastic Cloud web UI.
#cloud.id:

# The cloud.auth setting overwrites the `output.elasticsearch.username` and
# `output.elasticsearch.password` settings. The format is `<user>:<pass>`.
#cloud.auth:

# ================================== Outputs ===================================

# Configure what output to use when sending the data collected by the beat.

# ---------------------------- Elasticsearch Output ----------------------------
output.elasticsearch:
  # Array of hosts to connect to.
 
  # Performance preset - one of "balanced", "throughput", "scale",
  # "latency", or "custom".
  preset: balanced

  # Protocol - either `http` (default) or `https`.
  #protocol: "https"

  # Authentication credentials - either API key or username/password.
  #api_key: "id:api_key"
  #username: "elastic"
  #password: "changeme"

# ------------------------------ Logstash Output -------------------------------
output.logstash:
  #The Logstash hosts
  hosts: [192.168.56.141:5044]
  ssl.enabled: true
  ssl.certificate_authorities: ["/logstash/crts/logstash.crt"]
  #protocol: "https"
  # Optional SSL. By default is off.
  # List of root certificates for HTTPS server verifications
  #ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]

  # Certificate for SSL client authentication
  #ssl.certificate: "/etc/pki/client/cert.pem"

  # Client Certificate Key
  #ssl.key: "/etc/pki/client/cert.key"

# ================================= Processors =================================
processors:
  - add_host_metadata:
      when.not.contains.tags: forwarded
  - add_cloud_metadata: ~
  - add_docker_metadata: ~
  - add_kubernetes_metadata: ~

# ================================== Logging ===================================

# Sets log level. The default log level is info.
# Available log levels are: error, warning, info, debug
#logging.level: debug

# At debug level, you can selectively enable logging only for some components.
# To enable all selectors, use ["*"]. Examples of other selectors are "beat",
# "publisher", "service".
#logging.selectors: ["*"]

# ============================= X-Pack Monitoring ==============================
# Filebeat can export internal metrics to a central Elasticsearch monitoring
# cluster.  This requires xpack monitoring to be enabled in Elasticsearch.  The
# reporting is disabled by default.

# Set to true to enable the monitoring reporter.
#monitoring.enabled: false

# Sets the UUID of the Elasticsearch cluster under which monitoring data for this
# Filebeat instance will appear in the Stack Monitoring UI. If output.elasticsearch
# is enabled, the UUID is derived from the Elasticsearch cluster referenced by output.elasticsearch.
#monitoring.cluster_uuid:

# Uncomment to send the metrics to Elasticsearch. Most settings from the
# Elasticsearch outputs are accepted here as well.
# Note that the settings should point to your Elasticsearch *monitoring* cluster.
# Any setting that is not set is automatically inherited from the Elasticsearch
# output configuration, so if you have the Elasticsearch output configured such
# that it is pointing to your Elasticsearch monitoring cluster, you can simply
# uncomment the following line.
#monitoring.elasticsearch:

# ============================== Instrumentation ===============================

# Instrumentation support for the filebeat.
#instrumentation:
    # Set to true to enable instrumentation of filebeat.
    #enabled: false

    # Environment in which filebeat is running on (eg: staging, production, etc.)
    #environment: ""

    # APM Server hosts to report instrumentation results to.
    #hosts:
    #  - http://localhost:8200

    # API Key for the APM Server(s).
    # If api_key is set then secret_token will be ignored.
    #api_key:

    # Secret token for the APM Server(s).
    #secret_token:


# ================================= Migration ==================================

# This allows to enable 6.7 migration aliases
#migration.6_to_7.enabled: true

If I'm not wrong you need to comment theses lines:

setup.template.settings:
  index.number_of_shards: 1

Also, comment everything related to output.elasticsearch.

I commented out everything related to Elasticsearch, but now I am encountering an error. When I searched for a solution online, it suggested enabling the Elasticsearch config block, but I want to send my logs to Logstash

{"log.level":"error","@timestamp":"2024-10-09T14:53:19.627+0100","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/cmd/instance.handleError","file.name":"instance/beat.go","file.line":1360},"message":"Exiting: index management requested but the Elasticsearch output is not configured/enabled","service.name":"filebeat","ecs.version":"1.6.0"}
Exiting: index management requested but the Elasticsearch output is not configured/enabled

Do I need to enable both outputs, or can I use just one output option?

You cannot have 2 outputs, just one.

Did you comment the lines mentioned in the previous answer?

Yes, I commented out everything mentioned in above comment.

Exiting: index management requested but the Elasticsearch output is not configured/enabled

Something is weird, are you sure that you are using the correct filebeat.yml file?

Can you make a backup of your file and use this one? It is the your configuration without the commented lines, I also removed the Kibana configuration.

filebeat.inputs:
- type: filestream
  id: my-filestream-id
  enabled: false
  paths:
    - /var/log/*.log

filebeat.config.modules:
  path: ${path.config}/modules.d/*.yml
  reload.enabled: false

output.logstash:
  hosts: [192.168.56.141:5044]
  ssl.enabled: true
  ssl.certificate_authorities: ["/logstash/crts/logstash.crt"]

processors:
  - add_host_metadata:
      when.not.contains.tags: forwarded
  - add_cloud_metadata: ~
  - add_docker_metadata: ~
  - add_kubernetes_metadata: ~

Still getting same error, I added this block to my filebeat.yml file.

filebeat.inputs:

  • type: filestream
    id: my-filestream-id
    enabled: false
    paths:
    • /var/log/*.log

filebeat.config.modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false

output.logstash:
hosts: [192.168.56.141:5044]
ssl.enabled: true
ssl.certificate_authorities: ["/logstash/crts/logstash.crt"]

processors:

  • add_host_metadata:
    when.not.contains.tags: forwarded
  • add_cloud_metadata: ~
  • add_docker_metadata: ~
  • add_kubernetes_metadata: ~

Filebeat is working fine with the Elasticsearch output, and I can see the logs in the Kibana dashboard. However, when I set up Logstash as the output, I encounter the error mentioned above.

There is nothing in this configuration that would make Filebeat try to talk with Elasticsearch.

Can you share how you are running Filebeat? Is it as a service? As a command line?

Please share the entire log for some hints.

Sure thing,

filebeat verison
filebeat version 8.15.2 (amd64), libbeat 8.15.2 [26daf71e4ec87172523af7f0e916cba9f79dc0d0 built 2024-09-19 09:20:43 +0000 UTC]

Yes, its a service systemd service unit.

{"log.level":"info","@timestamp":"2024-10-09T15:43:57.684+0100","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/cmd/instance.(*Beat).configure","file.name":"instance/beat.go","file.line":828},"message":"Home path: [/usr/share/filebeat] Config path: [/etc/filebeat] Data path: [/var/lib/filebeat] Logs path: [/var/log/filebeat]","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2024-10-09T15:43:57.684+0100","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/cmd/instance.(*Beat).configure","file.name":"instance/beat.go","file.line":836},"message":"Beat ID: 878c4b5b-c20f-4dfa-9600-fc304f67ca60","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2024-10-09T15:43:57.690+0100","log.logger":"beat","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/cmd/instance.logSystemInfo","file.name":"instance/beat.go","file.line":1385},"message":"Beat info","service.name":"filebeat","system_info":{"beat":{"path":{"config":"/etc/filebeat","data":"/var/lib/filebeat","home":"/usr/share/filebeat","logs":"/var/log/filebeat"},"type":"filebeat","uuid":"878c4b5b-c20f-4dfa-9600-fc304f67ca60"},"ecs.version":"1.6.0"}}
{"log.level":"info","@timestamp":"2024-10-09T15:43:57.691+0100","log.logger":"beat","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/cmd/instance.logSystemInfo","file.name":"instance/beat.go","file.line":1394},"message":"Build info","service.name":"filebeat","system_info":{"build":{"commit":"26daf71e4ec87172523af7f0e916cba9f79dc0d0","libbeat":"8.15.2","time":"2024-09-19T09:20:43.000Z","version":"8.15.2"},"ecs.version":"1.6.0"}}
{"log.level":"info","@timestamp":"2024-10-09T15:43:57.691+0100","log.logger":"beat","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/cmd/instance.logSystemInfo","file.name":"instance/beat.go","file.line":1397},"message":"Go runtime info","service.name":"filebeat","system_info":{"go":{"os":"linux","arch":"amd64","max_procs":4,"version":"go1.22.6"},"ecs.version":"1.6.0"}}
{"log.level":"info","@timestamp":"2024-10-09T15:43:57.691+0100","log.logger":"beat","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/cmd/instance.logSystemInfo","file.name":"instance/beat.go","file.line":1403},"message":"Host info","service.name":"filebeat","system_info":{"host":{"architecture":"x86_64","native_architecture":"","boot_time":"2024-09-05T13:34:26+01:00","containerized":false,"name":"server1.example.com","ip":["127.0.0.1","192.168.58.11"],"kernel_version":"5.14.0-427.31.1.el9_4.x86_64","mac":["52:54:00:5e:7f:7c"],"os":{"type":"linux","family":"redhat","platform":"almalinux","name":"AlmaLinux","version":"9.4 (Seafoam Ocelot)","major":9,"minor":4,"patch":0,"codename":"Seafoam Ocelot"},"timezone":"BST","timezone_offset_sec":3600,"id":"376069e451964ec08505bc8e0163162a"},"ecs.version":"1.6.0"}}
{"log.level":"info","@timestamp":"2024-10-09T15:43:57.692+0100","log.logger":"beat","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/cmd/instance.logSystemInfo","file.name":"instance/beat.go","file.line":1432},"message":"Process info","service.name":"filebeat","system_info":{"process":{"capabilities":{"inheritable":null,"permitted":["chown","dac_override","dac_read_search","fowner","fsetid","kill","setgid","setuid","setpcap","linux_immutable","net_bind_service","net_broadcast","net_admin","net_raw","ipc_lock","ipc_owner","sys_module","sys_rawio","sys_chroot","sys_ptrace","sys_pacct","sys_admin","sys_boot","sys_nice","sys_resource","sys_time","sys_tty_config","mknod","lease","audit_write","audit_control","setfcap","mac_override","mac_admin","syslog","wake_alarm","block_suspend","audit_read","perfmon","bpf","checkpoint_restore"],"effective":["chown","dac_override","dac_read_search","fowner","fsetid","kill","setgid","setuid","setpcap","linux_immutable","net_bind_service","net_broadcast","net_admin","net_raw","ipc_lock","ipc_owner","sys_module","sys_rawio","sys_chroot","sys_ptrace","sys_pacct","sys_admin","sys_boot","sys_nice","sys_resource","sys_time","sys_tty_config","mknod","lease","audit_write","audit_control","setfcap","mac_override","mac_admin","syslog","wake_alarm","block_suspend","audit_read","perfmon","bpf","checkpoint_restore"],"bounding":["chown","dac_override","dac_read_search","fowner","fsetid","kill","setgid","setuid","setpcap","linux_immutable","net_bind_service","net_broadcast","net_admin","net_raw","ipc_lock","ipc_owner","sys_module","sys_rawio","sys_chroot","sys_ptrace","sys_pacct","sys_admin","sys_boot","sys_nice","sys_resource","sys_time","sys_tty_config","mknod","lease","audit_write","audit_control","setfcap","mac_override","mac_admin","syslog","wake_alarm","block_suspend","audit_read","perfmon","bpf","checkpoint_restore"],"ambient":null},"cwd":"/root","exe":"/usr/share/filebeat/bin/filebeat","name":"filebeat","pid":3084616,"ppid":3083192,"seccomp":{"mode":"disabled","no_new_privs":false},"start_time":"2024-10-09T15:43:56.990+0100"},"ecs.version":"1.6.0"}}
{"log.level":"info","@timestamp":"2024-10-09T15:43:57.692+0100","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/cmd/instance.(*Beat).createBeater","file.name":"instance/beat.go","file.line":341},"message":"Setup Beat: filebeat; Version: 8.15.2","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2024-10-09T15:43:57.695+0100","log.logger":"publisher","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/publisher/pipeline.LoadWithSettings","file.name":"pipeline/module.go","file.line":105},"message":"Beat name: server1.example.com","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2024-10-09T15:43:57.695+0100","log.logger":"modules","log.origin":{"function":"github.com/elastic/beats/v7/filebeat/fileset.newModuleRegistry","file.name":"fileset/modules.go","file.line":136},"message":"Enabled modules/filesets: ","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"warn","@timestamp":"2024-10-09T15:43:57.696+0100","log.origin":{"function":"github.com/elastic/beats/v7/filebeat/beater.(*Filebeat).setupPipelineLoaderCallback","file.name":"beater/filebeat.go","file.line":193},"message":"Filebeat is unable to load the ingest pipelines for the configured modules because the Elasticsearch output is not configured/enabled. If you have already loaded the ingest pipelines or are using Logstash pipelines, you can ignore this warning.","service.name":"filebeat","ecs.version":"1.6.0"}
{"log.level":"error","@timestamp":"2024-10-09T15:43:57.696+0100","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/cmd/instance.handleError","file.name":"instance/beat.go","file.line":1360},"message":"Exiting: index management requested but the Elasticsearch output is not configured/enabled","service.name":"filebeat","ecs.version":"1.6.0"}
Exiting: index management requested but the Elasticsearch output is not configured/enabled

The filebeat.yml that you shared is the /etc/filebeat/filebeat.yml? Can you double check it and share the current content of this file?

Your error does not make sense if it is using the correct file.

This is the file I'm currently using, and I also checked that the module is enabled. At the moment, only the system module is enabled.

 cat /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: filestream
  id: my-filestream-id
  enabled: false
  paths:
    - /var/log/*.log

filebeat.config.modules:
  path: ${path.config}/modules.d/*.yml
  reload.enabled: false

output.logstash:
  hosts: [192.168.56.141:5044]
  ssl.enabled: true
  ssl.certificate_authorities: ["/logstash/crts/logstash.crt"]


processors:
  - add_host_metadata:
      when.not.contains.tags: forwarded
  - add_cloud_metadata: ~
  - add_docker_metadata: ~
  - add_kubernetes_metadata: ~

ls -ltrh /etc/filebeat/
total 1.2M
-rw-r--r-- 1 root root 1.2M Sep 19 10:20 fields.yml
drwxr-xr-x 2 root root 4.0K Oct 7 06:42 modules.d
-rw------- 1 root root 8.9K Oct 9 15:37 filebeat.yml-org
-rw------- 1 root root 490 Oct 9 15:39 filebeat.yml

I have uninstalled Filebeat and reinstalled it fresh, but I am still getting the same error. :confused:

Is there any dependency on my Logstash pipeline configuration?

Yeah, no idea why are you getting this error.

Are you for some reason trying to run filebeat setup or just starting the systemd service?

There is nothing in your configuration that would try to talk with elasticsearch, not sure if anything changed in the last versions as I'm not using Filebeat anymore.

Can you try to add this line to the file and restart the systemd service?

setup.template.enabled: false

I just started the Filebeat service using systemctl and then ran the Filebeat setup command