EFK的安装和收集docker容器日志展示
在用户根目录创建个filebeat.docker.yml文件,文件内容如下
filebeat.config: modules: path: ${path.config}/modules.d/*.yml reload.enabled: false filebeat.autodiscover: providers: - type: docker templates: - condition: contains: docker.container.labels.collectLog: "true" config: - type: container paths: - /var/lib/docker/containers/${data.docker.container.id}/*.log processors: - add_cloud_metadata: ~ output.elasticsearch: hosts: ‘${ELASTICSEARCH_HOSTS:elasticsearch:9200}‘ username: ‘${ELASTICSEARCH_USERNAME:}‘ password: ‘${ELASTICSEARCH_PASSWORD:}‘
其中templates的condition里表示的是收集labels里有collectLog: "true"的容器的日志
通过docker-compose安装es filebeat kibana。(PS:这个单节点的efk,集群高可用的话一般还需要搭配队列,redis或者kafka。而且es一般也是集群,filebeat是每个节点一个,那样的话就得用k8s才方便了)
version: "3" services: elasticsearch: image: docker.elastic.co/elasticsearch/elasticsearch:7.7.1 container_name: es environment: - discovery.type=single-node ports: - 9200:9200 - 9300:9300 kibana: image: docker.elastic.co/kibana/kibana:7.7.1 container_name: kibana ports: - 5601:5601 filebeat: image: docker.elastic.co/beats/filebeat:7.7.1 container_name: filebeat environment: - output.elasticsearch.hosts=["elasticsearch:9200"] user: root volumes: - "~/filebeat.docker.yml:/usr/share/filebeat/filebeat.yml:ro" - "/var/lib/docker/containers:/var/lib/docker/containers:ro" - "/var/run/docker.sock:/var/run/docker.sock:ro"
然后启动一个容器,labels里有collectLog: "true"就行.
这里我以一个asp.net core服务为例,docker-compose.yml如下,镜像和服务名改为你自己的即可。
version: "3" services: xx_api: container_name: xx_api image: registry.cn-beijing.aliyuncs.com/xx/xx3api:latest labels: collectLog: "true" ports: - 9005:80
最后在kibana显示日志。
打开kibana的站点,点击Management
然后点击Kibana的Index Patterns, 再点创建索引样式
输入filebeat*,点击下一步
然后选个模式,我选的是timestamp的。这样就创建索引了。
回到主页,点击logs
就可以看到日志成功显示出来了。
相关推荐
王道革 2020-11-25
bwyyziq 2020-11-22
pigsmall 2020-11-19
changecan 2020-11-19
helloWorldAndYou 2020-11-16
nginxs 2020-11-14
红石丶 2020-11-13
WanKaShing 2020-11-12
yangkang 2020-11-12
滴水穿石点石成金 2020-11-12
张荣珍 2020-11-12
wuxunanjing 2020-11-11
魅惑青花瓷 2020-11-11
lihongtai 2020-11-09
yangkang 2020-11-09
worldsnow 2020-11-06
MichaelJScofield 2020-11-06
TaoTaoFu 2020-11-06