Filebeat can't connect to Elastic search

Downloaded a filebeat to my host (which is a domain controller ), trying to use filebeat to ship identity logs from DC to ELK (logstash and Elasticsearch).

having the following error everytime i run ./filebeat setup - e.

error initializing publisher: cannot set both api_key and username/password accessing 'output.elasticsearch' (source:'filebeat.yml')

can someone please help me with this?

Hi @ddiabe,

I'm not a pro in this, but I encountered a similar error when installing ELK.

It seems that you are trying to access elastic with both password and api. Try using only one (a password or an api key).

And if you can show us the config you have, it would be much simpler to see where's the issue.

t###################### 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: true

  # 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:

  # 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.
  hosts: ["ls1:9200"]

  # 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: ["ls1:5044"]

  # 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://ls1: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

ype or paste code here
 Errors: [error connecting to Elasticsearch at http://ls1:9200: Get \"http://ls1:9200\": EOF]","service.name":"filebeat","ecs.version":"1.6.0"}
Exiting: couldn't connect to any of the configured Elasticsearch hosts. Errors: [error connecting to Elasticsearch at http://ls1:9200: Get "http://ls1:9200": EOF]

try the two following...

filebeat test config
filebeat test output

This will also try to connect to kibana... which does not look configured.
filebeat setup -e

How did you install elasticsearch... is it running if so how do you know?

Hi @stephenb when i run the commands u mentioned, i get the following output

typeelasticsearch: http://ls1:9200...
  parse url... OK
  connection...
    parse host... OK
    dns lookup... OK
    addresses: 10.1.0.5
    dial up... OK
  TLS... WARN secure connection disabled
  talk to server... ERROR Get "http://ls1:9200": EOF or paste code here

@stephenb my ES is running on a docker container.. i used the curl -XGET ls1:9200 command.

@stephenb am getting a (52) empty reply from server

I don't see that username/pass has been set.
You can test with curl:
curl -u elastic:<pass> http://ls1:9200

Where did you run the curl command from?

In the container on the host?

Where is filebeat running? In a container or on the host?

How did you start Elasticsearch on Docker?

Please be very specific with what you are running and where you are running it.

@stephenb ran the curl from my cmd in the DC which is my host and its is a windows Vm in azure. While my Elk is running in a docker container.

@stephenb filebeat is running in my ho

So show all the commands and the outputs and where they are ; otherwise, we can't help.

How did you start elasticsearch in Docker?

What version are you on?

Most likely, you have host vs docker connectivity...

You providing clear details is what lets us help....

@stephenb that is fair. So to answer your questions,

  1. How did you start docker? So my architecture is set up such that, docker is housed in an Azure ubuntu Vm . In the VM, is a container , that contains my ELK stack (Logstash, ES and Kibana). So when ever i start my vm, my container starts as well without me running any docker command to run it.

  2. What version are you running ? My docker version is 26.1.0 and my ES version is 8.11.1

  3. Show all commands? used the curl ls1:9200 command on my host to check status of my ES.

C:\Users\admin.ackbar>curl ls1:9200
curl: (52) Empty reply from server

@stephenb please let me know if there is any other information u need to help rectify this issue. thanks.

try

curl -k -u elastic https://ls1:9200

Share your docker compose

curl: (52) Empty reply from server

Need you to show the command + the result every time....everytime...

What is ls1 did you try localhost

Did you try curl from the same server docker is running on

Share your docker compose or startup commands

Also check:

  • network.host: <ip or 0.0.0.0> in elasticsearch.yml
  • firewall rules, port 9200 should be opened to the FB host
CONTAINER ID   IMAGE                                                  COMMAND                  CREATED         STATUS                     PORTS                NAMES
6918b24b74bb   docker.elastic.co/logstash/logstash:8.11.1             "/usr/local/bin/dock…"   3 minutes ago   Up 3 minutes (healthy)     5044/tcp, 9600/tcp   lme_logstash.1.yl6xejl4u1bduihmimrwpixiz
5d31f9af39b7   docker.elastic.co/kibana/kibana:8.11.1                 "/bin/tini -- /bin/b…"   3 minutes ago   Up 3 minutes (healthy)     5601/tcp             lme_kibana.1.q7ot6y0i261ccrqw82xtkmihi
2b907d92139f   docker.elastic.co/elasticsearch/elasticsearch:8.11.1   "/bin/tini -- /usr/l…"   3 minutes ago   Up 3 minutes (healthy)     9200/tcp, 9300/tcp   lme_elasticsearch.1.v6w6ytregj5ttdhr4xx7vkgil
653f7b0458fa   docker.elastic.co/logstash/logstash:8.11.1             "/usr/local/bin/dock…"   3 hours ago     Exited (0) 7 minutes ago                        lme_logstash.1.kdy1ml8qf0zml1keh4agjeeje