Hi, I am facing an issue with lntegration of logstash 8.15.2 with elasticsearch8.15.2.
Logstash is failing to connect to Elasticsearch. The logs show the following errors:
EDITED By MOD. Please Format your Code in the future using 3 ```
before and after your code
[2024-10-17T13:24:43,507][WARN ][logstash.outputs.elasticsearch][main] Attempted to resurrect connection to dead ES instance, but got an error {:url=>"http://elasticsearch:9200/", :exception=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::HostUnreachableError, :message=>"Elasticsearch Unreachable: [http://elasticsearch:9200/][Manticore::SocketException] Connect to elasticsearch:9200 [elasticsearch/172.20.0.2] failed: Connection refused"}
[2024-10-17T13:24:48,561][WARN ][logstash.outputs.elasticsearch][main] Health check failed {:code=>401, :url=>http://elasticsearch:9200/, :message=>"Got response code '401' contacting Elasticsearch at URL 'http://elasticsearch:9200/'"}
Even though the correct username and password were set in the logstash.yml file, these values are being replaced by placeholders upon restarting the container:
xpack.monitoring.elasticsearch.password: ${xpack.monitoring.elasticsearch.password}
xpack.monitoring.elasticsearch.username: ${xpack.monitoring.elasticsearch.username}
My docker-compose file is below:
version: '3'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.15.2
container_name: elasticsearch
hostname: elasticsearch
environment:
- xpack.security.enabled=true
- discovery.type=single-node
- ES_JAVA_OPTS=-Xms1g -Xmx1g
- ELASTIC_PASSWORD=qwerty
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
volumes:
- elastic_data:/usr/share/elasticsearch/data/
ports:
- 9200:9200
networks:
- elk-network
logstash:
image: docker.elastic.co/logstash/logstash:8.15.2
container_name: logstash
hostname: logstash
environment:
- xpack.monitoring.elasticsearch.username=elastic
- xpack.monitoring.elasticsearch.password=qwerty
volumes:
- ./logstash/logstash.conf:/usr/share/logstash/pipeline/logstash.conf
- ./logstash/logstash.yml:/usr/share/logstash/config/logstash.yml
command: logstash -f /usr/share/logstash/pipeline/logstash.conf
depends_on:
- elasticsearch
ports:
- '9600:9600'
- '4560:4560'
environment:
- LS_JAVA_OPTS=-Xms1g -Xmx1g
- xpack.monitoring.elasticsearch.username=elastic
- xpack.monitoring.elasticsearch.password=qwerty
networks:
- elk-network
kibana:
container_name: kibana
image: docker.elastic.co/kibana/kibana:8.15.2
environment:
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200
- ELASTICSEARCH_USERNAME=kibana_system # Username for Kibana to connect to Elasticsearch
- ELASTICSEARCH_PASSWORD=qwerty
ports:
- 5601:5601
depends_on:
- elasticsearch
networks:
- elk-network
volumes:
elastic_data: {}
networks:
elk-network:
my logstash.conf file is below
input {
tcp {
port => 4560
codec => json
}
}
filter {
date {
match => [ "timeMillis", "UNIX_MS" ]
}
json {
source => "message"
target => "response"
}
}
output {
elasticsearch {
hosts => [ "http://elasticsearch:9200" ]
index => "%{[application_id]}-%{[environment]}-%{+YYYY.MM.dd}"
user => "elastic"
password => "qwerty"
}
}
my logstash.yml is below:
http.host: 0.0.0.0
xpack.monitoring.elasticsearch.hosts:- http://elasticsearch:9200
xpack.monitoring.elasticsearch.password:qwerty
xpack.monitoring.elasticsearch.username:elastic
Could someone assist with this? It would be greatly appreciated.