收集形式:
1,每个pod里面都跑两个容器,一个应用容器,一个filebeat日志收集容器
2,pod的容器之间通过emptyDir来共享一个日志目录,应用容器的里面的日志往这个目录里面去写日志,日志手机容器从这个目录里面去读取收集日志
3,使用configMap 去配置filebeat的配置文件,通过volumeMount的方式去使用configMap(注意这里需要先创建configMap)
eg:(我的elk 已经搭建好了,用的是6.7.3版本)
1.创建filebeat的dockerfile
FROM centos:7.6
ADD filebeat-6.3.2-linux-x86_64.tar.gz /usr/local/src
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& mv /usr/local/src/filebeat-6.3.2-linux-x86_64 /usr/local/filebeat \
&& mkdir /etc/filebeat
CMD ["/usr/local/filebeat/filebeat","-c","/etc/filebeat/filebeat.yaml"]
2.创建configMap
apiVersion: v1
kind: ConfigMap
metadata:
name: middle-filebeat
data:
filebeat.yaml: |
filebeat.inputs:
- type: log
fields:
tag: middle
enabled: true
paths:
- /mnt/*.log
multiline:
pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
negate: true
match: after
max_lines: 300
timeout: 10s
#----------------------------- Logstash output --------------------------------
output.logstash:
hosts: ["192.168.66.66:5044"]
3.使用Deployment去创建pod
apiVersion: apps/v1
kind: Deployment
metadata:
name: middle-service
labels:
app: middle-service
spec:
replicas: 1
minReadySeconds: 10
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: middle-service
template:
metadata:
labels:
app: middle-service
spec:
containers:
- name: middle-service
image: 192.168.0.204/dev/middle_service:202001091638
ports:
- containerPort: 8090
env:
- name: profile
value: dev
volumeMounts:
- name: provide-nfs
mountPath: /home/httpd/middle/img
- name: app-logs
mountPath: /var/log/md_service_yooticloud
- name: middle-filebeat
image: 192.168.0.204/dev/filebeat
volumeMounts:
- name: app-logs
mountPath: /mnt
- name: filebeat
mountPath: /etc/filebeat
volumes:
- name: provide-nfs
nfs:
path: /data/middle
server: 192.168.60.11
- name: app-logs
emptyDir: {}
- name: filebeat
configMap:
name: middle-filebeat
(备注:192.168.0.204/dev/filebeat 这是我的filebeat的镜像,这里由于采用了emptyDir{},数据不能持久化保留,生产的话最好使用其他的模式)
4.配置logsash
input {
stdin {}
beats {
port => 5044
}
}
output {
if [fields][type] == "odoo-test" {
elasticsearch {
hosts => ["192.168.66.66:9200"]
index => "odoo_test.yt"
}
}
if [fields][type] == "odoo-yuetian" {
elasticsearch {
hosts => ["192.168.66.66:9200"]
index => "yuetian.log"
}
}
if [fields][tag] == "middle" {
elasticsearch {
hosts => ["192.168.66.66:9200"]
index => "middle-service.log"
}
}
stdout {
codec => rubydebug }
}
(备注: 在output这里 添加了middle 这一段)
5.去kibana里面添加这个索引
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200113120321137.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM4Mjg2Mzc0,size_16,color_FFFFFF,t_70)
查看收集的日志:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200113120400379.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM4Mjg2Mzc0,size_16,color_FFFFFF,t_70)
完毕!!!
来源:CSDN
作者:qq_38286374
链接:https://blog.csdn.net/qq_38286374/article/details/103956337