Fateme Ghasemi
Fateme Ghasemi

Reputation: 285

BadResponseCodeError, :error=>"Got response code '401' contacting Elasticsearch at URL

I use logstash by logstash:7.9.1 image and i get this error when I up docker-compose and I dont know what to do with this (I try to make my logstash config wrong and connect it to the wrong elastic port but my docker still connect to 9200 and so I think it dosent read its data from my logstash config) pls help meeeee!!!! my error:

[logstash.licensechecker.licensereader] Attempted to resurrect connection to dead ES instance, but got an error. {:url=>"http://elasticsearch:9200/", :error_type=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError, :error=>"Got response code '401' contacting Elasticsearch at URL 'http://elasticsearch:9200/'"}

my docker-compose:

  zookeeper:
    image: wurstmeister/zookeeper:3.4.6
    container_name: zookeeper
    ports:
      - 2181:2181
    networks:
      - bardz


  kafka:

    image: wurstmeister/kafka:2.11-1.1.0
    container_name: kafka
    depends_on:
      - zookeeper
    environment:
      KAFKA_ADVERTISED_HOST_NAME: kafka
      KAFKA_CREATE_TOPICS: logs-topic:1:1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181

    ports:
      - 9092:9092
    volumes:
      - kofka-volume:/var/run/docker.sock
    networks:
      - bardz

  elasticsearch:
    build:
      context: elk/elasticsearch/
      args:
        ELK_VERSION: "7.9.1"
    volumes:
      - type: bind
        source: ./elk/elasticsearch/config/elasticsearch.yml
        target: /usr/share/elasticsearch/config/elasticsearch.yml
        read_only: true
      - type: volume
        source: elasticsearch
        target: /usr/share/elasticsearch/data
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      ES_JAVA_OPTS: "-Xmx256m -Xms256m"
      ELASTIC_PASSWORD: changeme
      # Use single node discovery in order to disable production mode and avoid bootstrap checks
      # see https://www.elastic.co/guide/en/elasticsearch/reference/current/bootstrap-checks.html
      discovery.type: single-node
    networks:
      - bardz


  logstash:
    image: logstash:7.9.1
    restart: on-failure
    ports:
      - "5000:5000/tcp"
      - "5000:5000/udp"
      - "9600:9600"
    volumes:
      - logstash_data:/bitnami
      - ./elk/logstash/logstash-kafka.conf:/opt/bitnami/logstash/config/logstash-kafka.conf
    environment:
      LOGSTASH_CONF_FILENAME: logstash-kafka.conf
    networks:
      - bardz
    depends_on:
      - elasticsearch


networks:
  bardz:
    external: true
    driver: bridge


volumes:
  elasticsearch:
  zipkin-volume:
  kofka-volume:
  logstash_data:


my logstash config:

input {
    kafka {
        bootstrap_servers => "kafka:9092"
        topics => ["logs-topic"]
    }
}

output {
    elasticsearch {
        hosts => ["elasticsearch:9200"]
        user => elastic
        password => changeme
        index => "logs-topic"
        workers => 1
    }
}

Upvotes: 1

Views: 11274

Answers (1)

user11935734
user11935734

Reputation:

You are using the wrong password of elastic user in 7.9 which is changed from changeme to password as shown in ES contribution doc, but I tried and this seems to work only when you are running ES from source code.

Anyway you are getting 401 means unauth access and you can read more about it here,

As you are not running ES code from source, would advise you to follow the steps mentioned in this thread to change the password and as you are running it in docker, you need to go inside the docker conatainer by docker exec -it <cont-id> /bin/bash and than run the command mentioned in thread to set your own password.

Upvotes: 0

Related Questions