version: '3'
services:
elasticsearch:
image: elasticsearch:latest
container_name: elasticsearch
restart: always
networks:
- elk
ports:
- '9200:9200'
- '9300:9300'
volumes:
- /mnt/elk/elasticsearch/data:/usr/share/elasticsearch/data
kibana:
image: kibana:latest
container_name: kibana
restart: always
networks:
- elk
ports:
- "5601:5601"
depends_on:
- elasticsearch
networks:
elk:
docker run --name test-springboot -p 1001:80 -f /mnt/logs:/mnt/logs -t test-springboot
logstash:
image: logstash:latest
container_name: logstash
restart: always
ports:
- "9601:9601"
volumes:
- /mnt/elk/logstash/config-dir:/config-dir
- /mnt/logs:/mnt/logs
command: logstash -f /config-dir
input{
file{
path => "/mnt/logs/*.log"
type => "web_log"
start_position => "beginning"
}
}
output{
elasticsearch{
hosts => ["192.168.1.18:9200"]
index => "log-%{+YYYY.MM.dd}"
}
}
input:爲輸入的方式,這裏使用file;web
output :是輸出的方式,這裏輸出到192.168.1.18的es中;spring
path:指向讀取日誌文件的位置,*表示讀取目錄下全部後綴名爲log的日誌文件;docker
type:自定義該文件的類型,在es中爲type字段;springboot
start_position:爲從log文件中讀取文件的位置,beginning爲從頭開始讀取,只在第一次啓動有效,後面只讀取最後一行;elasticsearch