Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
Update all container files for ELK
Browse files Browse the repository at this point in the history
  • Loading branch information
cduhn17 committed Aug 8, 2023
1 parent 36272ce commit d3dd5dc
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 43 deletions.
114 changes: 81 additions & 33 deletions elk-docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Need to increase vm.max_map_count

Check warning on line 1 in elk-docker/docker-compose.yml

View workflow job for this annotation

GitHub Actions / lint

1:2 [comments] missing starting space in comment

#echo vm.max_map_count=262144 >> /etc/sysctl.conf
#echo vm.max_map_count=262144 >> /etc/sysctl.conf

Check warning on line 3 in elk-docker/docker-compose.yml

View workflow job for this annotation

GitHub Actions / lint

3:2 [comments] missing starting space in comment
#sudo sysctl -p

Check warning on line 4 in elk-docker/docker-compose.yml

View workflow job for this annotation

GitHub Actions / lint

4:2 [comments] missing starting space in comment

version: "3.5"

Check warning on line 6 in elk-docker/docker-compose.yml

View workflow job for this annotation

GitHub Actions / lint

6:1 [document-start] missing document start "---"
Expand All @@ -10,7 +10,7 @@ services:
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
container_name: setup # Set the container name to "setup"

Check warning on line 11 in elk-docker/docker-compose.yml

View workflow job for this annotation

GitHub Actions / lint

11:27 [comments] too few spaces before comment
volumes:
- certs:/usr/share/elasticsearch/config/certs # Map the "certs" volume to the Elasticsearch certs directory
- ./certs:/usr/share/elasticsearch/config/certs # Map the "certs" volume to the Elasticsearch certs directory

Check warning on line 13 in elk-docker/docker-compose.yml

View workflow job for this annotation

GitHub Actions / lint

13:55 [comments] too few spaces before comment

Check failure on line 13 in elk-docker/docker-compose.yml

View workflow job for this annotation

GitHub Actions / lint

13:89 [line-length] line too long (115 > 88 characters)
user: "0" # Run the container as root (user ID 0)

Check warning on line 14 in elk-docker/docker-compose.yml

View workflow job for this annotation

GitHub Actions / lint

14:15 [comments] too few spaces before comment
command: > # Define a multi-line command to run in the container
bash -c '
Expand Down Expand Up @@ -49,7 +49,7 @@ services:
echo "Setting ${KIBANA_USERNAME} password";
until curl -s -X POST --cacert config/certs/ca/ca.crt -u elastic:${ELASTIC_PASSWORD} -H "Content-Type: application/json" https://es01:9200/_security/user/${KIBANA_USERNAME}/_password -d "{\"password\":\"${KIBANA_PASSWORD}\"}" | grep -q "^{}"; do sleep 10; done;

Check failure on line 50 in elk-docker/docker-compose.yml

View workflow job for this annotation

GitHub Actions / lint

50:89 [line-length] line too long (269 > 88 characters)
echo "All done!";
'
'
healthcheck:
# Healthcheck configuration for the setup service
test: [ "CMD-SHELL", "[ -f config/certs/es01/es01.crt ]" ]

Check failure on line 55 in elk-docker/docker-compose.yml

View workflow job for this annotation

GitHub Actions / lint

55:14 [brackets] too many spaces inside brackets

Check failure on line 55 in elk-docker/docker-compose.yml

View workflow job for this annotation

GitHub Actions / lint

55:63 [brackets] too many spaces inside brackets
Expand All @@ -66,9 +66,49 @@ services:
condition: service_healthy # Start only when the setup service is healthy (certificates and user passwords are created)

Check failure on line 66 in elk-docker/docker-compose.yml

View workflow job for this annotation

GitHub Actions / lint

66:89 [line-length] line too long (127 > 88 characters)
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION} # Elasticsearch image to use

Check failure on line 67 in elk-docker/docker-compose.yml

View workflow job for this annotation

GitHub Actions / lint

67:89 [line-length] line too long (102 > 88 characters)
container_name: es01 # Name for the container
# build:
# context: .
# dockerfile: Dockerfile
volumes:
- certs:/usr/share/elasticsearch/config/certs # Mount the certificates directory
- esdata01:/usr/share/elasticsearch/data # Mount the data directory for Elasticsearch
- ./certs:/usr/share/elasticsearch/config/certs # Mount the certificates directory
- ./esdata01:/usr/share/elasticsearch/data # Mount the data directory for Elasticsearch

Check failure on line 74 in elk-docker/docker-compose.yml

View workflow job for this annotation

GitHub Actions / lint

74:89 [line-length] line too long (93 > 88 characters)
# user: "0"
# command: >
# bash -c '
# 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;
# fi;
# if [ ! -f /usr/share/elasticsearch/config/certs/ca.zip ]; then
# echo "Creating CA";
# bin/elasticsearch-certutil ca --silent --pem -out /usr/share/elasticsearch/config/certs/ca.zip;
# unzip /usr/share/elasticsearch/config/certs/ca.zip -d /usr/share/elasticsearch/config/certs;
# fi;
# if [ ! -f /usr/share/elasticsearch/config/certs/certs.zip ]; then
# echo "Creating certs";
# echo -ne \
# "instances:\n"\
# " - name: es01\n"\
# " ip:\n"\
# " - 10.0.2.109\n"\
#
# > /usr/share/elasticsearch/config/certs/instances.yml;
# bin/elasticsearch-certutil cert --silent --pem -out /usr/share/elasticsearch/config/certs/certs.zip --in /usr/share/elasticsearch/config/certs/instances.yml --ca-cert /usr/share/elasticsearch/config/certs/ca/ca.crt --ca-key /usr/share/elasticsearch/config/certs/ca/ca.key;
# unzip /usr/share/elasticsearch/config/certs/certs.zip -d /usr/share/elasticsearch/config/certs;
# fi;
# echo "Setting file permissions"
# chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/config/certs;
# find /usr/share/elasticsearch/config/certs -type d -exec chmod 750 \{\} \;;
# find /usr/share/elasticsearch/config/certs -type f -exec chmod 640 \{\} \;;
# echo "Waiting for Elasticsearch availability";
# # until curl -s --cacert /usr/share/elasticsearch/config/certs/ca/ca.crt https://es01:9200 | grep -q "missing authentication credentials"; do sleep 30; done;
# echo "Setting kibana_system password";
# # until curl -s -X POST --cacert /usr/share/elasticsearch/config/certs/ca/ca.crt -u "elastic:${ELASTIC_PASSWORD}" -H "Content-Type: application/json" https://es01:9200/_security/user/kibana_system/_password -d "{\"password\":\"${KIBANA_PASSWORD}\"}" | grep -q "^{}"; do sleep 10; done;
# echo "All done!";
# '
ports:
- ${ES_PORT}:${ES_PORT} # Expose Elasticsearch's HTTP API
environment:
Expand All @@ -81,15 +121,16 @@ services:
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD} # Set the password for the "elastic" user
- bootstrap.memory_lock=true # Lock the process address space into RAM to prevent swapping
- xpack.security.enabled=true # Enable X-Pack security features
- xpack.security.authc.api_key.enabled=true
- xpack.security.http.ssl.enabled=true # Enable SSL for the HTTP API
- xpack.security.http.ssl.key=certs/es01/es01.key # Set the SSL key file
- xpack.security.http.ssl.certificate=certs/es01/es01.crt # Set the SSL certificate file
- xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt # Set the SSL certificate authority
- xpack.security.http.ssl.key=/usr/share/elasticsearch/config/certs/es01/es01.key # Set the SSL key file
- xpack.security.http.ssl.certificate=/usr/share/elasticsearch/config/certs/es01/es01.crt # Set the SSL certificate file
- xpack.security.http.ssl.certificate_authorities=/usr/share/elasticsearch/config/certs/ca/ca.crt # Set the SSL certificate authority
- xpack.security.http.ssl.verification_mode=certificate # Set the SSL verification mode
- xpack.security.transport.ssl.enabled=true # Enable SSL for the transport layer
- xpack.security.transport.ssl.key=certs/es01/es01.key # Set the transport SSL key file
- xpack.security.transport.ssl.certificate=certs/es01/es01.crt # Set the transport SSL certificate file
- xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt # Set the transport SSL certificate authority
- xpack.security.transport.ssl.key=/usr/share/elasticsearch/config/certs/es01/es01.key # Set the transport SSL key file
- xpack.security.transport.ssl.certificate=/usr/share/elasticsearch/config/certs/es01/es01.crt # Set the transport SSL certificate file
- xpack.security.transport.ssl.certificate_authorities=/usr/share/elasticsearch/config/certs/ca/ca.crt # Set the transport SSL certificate authority
- xpack.security.transport.ssl.verification_mode=certificate # Set the transport SSL verification mode
- xpack.license.self_generated.type=${LICENSE} # Set the type of self-generated license
mem_limit: ${MEM_LIMIT} # Set the memory limit for the container
Expand Down Expand Up @@ -120,12 +161,15 @@ services:
image: docker.elastic.co/kibana/kibana:${STACK_VERSION} # Kibana image to use
container_name: kibana # Name for the container
volumes:
- certs:/usr/share/kibana/config/certs # Mount the certificates directory
- kibanadata:/usr/share/kibana/data # Mount the data directory for Kibana
- ./certs:/usr/share/kibana/config/certs # Mount the certificates directory
- ./kibanadata:/usr/share/kibana/data # Mount the data directory for Kibana
ports:
- ${KIBANA_PORT}:${KIBANA_PORT} # Expose Kibana's HTTP API
environment:
# Environment variables for configuring Kibana
- xpack.encryptedSavedObjects.encryptionKey=XPACK_SECURITY_ENCRYPTIONKEY
- elasticsearch.username=${KIBANA_USERNAME}
- elasticsearch.password=${KIBANA_PASSWORD}
- SERVERNAME=kibana # Set the server name
- ELASTICSEARCH_HOSTS=https://es01:9200 # Set the Elasticsearch hosts
- ELASTICSEARCH_USERNAME=${KIBANA_USERNAME} # Set the Elasticsearch username
Expand All @@ -137,14 +181,14 @@ services:
- XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY=${CRYPTO_PASSWORD} # Set the encryption key for encrypted saved objects
- ES_ENFORCE_BOOTSTRAP_CHECKS=false # Disable enforcement of bootstrap checks
- XPACK_REPORTING_ENCRYPTIONKEY=${CRYPTO_PASSWORD} # Set the encryption key for reporting
- XPACK_FLEET_AGENTS_ELASTICSEARCH_HOSTS:'["https://es01:9200"]'
- XPACK_FLEET_AGENTS_ELASTICSEARCH_HOSTS:"['https://es01:9200']"
mem_limit: ${MEM_LIMIT} # Set the memory limit for the container
healthcheck:
# Healthcheck for the Kibana servi
test:
[
"CMD-SHELL",
"curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found'"
"curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 200 OK'"
]
interval: 10s # Interval between healthcheck attempts
timeout: 10s # Timeout for each healthcheck attempt
Expand All @@ -166,30 +210,32 @@ services:
- ./logstash.conf:/usr/share/logstash/config/logstash.conf # Mount the Logstash configuration file
- ./logs:/usr/share/logstash/logs # Mount the logs directory for Logstash
- ./logstash.yml:/usr/share/logstash/config/logstash.yml # Mount the Logstash YAML configuration file
- certs:/usr/share/logstash/config/certs # Mount the certificates directory
- ./certs:/usr/share/logstash/config/certs # Mount the certificates directory
environment:
- "LS_JAVA_OPTS=-Xmx512m -Xms512m" # Set the Java options for Logstash (memory settings)
ports:
- ${LOGSTASH_PORT}:${LOGSTASH_PORT} # Expose Logstash's listening port
mem_limit: ${MEM_LIMIT} # Set the memory limit for the container
networks:
- elk
#metricbeat:
##Curretnly not working on EC2 and may not need to be used in favor of Fleet Agent##
# Metricbeat service
#image: docker.elastic.co/beats/metricbeat:${STACK_VERSION} # Metricbeat image to use
#container_name: metricbeat # Name for the container
#volumes:
#- ./metricbeat.yml:/usr/share/metricbeat/metricbeat.yml # Mount the Metricbeat configuration file
#- /var/run/docker.sock:/var/run/docker.sock # Mount the Docker socket for container metrics
#- certs:/usr/share/metricbeat/config/certs
#depends_on:

metricbeat:
# Metricbeat service
image: docker.elastic.co/beats/metricbeat:${STACK_VERSION} # Metricbeat image to use
container_name: metricbeat # Name for the container
volumes:
- ./metricbeat.yml:/usr/share/metricbeat/metricbeat.yml # Mount the Metricbeat configuration file
- ./var/run/docker.sock:/var/run/docker.sock # Mount the Docker socket for container metrics
- ./certs:/usr/share/metricbeat/config/certs
depends_on:
# Define dependencies for the service
#- logstash
#- es01
#command: metricbeat -e -strict.perms=false # Start Metricbeat with error logging and disabled strict permission checks
#networks:
#- elk
- logstash
- es01
command: metricbeat -e -strict.perms=false # Start Metricbeat with error logging and disabled strict permission checks
env_file:
- .env
networks:
- elk

filebeat:
# Filebeat Service
Expand All @@ -202,9 +248,11 @@ services:
user: root
volumes:
- ./filebeats.yml:/usr/share/filebeat/filebeat.yml # Mount the Filebeats configuration file
- certs:/usr/share/filebeat/config/certs # Mount the certificates directory
- ./certs:/usr/share/filebeat/config/certs # Mount the certificates directory
- /var/log:/var/log
command: filebeat -e -strict.perms=false # Start Filebeats with error logging and disabled strict permission checks
command: /bin/sh -c "echo $$ELASTIC_USERNAME && echo $$ELASTIC_PASSWORD && filebeat -e -strict.perms=false" # Start Filebeats with error logging and disabled strict permission checks
env_file:
- .env
networks:
- elk

Expand Down
4 changes: 4 additions & 0 deletions elk-docker/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ echo "ELASTIC_PASSWORD=${ELASTIC_PASSWORD}" >> .env
KIBANA_PASSWORD=$(aws ssm get-parameter --name /ELK-Test/KIBANA_PASSWORD --with-decryption --query 'Parameter.Value' --output text)
echo "KIBANA_PASSWORD=${KIBANA_PASSWORD}" >> .env

# Get the Kibana IP address parameter, decrypt it, and append it to the .env file.
KIBANA_IP=$(aws ssm get-parameter --name /ELK-Test/KIBANA_IP --with-decryption --query 'Parameter.Value' --output text)
echo "KIBANA_IP=${KIBANA_IP}" >> .env

# Get the Cluster Name parameter, decrypt it, and append it to the .env file.
CLUSTER_NAME=$(aws ssm get-parameter --name /ELK-Test/CLUSTER_NAME --with-decryption --query 'Parameter.Value' --output text)
echo "CLUSTER_NAME=${CLUSTER_NAME}" >> .env
Expand Down
12 changes: 6 additions & 6 deletions elk-docker/logstash.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ input {
# ssl_extra_chain_certs => ["/path/to/another-ca-file.ca"] # Uncomment this line if you need to provide an additional CA file for the certificate chain.
}
}

# Filter section: This is where you process and enrich the input data.
filter {
# Use the grok filter plugin to parse the log message using the COMBINEDAPACHELOG pattern.
Expand All @@ -34,7 +34,7 @@ filter {
mutate {
add_field => { "client_ip" => "172.16.6.129" }
}

# Use the geoip filter plugin to add geolocation information to the event based on the client_ip field.
geoip {
source => "[client_ip]"
Expand All @@ -46,12 +46,12 @@ output {
elasticsearch {
hosts => "http://es01:9200/" # Elasticsearch host URL.
index => "logs-%{+YYYY.MM.dd}" # Index pattern for storing the data in Elasticsearch.
user => "${ELASTIC_USERNAME}" # or the appropriate user if it's different
password => "${ELASTIC_PASSWORD}" # replace with your actual password
ssl => true
user => "${ELASTIC_USERNAME}" # or the appropriate user if it's different
password => "${ELASTIC_PASSWORD}" # replace with your actual password
ssl => true
cacert => "/usr/share/logstash/config/certs/es01/es01.crt" # replace with the path to your CA certificate file }
}

# Output the processed data to the console using the rubydebug codec.
stdout {
codec => rubydebug
Expand Down
11 changes: 7 additions & 4 deletions elk-docker/metricbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ metricbeat.modules:

# Configure the output destination for the collected metrics.
output.elasticsearch:
hosts: "es01:9200"
protocol: "https"
hosts: ["https://es01:9200"] # Specify the hosts of your Elasticsearch instance.
username: "${ELASTIC_USERNAME}" # The username used to connect to Elasticsearch.
password: "${ELASTIC_PASSWORD}" # The password used to connect to Elasticsearch.
ssl.verification_mode: "true" # To skip verification. Use with caution.
ssl.verification_mode: "full" # To skip verification. Use with caution.
# Or, provide the path to the CA certificate.
ssl.certificate_authorities: ["/usr/share/metricbeat/config/certs/CA.pem"]
ssl.certificate_authorities: [ "/usr/share/metricbeat/config/certs/ca/ca.crt" ]
ssl.certificate: "/usr/share/metricbeat/config/certs/ca/ca.crt"
ssl.key: "/usr/share/metricbeat/config/certs/ca/ca.key"

# Configure the Kibana settings for index pattern setup and dashboard loading.
setup.kibana:
host: "kibana:5601"


0 comments on commit d3dd5dc

Please sign in to comment.