首页 > 系统相关 >filebeat 配置采集nginx 日志

filebeat 配置采集nginx 日志

时间:2023-08-24 21:11:29浏览次数:34  
标签:filebeat http log 00 nginx 日志 id

filebeat 配置nginx 日志采集

  • filebeat 采集需求
1.需要将以往30 天的日志输出到es,并且以时间按天展示
2.将不同的时间字段解析出来,输出到es
  • nginx 配置json 日志
  log_format log_json '{ "remoteAddr": "$clientRealIp", '
'"date_timeLocal": "$time_local", '
'"remoteUser": "$remote_user", '
'"requestType": "$request_method", '
'"requestUrl": "$uri", '
'"URIPROTO": "$server_protocol", '
'"args": "$args", '
'"scheme": "$scheme", '
'"long_status": $status, '
'"long_bodyBytesSent": $body_bytes_sent, '
'"httpReferer": "$http_referer", '
'"httpUserAgent": "$http_user_agent", '
'"upstream_addr": "$upstream_addr", '
'"request_time": "$request_time",'
'"http_website": "$http_website",'
'"http_g_id": "$http_g_id",'
'"http_s_id": "$http_s_id",'
'"http_u_id": "$http_u_id"'
' }';
  • nginx server 配置日志格式
access_log /export/home/logs/production/access.log log_json;
error_log /export/home/logs/production/error.log warn;

  • nginx 日志样式
{ "remoteAddr": "12.11.11.111", "date_timeLocal": "24/Aug/2023:00:00:00 +0800", "remoteUser": "-", "requestType": "POST", "requestUrl": "/api/v1/words/pc/semantic/defi/", "URIPROTO": "HTTP/1.1", "args": "-", "scheme": "http", "long_status": 200, "long_bodyBytesSent": 41, "httpReferer": "https://xxx/wantWordsResult?lang=zh&query=%E5%A4%B9%E5%B8%A6%E7%A7%81%E8%B4%A7&category=1001", "httpUserAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Edg/116.0.1938.54", "upstream_addr": "192.168.26.178:8087", "request_time": "0.232","http_website": "-","http_g_id": "24e023cf-ab6a-4894-b30b-83cc749d778d","http_s_id": "YRTyTyB7-4687-4336-4f3s-yB167U92KY80","http_u_id": "64c06effd35d7c4b9c99e924" }
{ "remoteAddr": "12.11.11.111", "date_timeLocal": "24/Aug/2023:00:00:01 +0800", "remoteUser": "-", "requestType": "GET", "requestUrl": "/api/v1/words/pc/history/", "URIPROTO": "HTTP/1.1", "args": "lang=zh", "scheme": "http", "long_status": 200, "long_bodyBytesSent": 41, "httpReferer": "https://xxx/", "httpUserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Safari/605.1.15", "upstream_addr": "192.168.26.178:8087", "request_time": "0.016","http_website": "-","http_g_id": "7c767a7b-7a77-482d-b2f6-3aa7951ea5b9","http_s_id": "rKY4Y4Pw-9204-4639-50CA-4P16sO92Pr80","http_u_id": "-" }

  • 配置filebeat 日志采集
[root@dev-test-lingowhale filebeat]# cat filebeat.yml
# ============================== Filebeat inputs ===============================
filebeat.inputs:
- type: log
  id: shenyandayinginx-id
  enabled: true
  paths:
    - /lingowhale/k8snode*/project/volume-frontend/prod-frontend/access*.log
  fields:
    product: shenyandayi_nginx
  json.keys_under_root: true
  json.overwrite_keys: true
# ============================== Filebeat modules ==============================
filebeat.config.modules:
  # Glob pattern for configuration loading
  path: ${path.config}/modules.d/*.yml
  reload.enabled: true

# ======================= Elasticsearch template setting =======================
setup.template.enabled: false
setup.ilm.enabled: false

# =================================== Kibana ===================================

# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
# This requires a Kibana endpoint configuration.
setup.kibana:
  host: "10.0.0.2:5601"

# ---------------------------- Elasticsearch Output ----------------------------
output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["10.0.0.0:9200"]
  indices:
    - index: "prod-nginx"
# ================================= Processors =================================
#注意: 匹配日志格式,有两种日志格式需要解析,第一种是 2023-07-19T00:00:02+08:00 、第二种是 24/Aug/2023:00:00:01 +0800 
#timestamp 处理器,将nginx 30天的日志 按照 date_timeLocal 字段进行解析,输出到es 里会展示真实日志里面当时的时间,而不是现在的采集时间

processors:
  - timestamp:
      field: date_timeLocal
      timezone: Asia/Shanghai
      layouts:
        - '2006-01-02T15:04:05Z'
        - '2006-01-02T15:04:05.999Z'
        - '2006-01-02T15:04:05.999-07:00'
        - '02/Jan/2006:15:04:05 +0800'
      test:
        - '2019-06-22T16:33:51Z'
        - '2019-11-18T04:59:51.123Z'
        - '02/Jan/2006:15:04:05 +0800'
        - '2020-08-03T07:10:20.123456+02:00'
  - drop_fields:
      fields: ["agent","offset", "prospector", "source", "input", "beat","date_timeLocal"]


  • filebeat 启动并设置定时任务
[root@dev-test-xxxmanagelog]# cat /opt/scripts/monitorlog.sh
#!/bin/sh
process_num=`ps -ef |grep filebeat.yml |grep -v 'grep' |wc -l`
if [ ${process_num} -eq 0 ];then
  cd /export/filebeat && nohup ./filebeat -e -c filebeat.yml >> /export/filebeat/filebeat.log 2>&1 &
else
  echo "进程运行---"
fi


# 配置定时任务
[root@dev-test-lingowhale managelog]# crontab  -l
* * * * * /bin/bash /opt/scripts/monitorlog.sh > /dev/null 2>&1
  • kibana 日志展示

标签:filebeat,http,log,00,nginx,日志,id
From: https://www.cnblogs.com/lixinliang/p/17655161.html

相关文章

  • Linux之Shell脚本与Nginx
    1.入门Shell脚本1.1HelloWord打开我们的finalshell软件连接虚拟机在/usr/local/下创建一个点后缀为test的文件且编辑文件文件头部固定语句必须输入#!/bin/bash随后在下面我们直接输出一句Helloword按下ESC键且输入:wq保存退出后,这时不能直接执行,因为这个时候的文件你......
  • allure报告中firefox信息不展示(多浏览器或多线程执行时只显示一个浏览器的日志)
    安装的allure-pytest的版本要是2.11.1之前的(之后的版本有test_result.historyId,但位置及方法不一样,我目前没研究怎么修改)在依赖包Lib--site-packages--allure_pytest--listener.py文件里修改test_result.historyId=md5(item.nodeid)变成test_result.historyId=md5(item.nod......
  • Nginx内置lua版OpenResty拦截转发请求Redis等操作
    Nginx内置lua版OpenResty拦截转发请求Redis等操作1下载并安装OpenRestyhttp://openresty.org/cn/download.html2下载lua-resty-http-0.17.1库以让openresty的lua支持外部http访问能力lua-resty-http-0.17.11下载lua-resty-http-0.17.12然后将文件中lua-resty-http......
  • mysql使用sql开启日志
    --查看日志是否开启和日志文件夹showvariableslike'%general%';SETGLOBALgeneral_log='On';setgloballog_syslog=on;--慢sql日志setglobalslow_query_log=on;setglobalsql_log_off=on;--设置日志生成道的文件夹SETGLOBALgeneral_log_file='/lo......
  • Nginx-配置WebSocket反向代理
    客户环境因开放端口有限,部署Portainer后默认端口无法访问,故使用nginx做转发,按照正常http协议配置nginx,启动后发现portainer默认的进入容器的功能无法使用,排查后发现报错如下。错误信息为websocket连接问题,需要更改nginx配置为websocket。仅修改http块中的内容即可。map$http_......
  • Nginx-配置https证书
    一、说明在有些项目中需要帮客户配置https证书,如果你的服务使用Nginx作为静态服务器并且做为了端口转发,那么可以直接在Nginx中配置https证书证书有好几种格式,不同的格式对应不同server的配置,这里主要使用的是pem/key格式的证书,即公钥私钥文件对(必须要配对,否则无法使用)二......
  • Docker 安装 Nginx 教程
    Docker安装1.拉取镜像PSC:\Users\Administrator>dockerpullnginx2.创建挂载目录PSC:\Users\Administrator>mkdir-p/docker/nginx/confPSC:\Users\Administrator>mkdir-p/docker/nginx/logsPSC:\Users\Administrator>mkdir-p/docker/nginx/con......
  • 【Oracle RAC Database】Oracle Grid Infrastructure 启动流程与日志
    OS启动OHASD(OracleHighAvailabilityServices)init.ohasd.run被启动,该进程负责启动ohasd.bin守护进程[root@node01~]#ps-ef|grepohasd|grep-vgreproot5151018:59?00:00:00/bin/sh/etc/init.d/init.ohasdrun>/dev/null2>&1</dev/......
  • IIS日志分析
    https://learn.microsoft.com/zh-cn/archive/blogs/exchange_chs/log-parser-studioIIS日志——统计IP访问次数的一种方法使用LogParser对IIS服务器被Hit访问的IP进行次数统计,方便结合防火墙IP***列表对IIS网站进行日志审计报表的编写配置IIS网站的日志下载进行日志分析的两个工具L......
  • 解密Nginx的高性能魔法:事件驱动与异步非阻塞模型
    在现代的Web服务架构中,Nginx已成为不可或缺的一部分,以其出色的性能和高效的事件驱动异步非阻塞模型而闻名。本文将深入探讨Nginx的工作原理,重点介绍其事件驱动与异步非阻塞模型,以及如何利用这些特性来实现高性能的后端服务。Nginx的事件驱动与异步非阻塞模型事件驱动模型Nginx使用......