美文网首页
The Road of DBA 21_NoSQL_ELK---(

The Road of DBA 21_NoSQL_ELK---(

作者: Linux_淡忘 | 来源:发表于2019-07-11 19:43 被阅读0次

    1.1、怎么修改filebeat默认索引格式

    
    索引格式为:服务名称-域名-日志格式-时间(按月)
    
    1)vim /etc/filebeat/filebeat.yml
    
    filebeat.inputs:
    - type: log
      enabled: true 
      paths:
        - /var/log/nginx/access.log
      json.keys_under_root: true
      json.overwrite_keys: true
    output.elasticsearch:
      hosts: ["10.0.0.51:9200"]
      index: "nginx-www-access-%{[beat.version]}-%{+yyyy.MM}"
    setup.template.name: "nginx"
    setup.template.pattern: "nginx-*"
    setup.template.enabled: false
    setup.template.overwrite: true
    
    2)systemctl restart filebeat.service 
    
    
    image image

    1.2、nginx修改多域名多日志

    
    1)vim  /etc/nginx/nginx.conf
    user nginx;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;
    events {
        worker_connections 1024;
    }
    http {
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
       log_format   json '{ "time_local": "$time_local", '            ##添加此项,以json格式进行刷写日志
                               '"remote_addr": "$remote_addr", '
                               '"referer": "$http_referer", '
                               '"request": "$request", '
                               '"status": $status, '
                               '"bytes": $body_bytes_sent, '
                               '"agent": "$http_user_agent", '
                               '"x_forwarded": "$http_x_forwarded_for", '
                               '"up_addr": "$upstream_addr",'
                               '"up_host": "$upstream_http_host",'
                               '"upstream_time": "$upstream_response_time",'
                               '"request_time": "$request_time"'
        ' }';
        access_log  /var/log/nginx/access.log  json;
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
        include /etc/nginx/conf.d/*.conf;
    }
    
    2) [root@db01 /etc/nginx/conf.d]# cat bbs.conf   #配置子网页
    server {
        listen 80;
        server_name  www.oldboy.com;
        location / {
            root /html/www;
            index index.html;
        }
        access_log  /var/log/nginx/www_access.log  json;
    }
    
    3)[root@db01 /etc/nginx/conf.d]# cat bbs.conf 
    server {
        listen 80;
        server_name  bbs.oldboy.com;
        location / {
            root /html/bbs;
            index index.html;
        }
        access_log  /var/log/nginx/bbs_access.log  json;
    }
    
    4)[root@db01 /etc/nginx/conf.d]# cat blog.conf 
    server {
        listen 80;
        server_name  blog.oldboy.com;
        location / {
            root /html/blog;
            index index.html;
        }
        access_log  /var/log/nginx/blog_access.log  json;
    }
    
    5)mkdir /html/{www,blog,bbs} -p
       echo "db01 www" > /html/www/index.html
       echo "db01 bbs" > /html/bbs/index.html               ##创建一个区别显示的首页文件
       echo "db01 blog" > /html/blog/index.html
       chown -R nginx:nginx /html/
       nginx -t
       systemctl restart nginx 
    
    6)filebeat配置文件
    vim /etc/filebeak/filebeak.yml
    
    filebeat.inputs:
    - type: log
      enabled: true 
      paths:
        - /var/log/nginx/bbs_access.log
      json.keys_under_root: true                              ##支持json格式的两个参数
      json.overwrite_keys: true                                  ##json重写索引
      tags: ["bbs"]                                                       ##关键字
    
    - type: log
      enabled: true 
      paths:
        - /var/log/nginx/blog_access.log
      json.keys_under_root: true
      json.overwrite_keys: true
      tags: ["blog"]
    
    - type: log
      enabled: true 
      paths:
        - /var/log/nginx/www_access.log
      json.keys_under_root: true
      json.overwrite_keys: true
      tags: ["www"]
    
    - type: log
      enabled: true
      paths:
        - /var/log/nginx/error.log
      tags: ["error"]
    
    output.elasticsearch:
      hosts: ["10.0.0.51:9200"]
      indices:
        - index: "nginx_www_access-%{[beat.version]}-%{+yyyy.MM}"
          when.contains:                 ###索引名称的重构
            tags: "www"                    ###当匹配到www的时候索引名字为上
        - index: "nginx_bbs_access-%{[beat.version]}-%{+yyyy.MM}"
          when.contains:
            tags: "bbs"
        - index: "nginx_blog_access-%{[beat.version]}-%{+yyyy.MM}"
          when.contains:
            tags: "blog"
        - index: "nginx_error-%{[beat.version]}-%{+yyyy.MM}"
          when.contains:
            tags: "error"
    
    setup.template.name: "nginx"                      ###重写规则
    setup.template.pattern: "nginx_*"                ##
    setup.template.enabled: false                     ###关闭默认格式
    setup.template.overwrite: true                    ###启用上面的规则
    
    systemctl restart filebeat.service 
    
    
    image image

    1.3、收集tomcat日志

    
    1.安装tomcat
    yum install tomcat tomcat-webapps tomcat-admin-webapps tomcat-docs-webapp tomcat-javadoc -y
    
    2.修改tomcat配置文件为json格式
    vim /etc/tomcat/server.xml
    
    第139行替换为:
    pattern="{"clientip":"%h","ClientUser":"%l","authenticated":"%u","AccessTime":"%t","method":"%r","status":"%s","SendBytes":"%b","Query?string":"%q","partner":"%{Referer}i","AgentVersion":"%{User-Agent}i"}"/>
    
    3.重启tomcat
    systemctl restart tomcat
    
    4.修改filebeat配置文件
    filebeat.inputs:
    - type: log
      enabled: true 
      paths:
        - /var/log/nginx/bbs_access.log
      json.keys_under_root: true
      json.overwrite_keys: true
      tags: ["bbs"]
    
    - type: log
      enabled: true 
      paths:
        - /var/log/nginx/blog_access.log
      json.keys_under_root: true
      json.overwrite_keys: true
      tags: ["blog"]
    
    - type: log
      enabled: true 
      paths:
        - /var/log/nginx/www_access.log
      json.keys_under_root: true
      json.overwrite_keys: true
      tags: ["www"]
    
    - type: log
      enabled: true 
      paths:
        - /var/log/tomcat/localhost_access_log.*.txt
      json.keys_under_root: true
      json.overwrite_keys: true
      tags: ["tomcat"]
    
    - type: log
      enabled: true 
      paths:
        - /var/log/nginx/error.log
      tags: ["error"]
    
    output.elasticsearch:
      hosts: ["10.0.0.51:9200"]
      indices:
        - index: "nginx_www_access-%{[beat.version]}-%{+yyyy.MM}"
          when.contains:
            tags: "www"
        - index: "nginx_bbs_access-%{[beat.version]}-%{+yyyy.MM}"
          when.contains:
            tags: "bbs"
        - index: "nginx_blog_access-%{[beat.version]}-%{+yyyy.MM}"
          when.contains:
            tags: "blog"
        - index: "nginx_error-%{[beat.version]}-%{+yyyy.MM}"
          when.contains:
            tags: "error"
        - index: "tomcat_access-%{[beat.version]}-%{+yyyy.MM}"
          when.contains:
            tags: "tomcat"
    
    setup.template.name: "nginx"
    setup.template.pattern: "nginx_*"
    setup.template.enabled: false
    setup.template.overwrite: true
    
    systemctl restart filebeat.service 
    
    
    image image

    1.4、收集elasticsearch日志

    cat /etc/filebeat/filebeat.yml
    filebeat.inputs:
    - type: log
      enabled: true 
      paths:
        - /var/log/nginx/bbs_access.log
      json.keys_under_root: true
      json.overwrite_keys: true
      tags: ["bbs"]
    
    - type: log
      enabled: true 
      paths:
        - /var/log/nginx/blog_access.log
      json.keys_under_root: true
      json.overwrite_keys: true
      tags: ["blog"]
    
    - type: log
      enabled: true 
      paths:
        - /var/log/nginx/www_access.log
      json.keys_under_root: true
      json.overwrite_keys: true
      tags: ["www"]
    
    - type: log
      enabled: true
      paths:
        - /var/log/nginx/error.log
      tags: ["error"]
    - type: log
      enabled: true
      paths:
        - /var/log/tomcat/localhost_access_log.*.txt
      tags: ["tomcat"]
    - type: log
      enabled: true
      paths:
        - /var/log/elasticsearch/linux58.log            ##监控ES日志的报错情况
      tags: ["java"]
      multiline.pattern: '^\['                                    ##通过此参数可以定义message行的范围
      multiline.negate: true                                   ##规则可以百度了解到
      multiline.match: after
    
    output.elasticsearch:
      hosts: ["10.0.0.51:9200"]
      indices:
        - index: "nginx_www_access-%{[beat.version]}-%{+yyyy.MM}"
          when.contains:
            tags: "www"
        - index: "nginx_bbs_access-%{[beat.version]}-%{+yyyy.MM}"
          when.contains:
            tags: "bbs"
        - index: "nginx_blog_access-%{[beat.version]}-%{+yyyy.MM}"
          when.contains:
            tags: "blog"
        - index: "nginx_error-%{[beat.version]}-%{+yyyy.MM}"
          when.contains:
            tags: "error"
        - index: "tomcat_access-%{[beat.version]}-%{+yyyy.MM}"
          when.contains:
            tags: "tomcat"
        - index: "es_access-%{[beat.version]}-%{+yyyy.MM}"
          when.contains:
            tags: "java"
    
    setup.template.name: "nginx"
    setup.template.pattern: "nginx_*"
    setup.template.enabled: false
    setup.template.overwrite: true
    
    systemctl restart filebeat.service 
    
    
    image image

    制图

    )QP47@DMX9S556~U9K_%9W8.png

    ![]U6HC)78A~MVVO67V2BOV}F.png](https://img.haomeiwen.com/i16832986/74884df895ef98ec.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

    }9EB{PN3CN3OMYIXNNM(RTA.png 0OOZVGQQD}ZXDS_R%YI6OHJ.png BNKK49CQ$2}_$AY)TGY)~M9.jpg H}O66UBB5I4{[R$]OW9$]8G.png OH1W$~4(B9TR0VHLSF76H%G.png

    ![ULMDNSAAQFG$Y(`H5XXYTJ.png

    相关文章

      网友评论

          本文标题:The Road of DBA 21_NoSQL_ELK---(

          本文链接:https://www.haomeiwen.com/subject/qlljkctx.html