ELK收集nginx日志

配置nginx 正则表达式

路径:

bash 复制代码
/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/logstash-patterns-core-4.1.2/patterns

正则表达式:

bash 复制代码
URIPARAM1 [A-Za-z0-9$.+!*'|(){},~@#%&/=:;_?\-\[\]]*

NGINXACCESS %{IPORHOST:client_ip} (%{USER:ident}|- ) (%{USER:auth}|-) \[%{HTTPDATE:timestamp}\] 
"(?:%{WORD:verb} (%{NOTSPACE:request}|-)(?: HTTP/%{NUMBER:http_version})?|-)" %{NUMBER:status} 
(?:%{NUMBER:bytes}|-) "(?:%{URI:referrer}|-)" "%{GREEDYDATA:agent}"

然后配置logstash 的conf.d的目录

新建nginx.conf

bash 复制代码
input {
      file {
            path => "/var/log/nginx/access.log"
            type => "nginx-log"
            start_position => "beginning"

}
}
filter{
         grok{

         match => {"message" => "%{NGINXACCESS}"}
}

}
output {
          elasticsearch {

              hosts => "192.168.253.225:9200"
              index => "nginx_log-%{+YYYY.MM.dd}"

重启 logstash

bash 复制代码
systemctl restart logstash

压力测试

bash 复制代码
yum -y install epel-release httpd-tools

ab  -n  1000  -c  200 http://192.168.253.232/index.html

这个是测试报错信息的

bash 复制代码
/usr/share/logstash/bin/logstash -rf /etc/logstash/conf.d/nginx.conf

然后去kibana

创建索引

定制日志趋势图

粉丝福利

相关推荐
君穆南1 小时前
基于 NFS 与 Rsync 实现跨服务器 Seafile 数据平滑迁移实战
linux·运维·git
bloglin999991 小时前
scp、rsync远程文件同步
linux·运维·服务器
迦南的迦 亚索的索1 小时前
LINUX环境
linux·运维·服务器
yuanjj881 小时前
linux下调试域格CLM920 NC5等9x07平台模块 QMI拨号
linux·运维·服务器
IMPYLH2 小时前
Linux 的 printenv 命令
linux·运维·服务器·bash
SilentSamsara2 小时前
SSH 远程管理:密钥登录 + 隧道转发,一次性配置好
linux·运维·服务器·ubuntu·centos·ssh
Cx330❀3 小时前
Linux命名管道(FIFO)通信:从原理到实操,一文搞懂跨进程通信
大数据·linux·运维·服务器·elasticsearch·搜索引擎
嵌入式×边缘AI:打怪升级日志3 小时前
嵌入式Linux应用开发快速入门(从零到第一个程序)
linux·运维·notepad++
AI、少年郎3 小时前
MiniMind第 2 篇:破除大模型 “神秘感“, 环境搭建|Win/Linux 本地快速部署
linux·运维·服务器·ai·大模型训练·大模型微调·大模型原理
乐维_lwops4 小时前
五层架构全景解析:Lerwee 运维智能体如何实现 “从感知到行动”(二)
运维·架构·运维智能体