Docker Compose部署 EFK(Elasticsearch + Fluentd + Kibana)收集日志
简述
本文用于记录如何使用Docker Compose部署 EFK(Elasticsearch + Fluentd + Kibana) 收集Docker容器日志,使用EFK,可以无侵入代码,获得灵活,易用的日志收集和分析。
fluentd镜像构建相关文件、docker-compose.yml文件都放在 https://github.com/LXD24/EFK 仓库里。
1、首先弄个fluentd镜像
因为Fluentd需要fluent-plugin-elasticsearch插件才能将日志传输到Elasticsearch,所以需要根据fluentd基础镜像构建一个集成fluent-plugin-elasticsearch插件的镜像,当然也可以在网上找一个已经集成的镜像,这里懒得找就自己构建了。
按照 https://github.com/fluent/fluentd-docker-image/blob/master/README.md 上的说明创建个Dockerfile文件,看了说明需要先下载两个文件(fluent.conf
和 entrypoint.sh
),github上有地址。
Dockerfile内容如下,因为我想着到时挂载fluent.conf
配置文件,所以删掉了 COPY fluent.conf /fluentd/etc/
这句复制配置文件的命令。
FROM fluent/fluentd:v1.11-1
# Use root account to use apk
USER root
# below RUN includes plugin as examples elasticsearch is not required
# you may customize including plugins as you wish
RUN apk add --no-cache --update --virtual .build-deps \
sudo build-base ruby-dev \
&& sudo gem install fluent-plugin-elasticsearch \
&& sudo gem sources --clear-all \
&& apk del .build-deps \
&& rm -rf /tmp/* /var/tmp/* /usr/lib/ruby/gems/*/cache/*.gem
#COPY fluent.conf /fluentd/etc/
COPY entrypoint.sh /bin/
USER fluent
然后就是docker build -t custom-fluentd:latest ./
看着一顿下载构建镜像。
2、准备一个会输出日志的镜像
这里我随便弄了个.net core web服务,输出下访问接口的日志到控制台。
3、编写docker-compose.yml
内容如下:
version: '2'
services:
webapplication1:
image: webapplication1
container_name: webapplication1
ports:
- '8001:80'
links:
- fluentd
logging:
driver: 'fluentd'
options:
fluentd-address: localhost:24224
tag: httpd.access
fluentd:
image: custom-fluentd
container_name: fluentd
volumes:
- ./fluentd/conf:/fluentd/etc
links:
- 'elasticsearch'
ports:
- '24224:24224'
- '24224:24224/udp'
elasticsearch:
image: elasticsearch:6.6.2
container_name: elasticsearch
ports:
- '9200:9200'
environment:
- 'discovery.type=single-node'
- 'cluster.name=docker-cluster'
- 'bootstrap.memory_lock=true'
- 'ES_JAVA_OPTS=-Xms512m -Xmx512m'
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./data:/usr/share/elasticsearch/data
kibana:
image: kibana:6.6.2
container_name: kibana
links:
- 'elasticsearch'
ports:
- '5601:5601'
webapplication1是我创建的web服务,需要配置日志驱动为fluentd
fluentd需要挂载fluent.conf
配置文件,fluent.conf
内容如下:
<source>
@type forward
port 24224
bind 0.0.0.0
</source>
<match *.**>
@type copy
<store>
@type elasticsearch
host elasticsearch
port 9200
logstash_format true
logstash_prefix fluentd
logstash_dateformat %Y%m%d
include_tag_key true
type_name access_log
tag_key @log_name
flush_interval 1s
</store>
<store>
@type stdout
</store>
</match>
4、启动
到yml文件夹目录下敲 docker-compose up
启动。
看到四个服务都是done的就可以了。
先访问下webapplication1造点日志,然后访问 http://localhost:5601 ,为Kibana设置匹配的索引名
然后就能看到收集的日志了。
Docker Compose部署 EFK(Elasticsearch + Fluentd + Kibana)收集日志的更多相关文章
- EFK(Elasticsearch+Filebeat+Kibana)收集容器日志
介绍 Elasticsearch 是一个实时的.分布式的可扩展的搜索引擎,允许进行全文.结构化搜索,它通常用于索引和搜索大量日志数据,也可用于搜索许多不同类型的文档. Beats 是数据采集的得力工具 ...
- Docker Compose部署GitLab服务,搭建自己的代码托管平台(图文教程)
场景 Docker-Compose简介与Ubuntu Server 上安装Compose: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/deta ...
- 使用Docker Compose部署基于Sentinel的高可用Redis集群
使用Docker Compose部署基于Sentinel的高可用Redis集群 https://yq.aliyun.com/articles/57953 Docker系列之(五):使用Docker C ...
- Docker Compose 部署前后端分离应用
部署前后端分离应用 容器化 Abp 应用 关于 Abp 应用的容器化,其实和普通的 ASP.NET Core 应用差不多,大家可以参考我此前的文章. 唯一需要注意的是:因为 Abp 解决方案中有多个项 ...
- Docker Compose部署项目到容器-基于Tomcat和mysql的项目yml配置文件代码
场景 Docker-Compose简介与Ubuntu Server 上安装Compose: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/deta ...
- 在Windows Server 2019通过Docker Compose部署Asp.Net Core
一.安装Docker Enterprise 安装文档是: https://docs.docker.com/install/windows/docker-ee/ 安装完成后,如下图 二.首先,拉取一个W ...
- 使用Docker Compose 部署Nexus后初次登录账号密码不正确,并且在nexus-data下没有admin,password
场景 Ubuntu Server 上使用Docker Compose 部署Nexus(图文教程): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/ ...
- Ubuntu Server 上使用Docker Compose 部署Nexus(图文教程)
场景 Docker-Compose简介与Ubuntu Server 上安装Compose: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/deta ...
- Docker Compose部署Nexus3时的docker-compose,yml代码
场景 Docker-Compose简介与Ubuntu Server 上安装Compose: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/deta ...
随机推荐
- https://www.cnblogs.com/mrchige/p/6409444.html
https://www.cnblogs.com/mrchige/p/6409444.html http://c.biancheng.net/view/2172.html https://www.cnb ...
- Telegraf和Grafana监控多平台上的SQL Server-自定义监控数据收集
问题 在上一篇文章中,我们使用Telegraf自带的Plugin配置好了的监控,但是自带的Plugin并不能完全覆盖我们想要的监控指标,就需要收集额外的自定义的监控数据,实现的方法有: 开发自己的Te ...
- 解决intellij idea卡顿的方法
使用idea越用越卡,即使是16G内存也是卡,多开几个微服务卡死了!! 解决方案 参考网路资源整理如下几条 1. 卸载不需要用的插件 我是Java开发,对于一些默认安装的什么安卓的google的app ...
- C#9.0 终于来了,带你一起解读Pattern matching 和 nint 两大新特性玩法
一:背景 1. 讲故事 上一篇跟大家聊到了Target-typed new 和 Lambda discard parameters,看博客园和公号里的阅读量都达到了新高,甚是欣慰,不管大家对新特性是多 ...
- 列表、元组、字典和简单if语句【python实验1】
第一次实验报告: 学生姓名 总成绩 tom 90 jack 89 john 96 kate 86 peter 100 实验内容3-1 建立两个列表分别对学生的姓名和总成绩信息进行存储 name=['t ...
- Swift 界面跳转
iOS开发中界面跳转有两种方式,上下跳转和左右跳转. 上下跳转_TO: let secondViewController = SecondViewController() self.presentVi ...
- matplotlib.pyplot.plot详解
参考资料: https://blog.csdn.net/baidu_41902768/article/details/80686608 之前的随笔也有说过,matplotlib是python中一个非常 ...
- Centos7 composer安装时 Warning: This development build of composer is over 60 days old. It is recommended to update it by running "/usr/bin/composer self-update" to get the latest version.
emmm,其实就是想让你运行一下/usr/bin/composer self-update这个命令更新一下
- 一小时彻底搞懂RabbitMQ
windows上面安装rabbitmq-server-3.7.4.exe 首先需要安装otp_win64_20.3.exe 步骤1:安装Erlang RabbitMQ 它依赖于Erlang,需要先安装 ...
- Vmware虚拟机克隆以及关闭防火墙
vmware虚拟机克隆之后,一定要修改克隆机器的mac地址和IP上网地址,不能和之前的机器一样