美文网首页
day21(ELK第二天)

day21(ELK第二天)

作者: 五月_w | 来源:发表于2019-07-11 17:03 被阅读0次

1、ELK第一天知识回顾


1.ELK各代表什么软件?
   - Elasticsearch
   - Filebeat
   - Logstash
   - Kibana

2.传统方式收集日志的弊端
   - 时间长,效率低,字段不能拆分,不能单独显示

3.ELK收集日志的架构

4.日志流转流程

5.安装部署filebeat
   - input    ----->nginx
   - output    ----->es
   - ES       ---->kibana

6.收集普通nginx日志有哪些不足
- 日志字段内容不能拆分,不能单独显示

7. 把nginx日志修改为JSON格式

8. filebeat配置文件添加2行JSON参数

9. 删除旧索引,重启filebeat

10. 在kibana里添加索引,测试数据
-时间范围    鼠标选择区间    quick time




2、现在的架构这不合理的地方以及合理的规划


1.按天生成太费事,不能聚合几天的数据
2.filebeat默认创建的索引不好区分是什么业务,不能区分域名



合理的规划:

1.索引按月生成
2.按照域名

3、怎么修改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.png

4、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", '
                           '"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.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"]

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"

setup.template.name: "nginx"
setup.template.pattern: "nginx_*"
setup.template.enabled: false
setup.template.overwrite: true

systemctl restart filebeat.service 


image.png
image.png

5、收集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.png image.png

6、收集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
  tags: ["java"]
  multiline.pattern: '^\['
  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.png
image.png

相关文章

  • day21(ELK第二天)

    1、ELK第一天知识回顾 2、现在的架构这不合理的地方以及合理的规划 3、怎么修改filebeat默认索引格式 4...

  • DBA课程-day20-ELK第二天

    ELK第一天知识回顾 ELK第二天内容 大家的索引命令方案 大家开会讨论筛选之后合理的索引命名 为什么filebe...

  • Docker下ELK设置

    1获取、启动elk 1.1获取elk镜像 $ docker pull sebp/elk 1.2启动elk镜像 启动...

  • Spring Cloud学习day108:ELK

    一、ELK介绍 1.ELK解决了什么问题? ELK的介绍:示例 ELK的架构原理:示例 二、安装ELK 1.安装E...

  • ELK日志分析系统初体验

    1 ELK技术栈 1.0 官方文档 ELK logstash elasticsearch kibana ELK技术...

  • 1.ELK介绍

    1.1 ELK简介 1.1.1 ELK是什么? ELK Stack 是 Elasticsearch、Logstas...

  • ELK扫盲以及搭建

    1. ELK部署说明 1.1ELK介绍: 1.1.1 ELK是什么? ELK是三个开源软件的缩写,分别表示:Ela...

  • 二、ELK工作原理

    ELK工作原理 ELK含义 ELK由ElasticSearch、Logstash和Kiabana三个开源工具组成。...

  • ELK基本部署

    ELK简介 什么是ELK?通俗来讲,ELK是由Elasticsearch、Logstash、Kibana 三个开源...

  • docker swarm elk 日志收集 kibana

    准备三个节点 elk1、elk2、elk3 准备elk环境 准备swarm环境 准备启动 备注: 源码地址 htt...

网友评论

      本文标题:day21(ELK第二天)

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