Filebeat+Elasticsearch+kibana日志收集

908 阅读1分钟

安装Filebeat

https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.15.0-linux-x86_64.tar.gz

配置Filebeat(testfilebeat.yml)

filebeat.inputs:  //设置日志输入源(可以配置多个)
- type: stdin     //日志源类型,这里指定标准输入,也就是控制台
  enabled: false   //是否启用
- type: log       //输入源是个日志文件
  enabled: true
  paths:          //指定文件路径
    - /logs/*.log
output.console:  //日志收集,最后输出,这里指定输出到控制台
  pretty: true   //使用友好格式输出
  enabled: true  //是否启用
output.elasticsearch:  //收集日志到es
  hosts: ["http://10.0.16.15:9202"]  

k8s启动pod(日志直接挂载在hostpath)

apiVersion: v1
kind: Pod
metadata:
  name: test-pro-pod
  labels:
    app: test-pro
spec:
  containers:
   - name: test-pro
     image: registry.cn-hangzhou.aliyuncs.com/wxximage/test-pro:2.0
     imagePullPolicy: IfNotPresent
     volumeMounts:
          - name: aaa
            mountPath: /app/app.log
  volumes:
        - name: aaa
          hostPath:
            path: /logs/app.log
            type: File

查看效果(kibana)

image.png 说明:这是我编写的一个测试镜像,已经上传了,调用一次接口打印三行日志(localhost:8080/test)