我目前所在公司开发团队比较小,为集团下面的工厂开发了一套小的系统,跑在一台CentOS服务器上,服务器搭建了docker环境,安装了docker-compose,但在日志处理方面,暂时没有一个好的方法能够收集完全的日志,只能依赖进入至服务器后,以docker logs containerID的方法来进入查看,非常不方便,之前也有关注ELK的技术,但一直在开发系统功能,全力实现,今天得空,重新想起了ELK查看日志的任务。

kibana文档:https://www.elastic.co/guide/cn/kibana/current/index.html

关于elastic开始视频:https://www.elastic.co/guide/cn/index.html

项目文件夹

其中docker-compose.yml

version: '3'

services:
filebeat:
hostname: filebeat
image: weschen/filebeat
build:
context: filebeat
dockerfile: Dockerfile
volumes:
# needed to access all docker logs (read only) :
- "/var/lib/docker/containers:/usr/share/dockerlogs/data:ro"
# needed to access additional informations about containers
- "/var/run/docker.sock:/var/run/docker.sock"
links:
- logstash
kibana:
image: docker.elastic.co/kibana/kibana:6.5.2
environment:
- "LOGGING_QUIET=true"
links:
- elasticsearch
ports:
- 5601:5601
logstash:
hostname: logstash
image: weschen/logstash
build:
context: logstash
dockerfile: Dockerfile
ports:
- 5044:5044
environment:
LOG_LEVEL: error
links:
- elasticsearch
elasticsearch:
hostname: elasticsearch
image: weschen/elasticsearch
build:
context: elasticsearch
dockerfile: Dockerfile
environment:
- cluster.name=docker-elk-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms256m -Xmx256m"
ulimits:
memlock:
soft: -1
hard: -1
ports:
- 9200:9200

1.Elasticsearch

文件elasticsearch/Dockerfile

FROM docker.elastic.co/elasticsearch/elasticsearch:6.5.2
COPY --chown=elasticsearch:elasticsearch elasticsearch.yml /usr/share/elasticsearch/config/ CMD ["elasticsearch", "-Elogger.level=INFO"]

文件elasticsearch/elasticsearch.yml

cluster.name: ${cluster.name}
network.host: 0.0.0.0 # minimum_master_nodes need to be explicitly set when bound on a public IP
# set to 1 to allow single node clusters
# Details: https://github.com/elastic/elasticsearch/pull/17288
discovery.zen.minimum_master_nodes: 1

2.Logstash

文件logstash/Dockerfile

FROM docker.elastic.co/logstash/logstash:6.5.2

RUN rm -f /usr/share/logstash/pipeline/logstash.conf
COPY pipeline /usr/share/logstash/pipeline/

文件logstash/pipeline/logstash.conf

input {
beats {
port => 5044
host => "0.0.0.0"
}
} output {
elasticsearch {
hosts => elasticsearch
manage_template => false
index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
} stdout { codec => rubydebug }
}

3.Filebeat

文件filebeat/Dockerfile

FROM docker.elastic.co/beats/filebeat:6.5.2

# Copy our custom configuration file
COPY filebeat.yml /usr/share/filebeat/filebeat.yml USER root
# Create a directory to map volume with all docker log files
RUN mkdir /usr/share/filebeat/dockerlogs
RUN chown -R root /usr/share/filebeat/
RUN chmod -R go-w /usr/share/filebeat/

文件filebeat/filebeat.yml

filebeat.inputs:
- type: docker
combine_partial: true
containers:
path: "/usr/share/dockerlogs/data"
stream: "stdout"
ids:
- "*"
exclude_files: ['\.gz$']
ignore_older: 10m processors:
# decode the log field (sub JSON document) if JSON encoded, then maps it's fields to elasticsearch fields
- decode_json_fields:
fields: ["log", "message"]
target: ""
# overwrite existing target elasticsearch fields while decoding json fields
overwrite_keys: true
- add_docker_metadata:
host: "unix:///var/run/docker.sock" filebeat.config.modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false # setup filebeat to send output to logstash
output.logstash:
hosts: ["logstash"] # Write Filebeat own logs only to file to avoid catching them with itself in docker log files
logging.level: error
logging.to_files: false
logging.to_syslog: false
loggins.metrice.enabled: false
logging.files:
path: /var/log/filebeat
name: filebeat
keepfiles: 7
permissions: 0644
ssl.verification_mode: none

使用docker-compose up -d跑起来

在浏览器打开[Host-IP]:9200,能够打开以下界面,说明elasticsearch服务已经起来了

再在浏览器打开[Host-IP]:5601,是Kibana日志查看平台

进入至系统菜单【管理】中的【index-pattern】

首次使用Kibana需要先创建index-pattern,创建index-pattern操作如下,如果在Discover菜单中创建index-pattern时,会出现以下

创建了index-pattern后,查看Logs应该可以查看到日志

首页查看日志

源码地址:https://github.com/ChenWes/docker-elk

docker-compose ELK+Filebeat查看docker及容器的日志的更多相关文章

  1. Docker 部署 elk + filebeat

    Docker 部署 elk + filebeat kibana 开源的分析与可视化平台logstash 日志收集工具 logstash-forwarder(原名lubmberjack)elastics ...

  2. asp.net core容器&mysql容器network互联 & docker compose方式编排启动多个容器

    文章简介 asp.net core webapi容器与Mysql容器互联(network方式) docker compose方式编排启动多个容器 asp.net core webapi容器与Mysql ...

  3. DCOS实践分享(2):基于Docker Compose和Swarm的Docker化之路

    2016 年1 月 23 日,北京史上气温最低的一天. 在下午 1 点半的时候,由 DaoCloud 赞助的 2016 年度首次 Docker Meetup 准时开始. 在这次Meetup中,我分享了 ...

  4. Docker学习笔记之查看Docker

    命令: 使用history命令查看镜像历史 使用cp命令复制容器中的文件到主机 使用commit命令把修改过的容器创建为镜像 使用diff命令检查容器文件的修改 使用inspect命令查看容器/镜像详 ...

  5. docker-compose EFK查看docker及容器的日志

    上一篇<docker-compose ELK+Filebeat查看docker及容器的日志>已经演示了如何在docker中使用docker-compose创建容器,并将docker中的所有 ...

  6. Docker学习笔记之使用 Docker Compose 管理容器

    0x00 概述 通过之前的介绍,我们已经基本掌握了构建.运行容器的方法,但这还远远不够,由于 Docker 采用轻量级容器的设计,每个容器一般只运行一个软件,而目前绝大多数应用系统都绝不是一个软件所能 ...

  7. Docker 容器编排利器 Docker Compose

    Compose 简介 通过前面几篇文章的学习,我们可以通过 Dockerfile 文件让用户很方便的定义一个单独的应用容器.然而,在日常工作中,经常会碰到需要多个容器相互配合来完成某项任务的情况,例如 ...

  8. Docker Compose 容器编排 NET Core 6+MySQL 8+Nginx + Redis

    环境: CentOS 8.5.2111Docker 20.10.10Docker-Compose 2.1.0 服务: db  redis  web nginx NET Core 6+MySQL 8+N ...

  9. Docker Compose之容器编排开发初探

    1.前言 Docker Compose 是 Docker 官方编排(Orchestration)项目之一,负责快速在集群中部署分布式应用. Compose 是一个用于定义和运行多个 Docker 应用 ...

随机推荐

  1. 改写Unity DropDown 支持多次点击同一选项均回调

    [很久前的一个Note,不知道现在的Unity Dropdown是否已经支持该特性] Unity UGUI是开源的: https://bitbucket.org/Unity-Technologies/ ...

  2. 简单SQL注入试探、二

    DVWA——简单SQL注入小记 今天我们来记录简单的盲注过程 简单的SQL injection(blind) Level:low 登陆后选择SQL Injection(Blind) 能看到这样的界面 ...

  3. sql查询并把数据更新到另一个表中

    update OpenBills set peopleCount=(select rtNumber from Rooms where obId='ZD201005223') where obId='Z ...

  4. 部署在SAP Cloud Platform CloudFoundry环境的应用如何消费SAP Leonardo机器学习API

    Jerry的前一篇文章 如何在Web应用里消费SAP Leonardo的机器学习API 里介绍的例子是Neo测试环境的Web应用消费sandbox版本的机器学习API,url如下: https://s ...

  5. 第三章、vue-项目前端 - vue配置 | axios配置 | cookies配置 | element-ui配置 | bootstrap配置

    目录 vue项目创建 环境 创建项目 重构项目目录 文件修订:目录中非配置文件的多余文件可以移除 全局配置:全局样式.配置文件 axios前后台交互 cookies操作 element-ui页面组件框 ...

  6. python3和python2共存

    在window上同时安装py3.5和py2.7,但是命令行敲击python命令后,默认只出现py2.7的信息,敲击python3命令,提示未知的命令. 从网上查了一下,虽然环境变量都添加对了,但是可执 ...

  7. Anton and Chess(模拟+思维)

    http://codeforces.com/group/1EzrFFyOc0/contest/734/problem/D 题意:就是给你一个很大的棋盘,给你一个白棋的位置还有n个黑棋的位置,问你黑棋能 ...

  8. 18 Candidates for the Top 10 Algorithms in Data Mining

    Classification============== #1. C4.5 Quinlan, J. R. 1993. C4.5: Programs for Machine Learning.Morga ...

  9. NLP传统基础(1)---BM25算法---计算文档和query相关性

    一.简介:TF-IDF 的改进算法 https://blog.csdn.net/weixin_41090915/article/details/79053584 bm25 是一种用来评价搜索词和文档之 ...

  10. 基于RestOn智能睡眠监测器的睡眠监测系统

    一.项目地址为: https://github.com/linqian123... 二.项目功能概述: 该项目实现的是一个基于RestOn智能睡眠监测器的睡眠监测系统.RestOn智能睡眠检测器通过W ...