$ tree efk-demo-composeefk-demo-compose├── docker-compose.yml├── elasticsearch_conf│ └── elasticsearch.yml├── filebeat_conf│ ├── create_pipeline.sh│ ├── filebeat.yml│ └── pipeline.json├── kibana_conf│ └── kibana.yml└── nginx_conf └── start.sh
4 directories, 8 filesdocker-compose.yml:
version"3"
services elasticsearch container_nameelasticsearch imageelasticsearch8.6.1 restarton-failure environmentES_JAVA_OPTS=-Xms1024m -Xmx1024m volumeselasticsearch_data:/usr/share/elasticsearch/data./elasticsearch_conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml./elasticsearch_conf/elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12 ports"9200:9200/tcp" networks efk_demo
kibana container_namekibana imagekibana8.6.1 restarton-failure volumes./kibana_conf/kibana.yml:/usr/share/kibana/config/kibana.yml depends_onelasticsearch ports"5601:5601/tcp" networks efk_demo
filebeat container_namefilebeat imagedocker.elastic.co/beats/filebeat8.6.1 restarton-failure volumes./filebeat_conf/filebeat.yml:/usr/share/filebeat/filebeat.ymlnginx_logs:/opt/logs depends_onelasticsearch networks efk_demo
nginx container_namenginx imagenginx1.23.3 restarton-failure volumesnginx_logs:/var/log/nginx./nginx_conf/start.sh:/start.sh ports"10000:80/tcp" networks efk_demo command/start.sh
networks efk_demo driverbridge
volumes nginx_logs driverlocal elasticsearch_data driverlocalelasticsearch_conf/elasticsearch.yml:
cluster.name"docker-cluster"network.host"0.0.0.0"cluster.routing.allocation.disk.threshold_enabledtruecluster.routing.allocation.disk.watermark.low"5120mb"cluster.routing.allocation.disk.watermark.high"2560mb"cluster.routing.allocation.disk.watermark.flood_stage"1280mb"discovery.type"single-node"
xpack.security.enabledtruexpack.security.transport.ssl.enabledtruexpack.security.transport.ssl.keystore.typePKCS12xpack.security.transport.ssl.verification_modecertificatexpack.security.transport.ssl.keystore.pathelastic-certificates.p12xpack.security.transport.ssl.truststore.pathelastic-certificates.p12xpack.security.transport.ssl.truststore.typePKCS12xpack.security.transport.ssl.keystore.password123456xpack.security.transport.ssl.truststore.password123456xpack.security.audit.enabledtruefilebeat_conf/create_pipeline.sh:
curl \ -X PUT \ -H "Content-Type: application/json" \ -d @pipeline.json \ -u elastic:123456 \ "http://127.0.0.1:9200/_ingest/pipeline/access-log-pipeline?pretty"filebeat_conf/filebeat.yml:
filebeat.inputstypefilestream idfilestream-1 enabledtrue paths/opt/logs/access.log fields service_name"efk_demo" fields_under_roottrue close_removedfalse close_renamedfalseprocessorsdrop_fields fields"prospector" "event" "dataset" "ecs" "agent" "input"queue.mem events8192 flush.timeout0output.elasticsearch hosts"http://elasticsearch:9200" username"elastic" password"123456" pipeline"access-log-pipeline"filebeat_conf/pipeline.json:
{ "description": "access log pipeline", "processors": [ { "grok": { "field": "message", "patterns": [ "%{DATA:remote_addr} - %{DATA:remote_user} \\[%{HTTPDATE:time_local}\\] \"%{WORD:request_method} %{DATA:request_uri} %{DATA:scheme}\" %{NUMBER:status:int} %{NUMBER:body_bytes_sent:int} \"%{DATA:http_referer}\" \"%{DATA:http_user_agent}\" \"%{DATA:http_x_forwarded_for}\"" ] } } ]}kibana_conf/kibana.yml:
server.name"kibana"server.host"0.0.0.0"server.shutdownTimeout"5s"elasticsearch.hosts"http://elasticsearch:9200"elasticsearch.username"kibana"elasticsearch.password"123456"xpack.monitoring.ui.container.elasticsearch.enabledtruei18n.locale"zh-CN"nginx_conf/start.sh:
logfile=/var/log/nginx/access.log
if [ -L "$logfile" ] ; then rm -f "$logfile"fi
exec /usr/sbin/nginx -g "daemon off;"xxxxxxxxxx# 启动 ES 容器$ docker run -itd --name es elasticsearch:8.6.1
$ docker exec -it es ./bin/elasticsearch-certutil ca# 第一次提示输入时,按回车# 第二次提示输入时,输入 123456
$ docker exec -it es ./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12# 第一次提示输入时,输入 123456# 第二次提示输入时,按回车# 第三次提示输入时,输入 123456
# 先 cd 到 efk-demo-compose/ 目录$ docker cp es:/usr/share/elasticsearch/elastic-certificates.p12 elasticsearch_conf/
# 关闭、删除容器$ docker kill es$ docker rm esxxxxxxxxxx$ docker compose up -dxxxxxxxxxx$ docker exec -it elasticsearch ./bin/elasticsearch-setup-passwords interactive# 第一次提示输入时,输入 y# 接下来都输入 123456xxxxxxxxxx# 先 cd 到 efk-demo-compose/filebeat_conf/ 目录$ sh create_pipeline.sh{ "acknowledged" : true}x
# 启动$ docker compose up -d
# 重启$ docker compose restart
# 关闭$ docker compose down