赞
踩
安装docker容器
拉取镜像:
docker pull elastic/filebeat:7.5.1
启动:
docker run -d --name=filebeat elastic/filebeat:7.5.1
拷贝容器中的数据文件到宿主机:
mkdir -p /data/elk7
docker cp filebeat:/usr/share/filebeat /data/elk7/
设置权限
chmod 777 -R /data/elk7/filebeat
#go-w: 这个命令表示去掉文件的“组”和“其他用户”的写权限。其中,
#g 代表组权限,o 代表其他用户权限,-w 表示去掉写权限。
chmod go-w /data/elk7/filebeat/filebeat.yml
配置filebeat
vim /data/elk7/filebeat/filebeat.yml
修改样例如下:
filebeat.inputs: - type: log enabled: true paths: - /var/log/*.log fields: AppId: "springbootadmin" ENV: "DEV" fields_under_root: true tags: ["服务ip地址自定义其他", "boot"] json.keys_under_root: true - type: log enabled: true paths: - /java/*.log fields: AppId: "live-admin" ENV: "DEV" fields_under_root: true tags: ["服务ip地址自定义其他", "live"] json.keys_under_root: true processors: - timestamp: field: "time" timezone: "Asia/Shanghai" layouts: - "yyyy-MM-dd HH:mm:ss.SSS" output.elasticsearch: hosts: 'es:9200' username: "elastic" password: "elastic" indices: - index: "spring-boot-admin-%{+yyyy.MM}" when.contains: tags: "boot" - index: "live-admin-%{+yyyy.MM}" when.contains: tags: "live" setup.template.settings: index.number_of_shards: 3 index.number_of_replicas: 0
日志输入源:
日志标签:
Elasticsearch 输出:
Elasticsearch 索引设置:
删除之前的容器:
docker rm -f filebeat
再重启启动:
docker run --name=filebeat --restart=always \
-v /data/elk7/filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml \
-v /var/log/springboot/:/var/log/springboot/ \
-v /data/log/live-admin/logs/:/var/log/live-admin/logs/ \
-d elastic/filebeat:7.5.1
排查问题命令
docker logs filebeat
进入容器:
docker exec -it filebeat /bin/bash
docker exec -it filebeat /bin/sh
nginx的日志采集
如果要采集nginx的日志的话需要设置nginx日志格式
#修改nginx.conf,在http 、https中设置日志格式 #添加 log_format main user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; worker_rlimit_nofile 10240; events { worker_connections 10240; } http { include /etc/nginx/mime.types; default_type application/octet-stream; server_tokens off; proxy_hide_header X-Powered-By; proxy_hide_header Server; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; proxy_connect_timeout 30000; keepalive_timeout 30000; client_max_body_size 100m; client_header_buffer_size 512k; large_client_header_buffers 4 512k; #gzip on; include /etc/nginx/conf.d/*.conf; }
在**filebeat.inputs:**新增一个log
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
fields:
AppId: "nginx"
ENV: "DEV"
fields_under_root: true
tags: ["ip","nginx"]
json.keys_under_root: true
在**indices:**下新增一个index
- index: "nginx-%{+yyyy.MM}"
when.contains:
tags: "nginx"
设置命令行中执行 Nginx 相关的命令时不输入完整路径
export PATH=/usr/sbin:/usr/local/nginx/sbin:$PATH
通过将这两个目录添加到 PATH 中,可以方便地在命令行中直接执行 nginx 命令来启动或管理 Nginx 服务器,而不必输入完整的路径。
再次删除容器重新启动,把nginx日志也挂在上去
docker run --name=filebeat --restart=always \
-v /data/elk7/filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml \
-v /var/log/springboot/:/var/log/springboot/ \
-v /data/log/live-admin/logs/:/var/log/live-admin/logs/ \
-v /var/log/nginx/:/var/log/nginx/ \
-d elastic/filebeat:7.5.1
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。