首页 > 系统相关 >elk 入门 - 分析nginx日志 + json格式 + 有调试的意识 + elk7.2.0

elk 入门 - 分析nginx日志 + json格式 + 有调试的意识 + elk7.2.0

时间:2023-06-26 12:03:50浏览次数:70  
标签:elk elk7.2 http log request nginx user time

1.本次采用的一台主机,将所有的软件安装一台上进行测试工作。

2.安装部署:https://blog.51cto.com/hwg1227/2299995

3.简单调试

输出rubydebug
input{
    file {
            path => "/usr/local/log_test/*/*/*.log"
        start_position => "beginning"
    }   
}
output {
    elasticsearch {
        hosts => ["10.0.0.92:9200"]
        index => "myre-%{+YYY.MM.dd}"
    }
    stdout {codec => rubydebug}
}
--------------------- 

原文:https://blog.csdn.net/yelllowcong/article/details/80847425
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for" $request_time';

5.filter的定义 参考

filter {
    grok {
        match => { "message" => "%{IPORHOST:remote_ip} - %{DATA:user_name} \[%{HTTPDATE:time}\] \"%{WORD:method} %{DATA:url} HTTP/%{NUMBER:http_version}\" %{NUMBER:response_code} %{NUMBER:body_sent:bytes} \"%{DATA:referrer}\" \"%{DATA:agent}\" \"%{DATA:x_forwarded_for}\" %{NUMBER:request_time}" }
#        remove_field => "message"
    }
}

 ########################################################

1.目标定义好nginx的日志格式为json格式。分割成多份。demo:统计11:00 - 11:50的404status状态的访问

2.nginx的日志格式

参考:https://www.linuxidc.com/Linux/2017-12/149811.htm

[root@rbtnode1 nginx]# cat /usr/local/nginx/conf/nginx.conf|egrep -v '#|^$'
。。。
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format json '{ "@timestamp": "$time_iso8601", '
                         '"time": "$time_iso8601", '
                         '"remote_addr": "$remote_addr", '
                         '"remote_user": "$remote_user", '
                         '"body_bytes_sent": "$body_bytes_sent", '
                         '"request_time": "$request_time", '
                         '"status": "$status", '
                         '"host": "$host", '
                         '"request": "$request", '
                         '"request_method": "$request_method", '
                         '"uri": "$uri", '
                         '"http_referrer": "$http_referer", '
                         '"body_bytes_sent":"$body_bytes_sent", '
                         '"http_x_forwarded_for": "$http_x_forwarded_for", '
                         '"http_user_agent": "$http_user_agent" '
                    '}';
    access_log  /var/log/nginx/access.log  json;
    sendfile        on;
    keepalive_timeout  65;

。。。
}

3.logstash的配置文件,连接es

[root@VM_0_92_centos bin]# cat  ../config/nginxdemojson.conf
input{
    file {
        path => "/var/log/nginx/access.log"
        codec => "json"
    }
}
filter{
}

output {
    elasticsearch {
        hosts => ["10.0.0.92:9200"]
        index => "demo-%{+YYY.MM.dd}"
    }
    stdout {codec => rubydebug}
}

---------------------------------------------------------------------------------------------------------------------

3.修改配置文件

vim config/elasticsearch.yml
#修改为自己的ip
network.host: x.x.x.x
#把这个注释先放开
cluster.initial_master_nodes: ["node-1", "node-2"]

4.修改limit文件

vim /etc/security/limits.conf
*               soft    nofile          65536
*               hard    nofile          65536
*               soft    nproc           4096
*               hard    nproc           4096
 
vi /etc/sysctl.conf
vm.max_map_count=262144
sysctl -p

 

用一个例子来演示会更加清晰



标签:elk,elk7.2,http,log,request,nginx,user,time
From: https://blog.51cto.com/u_13747193/6552918

相关文章

  • 配置文件 proxy_set_header -发往后端服务器的请求头---- nginx日志设置级别调试技巧
    http{includemime.types;default_typeapplication/octet-stream;sendfileon;#tcp_nopushon;#keepalive_timeout0;keepalive_timeout65;server_tokensoff;log_formatmain'$remote_addr-$remote_user[$time_local]......
  • Nginx 根据请求参数代理到指定网址
    1、参考nginx中将某一个请求的路径重定向到其它网址nginx:[emerg]unknowndirective"if($request_uri"in2、小坑if与($间需要有空格。判断请求路径中,是否包含/adminif($request_uri~'/admin'){return404;}3、配置location/xxxxx/client/register{......
  • MacOs Docker nginx.conf 配置
    `server{listen8089;server_namelocalhost;client_max_body_size120M;#php容器项目地址root/var/www/html/shop;indexindex.phpindex.htmlindex.htm;location/{#try_files$uri$uri//index.php?s=$uri&$args;}......
  • macbook m1 使用 brew 安装 nginx + 多版本 php
    目录macbookm1使用brew安装nginx+多版本php安装多个php版本1.配置php仓库2.安装多版本php3.配置php-pfm的端口4.启动php-pfm服务5.切换php-cli命令行的版本安装nginxmacbookm1使用brew安装nginx+多版本php在FastAdmin开发是,可能会用到多个p......
  • 使用 Debian、Docker 和 Nginx 部署 Web 应用
    前言本文将介绍基于Debian的系统上使用Docker和Nginx进行Web应用部署的过程。着重介绍了Debian、Docker和Nginx的安装和配置。第1步:更新和升级Debian系统通过SSH连接到服务器。更新软件包列表:sudoaptupdate升级已安装的软件包:sudoaptupgrade第2步......
  • 服务器与本地资源同步,在ubuntu自建git库,使用nginx远程http访问
    xshell在linux与windows之间传文件虽然方便,但使用git才能真正实现资源同步。为实现服务器与本地资源同步,在ubuntu服务器端自建git库。使用 git-http-backend 搭建git服务的原理都是类似的,主要是利用web服务器(apache/nginx)进行用户认证,并将用户信息传递给CGI程序 ......
  • Nginx反向代理&记录用户IP地址企业案例
    反向代理机器节点:lb0110.0.0.30#lb01是反向代理服务器(包括负载均衡的功能)www0110.0.0.40www0210.0.0.50【演示反向代理功能】 图片解读:使用客户端机器www01,访问负载均衡lb01(反向代理),看到了www01,www02页面信息在www01服务器上检测客户端信息,发现请求是10.0.0.3......
  • Nginx 优化
    目录一、Nginx隐藏版本号1.访问网站查看版本号2.隐藏方法3.刷新网页二、Nginx更改版本号1.修改Nginx源码文件2.重新编译安装3.将隐藏版本号设置打开4.刷新网页三、Nginx日志分割1.编写shell脚本2.运行脚本3.创建定时任务四、Nginx压缩页面1.更改配置文件2.清空......
  • Ingress-Nginx 灰度(金丝雀)发布
    使用Ingress-Nginx进行灰度(金丝雀)发布Ingress-NginxCanary介绍NginxIngressController作为项目对外的流量入口和项目中各个服务的反向代理。官方文档概述:Annotations-Ingress-NginxController(kubernetes.github.io)NginxAnnotations的几种Canary规则:Annota......
  • nginx
    Nginx是一种高性能的Web服务器软件,它可以作为反向代理服务器、负载均衡器、HTTP缓存、静态资源服务器等用途。Nginx的主要作用包括:静态资源服务器:Nginx支持快速、高效地响应静态文件的请求,包括HTML页面、CSS文件、图片等。它可以快速地将静态资源缓存起来,提高Web应用的访问速度......