新款kubernetes日志收集利器fluent bit
Fluent Bit是一个开源和多平台的日志转发器 ,可以让您从不同来源收集数据/日志,统一并将其发送到多个目的地。它与Docker和Kubernetes环境完全兼容。Fluent Bit用C编写,具有支持30个扩展的可插拔架构。它快速轻便,通过TLS提供网络操作所需的安全性。最主要的是支持app分类,按容器id app等排序爽,而不是fluentd只有一个tag非常乱。
Fluent Bit是一个开源和多平台的日志转发器 ,可以让您从不同来源收集数据/日志,统一并将其发送到多个目的地。它与Docker和Kubernetes环境完全兼容。
Fluent Bit用C编写,具有支持30个扩展的可插拔架构。它快速轻便,通过TLS提供网络操作所需的安全性。
最主要的是支持app分类,按容器id app等排序爽,而不是fluentd只有一个tag非常乱。
此config我已加入监控 cpu 内存 磁盘等
kubectl create 启动即可
cat fluent-bit-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: fluent-bit
# namespace: logging
labels:
component: fluent-bit
data:
fluent-bit.conf: |
[SERVICE]
Flush 1
Daemon Off
Log_Level info
Parsers_File parsers.conf
# HTTP_Monitor Off
# HTTP_Port 2020
[INPUT]
Name tail
Path /var/log/containers/*.log
Parser docker
Tag kube.*
Mem_Buf_Limit 5MB
# DB /path/to/logs.db
# [INPUT]
# Name kmsg
# Tag kernel
[INPUT]
Name disk
Tag disk
Interval_Sec 60
[INPUT]
Name cpu
Tag my_cpu
[INPUT]
Name mem
Tag memory
[FILTER]
Name kubernetes
Match kube.*
[OUTPUT]
Name es
Match *
Host ${FLUENT_ELASTICSEARCH_HOST}
Port ${FLUENT_ELASTICSEARCH_PORT}
Logstash_Format On
Logstash_Prefix fluent-bit
Retry_Limit False
parsers.conf: |
[PARSER]
Name apache
Format regex
Regex ^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*?)(?: +\S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$
Time_Key time
Time_Format %d/%b/%Y:%H:%M:%S %z
[PARSER]
Name apache2
Format regex
Regex ^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$
Time_Key time
Time_Format %d/%b/%Y:%H:%M:%S %z
[PARSER]
Name apache_error
Format regex
Regex ^\[[^ ]* (?<time>[^\]]*)\] \[(?<level>[^\]]*)\](?: \[pid (?<pid>[^\]]*)\])?( \[client (?<client>[^\]]*)\])? (?<message>.*)$
[PARSER]
Name nginx
Format regex
Regex ^(?<remote>[^ ]*) (?<host>[^ ]*) (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*?)(?: +\S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$
Time_Key time
Time_Format %d/%b/%Y:%H:%M:%S %z
[PARSER]
Name json-test
Format json
Time_Key time
Time_Format %d/%b/%Y:%H:%M:%S %z
[PARSER]
Name docker
Format json
Time_Key time
Time_Format %Y-%m-%dT%H:%M:%S
Time_Keep On
[PARSER]
Name syslog
Format regex
Regex ^\<(?<pri>[0-9]+)\>(?<time>[^ ]* {1,2}[^ ]* [^ ]*) (?<host>[^ ]*) (?<ident>[a-zA-Z0-9_\/\.\-]*)(?:\[(?<pid>[0-9]+)\])?(?:[^\:]*\:)? *(?<message>.*)$
Time_Key time
Time_Format %b %d %H:%M:%S
cat fluent-bit-daemonset.yaml
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: fluent-bit
# namespace: kube-system
# namespace: logging
labels:
k8s-app: fluent-bit-logging
version: v1
kubernetes.io/cluster-service: "true"
spec:
template:
metadata:
labels:
k8s-app: fluent-bit-logging
version: v1
kubernetes.io/cluster-service: "true"
spec:
containers:
- name: fluent-bit
image: 192.168.1.103/k8s_public/fluent-bit:0.11.2
# image: fluent/fluent-bit-kubernetes-daemonset:latest
env:
- name: FLUENT_ELASTICSEARCH_HOST
value: "elasticsearch-logging"
- name: FLUENT_ELASTICSEARCH_PORT
value: "9200"
resources:
limits:
memory: 100Mi
requests:
cpu: 100m
memory: 100Mi
volumeMounts:
- name: config
mountPath: /fluent-bit/etc
- name: host-var-log
mountPath: /var/log
- name: host-var-lib-docker-containers
mountPath: /var/lib/docker/containers
# readOnly: true
- name: minikube-var-lib-docker-containers
mountPath: /mnt/sda1/var/lib/docker/containers
terminationGracePeriodSeconds: 10
volumes:
- name: config
configMap:
name: fluent-bit
- name: host-var-log
hostPath:
path: /var/log
- name: host-var-lib-docker-containers
hostPath:
path: /var/lib/docker/containers
- name: minikube-var-lib-docker-containers
hostPath:
path: /mnt/sda1/var/lib/docker/containers
#注意namespace 我这里为default , 如果你是其它namespace 要和es空间一致,kibana上创建索引注意头部为fluent-bit-*
更多推荐
所有评论(0)