当前位置:   article > 正文

用docker-compose安装efk和使用_dockercompose搭建efk

dockercompose搭建efk

系统版本为ubuntu 24.04

相关组件,filebeat:8.10.2 ,kibana:8.10.2 ,elasticsearch:8.10.2 

先运行docker network create 命令创建网络,我创建的名字是logging

docker network create logging

docker-compose文件

  1. root@monitor:/home/monitor/efk# cat docker-compose.yml
  2. version: '3'
  3. services:
  4. elasticsearch:
  5. image: docker.elastic.co/elasticsearch/elasticsearch:8.10.2
  6. container_name: elasticsearch
  7. networks:
  8. - logging
  9. volumes:
  10. - elasticsearch-data:/usr/share/elasticsearch/data
  11. environment:
  12. - discovery.type=single-node
  13. - xpack.security.enabled=false
  14. - ES_JAVA_OPTS=-Xms512m -Xmx1g
  15. ports:
  16. - "9200:9200"
  17. kibana:
  18. image: docker.elastic.co/kibana/kibana:8.10.2
  19. container_name: kibana
  20. networks:
  21. - logging
  22. environment:
  23. - ELASTICSEARCH_HOSTS=http://elasticsearch:9200
  24. - I18N_LOCALE=zh-CN
  25. ports:
  26. - "5601:5601"
  27. filebeat:
  28. image: docker.elastic.co/beats/filebeat:8.10.2
  29. container_name: filebeat
  30. networks:
  31. - logging
  32. volumes:
  33. - /etc/filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml
  34. - /var/log:/var/log
  35. user: root
  36. command: filebeat -e -strict.perms=false
  37. depends_on:
  38. - elasticsearch
  39. networks:
  40. logging:
  41. volumes:
  42. elasticsearch-data:
  43. driver: local

然后根据绑定的数据卷,进到filebeat的yml文件目录下

  1. root@monitor:/home/monitor/efk# cd /etc/filebeat/
  2. root@monitor:/etc/filebeat# ls
  3. filebeat.yml

可以看到filebeta.yml文件已经自动创建了,手动修改它,先将里面的内容清空,添加如下内容

  1. root@monitor:/etc/filebeat# cat filebeat.yml
  2. filebeat.inputs:
  3. - type: log
  4. enabled: true
  5. paths:
  6. - /var/log/nginx/access.log
  7. - /var/log/nginx/error.log
  8. fields:
  9. project: ms
  10. app: nginx
  11. - type: log
  12. enabled: true
  13. paths:
  14. - /var/log/messages
  15. fields:
  16. project: cu
  17. app: messages
  18. setup.template.name: "filebeat"
  19. setup.template.pattern: "filebeat-*"
  20. output.elasticsearch:
  21. hosts: ["http://192.168.2.96:9200"]
  22. index: "%{[fields.project]}-%{[fields.app]}-%{+yyyy.MM.dd}"

最后的output中的hosts的ip地址是elasticsearch的ip地址和监听端口。

可以用docker ps命令查看是否在相关容器是否在运行

然后打开浏览器,输入服务器ip:5601,如下打开

在索引模板中可以查看到创建的filebeat模板已经加载成功了

创建数据视图

查看创建的日志视图

可以将filebeat装在其他服务器上,就可以实现多服务器的日志收集

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/949852
推荐阅读
相关标签
  

闽ICP备14008679号