I try to setup elasticstack in docker with Elasticsearch, Kibana and fleet-server as components. All components use the version 8.12.1
docker-compose.yml:
services:
setup:
image: elasticsearch:${STACK_VERSION}
volumes:
- certs:/usr/share/elasticsearch/config/certs
- ./entrypoint:/usr/share/elasticsearch/config/entrypoint:ro
user: "0"
entrypoint: /usr/share/elasticsearch/config/entrypoint/entrypoint.sh
healthcheck:
test: ["CMD-SHELL", "[ -f config/certs/elasticsearch/elasticsearch.crt ]"]
interval: 1s
timeout: 5s
retries: 120
elasticsearch:
depends_on:
setup:
condition: service_healthy
image: elasticsearch:${STACK_VERSION}
container_name: elasticsearch
volumes:
- esdata:/usr/share/elasticsearch/data
- certs:/usr/share/elasticsearch/config/certs
ports:
- ${ES_PORT}:9200
environment:
- discovery.type=single-node
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
- bootstrap.memory_lock=true
- xpack.security.enabled=true
- xpack.security.authc.api_key.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.http.ssl.key=certs/elasticsearch/elasticsearch.key
- xpack.security.http.ssl.certificate=certs/elasticsearch/elasticsearch.crt
- xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.http.ssl.verification_mode=certificate
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.key=certs/elasticsearch/elasticsearch.key
- xpack.security.transport.ssl.certificate=certs/elasticsearch/elasticsearch.crt
- xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.license.self_generated.type=${LICENSE}
mem_limit: ${MEM_LIMIT}
ulimits:
memlock:
soft: -1
hard: -1
healthcheck:
test:
[
"CMD-SHELL",
"curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
]
interval: 10s
timeout: 10s
retries: 120
kibana:
depends_on:
elasticsearch:
condition: service_healthy
image: kibana:${STACK_VERSION}
container_name: kibana
volumes:
- certs:/usr/share/kibana/config/certs
- kibanadata:/usr/share/kibana/data
- ./kibana.yml:/usr/share/kibana/config/kibana.yml:Z
ports:
- ${KIBANA_PORT}:5601
environment:
- SERVER_NAME=kibana
- ELASTICSEARCH_HOSTS=https://elasticsearch:9200
- ELASTICSEARCH_USERNAME=kibana_system
- ELASTICSEARCH_PASSWORD=${KIBANA_PASSWORD}
- ELASTICSEARCH_SSL_CERTIFICATEAUTHORITIES=config/certs/ca/ca.crt
- SERVER_SSL_ENABLED=true
- SERVER_SSL_CERTIFICATE=config/certs/kibana/kibana.crt
- SERVER_SSL_KEY=config/certs/kibana/kibana.key
- SERVER_SSL_CERTIFICATEAUTHORITIES=config/certs/ca/ca.crt
mem_limit: ${MEM_LIMIT}
healthcheck:
test:
[
"CMD-SHELL",
"curl -s --cacert config/certs/ca/ca.crt -I https://localhost:5601 | grep -q 'HTTP/1.1 302 Found'",
]
interval: 10s
timeout: 10s
retries: 120
fleet-server:
depends_on:
kibana:
condition: service_healthy
elasticsearch:
condition: service_healthy
image: docker.elastic.co/beats/elastic-agent:${STACK_VERSION}
container_name: ecp-fleet-server
volumes:
- certs:/certs:z
ports:
- ${FLEET_PORT}:8220
restart: always
user: root
environment:
- FLEET_ENROLL=1
- FLEET_SERVER_POLICY_ID=fleet-server-policy
- FLEET_SERVER_ENABLE=1
- KIBANA_FLEET_SETUP=1
- KIBANA_HOST=https://kibana:5601
- FLEET_URL=https://fleet-server:8220
- FLEET_SERVER_ELASTICSEARCH_HOST=https://elasticsearch:9200
- FLEET_CA=/certs/ca/ca.crt
- KIBANA_FLEET_USERNAME=elastic
- KIBANA_FLEET_PASSWORD=${ELASTIC_PASSWORD}
- FLEET_SERVER_CERT=/certs/fleet-server/fleet-server.crt
- FLEET_SERVER_CERT_KEY=/certs/fleet-server/fleet-server.key
- FLEET_SERVER_ELASTICSEARCH_CA=/certs/ca/ca.crt
- KIBANA_FLEET_CA=/certs/ca/ca.crt
- ssl.certificate_authorities=/certs/ca/ca.crt
volumes:
certs:
driver: local
esdata:
driver: local
kibanadata:
driver: local
it uses an entrypoint to create the certificates and setup the passwords
entrypoint.sh
#!/bin/bash
set -o allexport
source /usr/share/elasticsearch/config/entrypoint/.env
set +o allexport
if [ x${ELASTIC_PASSWORD} == x ]; then
echo "Set the ELASTIC_PASSWORD environment variable in the .env file";
exit 1;
elif [ x${KIBANA_PASSWORD} == x ]; then
echo "Set the KIBANA_PASSWORD environment variable in the .env file";
exit 1;
elif [ x${LOGSTASH_PASSWORD} == x ]; then
echo "Set the LOGSTASH_PASSWORD environment variable in the .env file";
exit 1;
fi;
if [ ! -f config/certs/ca.zip ]; then
echo "Creating CA";
bin/elasticsearch-certutil ca --silent --pem -out config/certs/ca.zip;
unzip config/certs/ca.zip -d config/certs;
fi;
if [ ! -f config/certs/certs.zip ]; then
echo "Creating certs";
echo -ne \
"instances:\n"\
" - name: elasticsearch\n"\
" dns:\n"\
" - elasticsearch\n"\
" - localhost\n"\
" ip:\n"\
" - ***\n"\
" - name: kibana\n"\
" dns:\n"\
" - kibana\n"\
" - localhost\n"\
" ip:\n"\
" - ***\n"\
" - name: fleet-server\n"\
" dns:\n"\
" - fleet-server\n"\
" - localhost\n"\
" ip:\n"\
" - ***\n"\
> config/certs/instances.yml;
bin/elasticsearch-certutil cert --silent --pem -out config/certs/certs.zip --in config/certs/instances.yml --ca-cert config/certs/ca/ca.crt --ca-key config/certs/ca/ca.key;
unzip config/certs/certs.zip -d config/certs;
fi;
echo "Setting file permissions"
chown -R root:root config/certs;
find . -type d -exec chmod 750 \{\} \;;
find . -type f -exec chmod 640 \{\} \;;
echo "Waiting for Elasticsearch availability";
until curl -s --cacert config/certs/ca/ca.crt https://elasticsearch:9200 | grep -q "missing authentication credentials"; do sleep 30; done;
echo "Setting kibana_system password";
until curl -s -X POST --cacert config/certs/ca/ca.crt -u elastic:${ELASTIC_PASSWORD} -H "Content-Type: application/json" https://elasticsearch:9200/_security/user/kibana_system/_password -d "{\"password\":\"${KIBANA_PASSWORD}\"}" | grep -q "^{}"; do sleep 10; done;
but when I try to install the elastic agent on another server, it shows up but is stuck on the "Confirm incoming data" point.
sudo ./elastic-agent install --url=https://***:8220 \
--enrollment-token=*** \
--fleet-server-es-ca=/home/vema/elastic-agent-8.12.1-linux-x86_64/cert/es.crt \
--certificate-authorities=/home/vema/elastic-agent-8.12.1-linux-x86_64/cert/ca.crt \
--fleet-server-cert=/home/vema/elastic-agent-8.12.1-linux-x86_64/cert/fleet.crt \
--fleet-server-cert-key=/home/vema/elastic-agent-8.12.1-linux-x86_64/cert/fleet.key
But in the overview it is Healthy