美文网首页
centos7搭建ELK6.6.0(下)

centos7搭建ELK6.6.0(下)

作者: 萌木盖 | 来源:发表于2019-04-05 22:49 被阅读0次
基于 Filebeat 的 ELK 集群架构

因为免费的 ELK 没有任何安全机制,所以可以使用了 Nginx 作反向代理,避免用户直接访问 Kibana 服务器。加上配置 Nginx 实现简单的用户认证,一定程度上提高安全性。另外,Nginx 本身具有负载均衡的作用,能够提高系统访问性能。

可以使用Nginx,但是~我不用!hhhhhhhh

当然,除了Filebeat,还有很多的beat,因为我不用,所以我不讲,hhhh

下面是Filebeat的运行图:

Filebeat

Filebeat由两个主要组件组成:prospector 和harvester。这些组件一起工作来读取文件(tail file)并将事件数据发送到您指定的输出
启动Filebeat时,它会启动一个或多个查找器,查看您为日志文件指定的本地路径。 对于prospector 所在的每个日志文件,prospector 启动harvester。 每个harvester都会为新内容读取单个日志文件,并将新日志数据发送到libbeat,后者将聚合事件并将聚合数据发送到您为Filebeat配置的输出。

harvester

harvester :负责读取单个文件的内容。读取每个文件,并将内容发送到 the output
每个文件启动一个harvester, harvester 负责打开和关闭文件,这意味着在运行时文件描述符保持打开状态
如果文件在读取时被删除或重命名,Filebeat将继续读取文件。
这有副作用,即在harvester关闭之前,磁盘上的空间被保留。默认情况下,Filebeat将文件保持打开状态,直到达到close_inactive状态
关闭harvester会产生以下结果:

  • 1、如果在harvester仍在读取文件时文件被删除,则关闭文件句柄,释放底层资源。
  • 2、文件的采集只会在scan_frequency过后重新开始。
  • 3、如果在harvester关闭的情况下移动或移除文件,则不会继续处理文件。
    要控制收割机何时关闭,请使用close_ *配置选项

prospector

prospector 负责管理harvester并找到所有要读取的文件来源。
如果输入类型为日志,则查找器将查找路径匹配的所有文件,并为每个文件启动一个harvester。
每个prospector都在自己的Go协程中运行。
以下示例将Filebeat配置为从与指定的匹配的所有日志文件中收集行:

filebeat.prospectors:
- type: log
  paths:
    - /var/log/*.log
    - /var/path2/*.log

Filebeat目前支持两种prospector类型:log和stdin。
每个prospector类型可以定义多次。
日志prospector检查每个文件以查看harvester是否需要启动,是否已经运行,
或者该文件是否可以被忽略(请参阅ignore_older)。
只有在harvester关闭后文件的大小发生了变化,才会读取到新行。
注:Filebeat prospector只能读取本地文件, 没有功能可以连接到远程主机来读取存储的文件或日志。

filebeat配置

由于6.0之后的版本,不再支持 document_type 这个选项了

Starting with Logstash 6.0, the document_type option is deprecated due to the removal of types in Logstash 6.0. It will be removed in the next major version of Logstash. If you are running Logstash 6.0 or later, you do not need to set document_type in your configuration because Logstash sets the type to doc by default.

所以为了lostash能区分不同目录发过来的日志,我们使用 tags属性

tags
A list of tags that the Beat includes in the tags field of each published event. Tags make it easy to select specific events in Kibana or apply conditional filtering in Logstash. These tags will be appended to the list of tags specified in the general configuration.

创建filebeat目录下新建一个mytest.yml:

#=========================== Filebeat inputs =============================

filebeat.prospectors:
- type: log
  # Change to true to enable this prospector configuration.
  enabled: true
  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - /var/log/*.log
  tags: ["log1"]
- type: log
  enabled: true
  paths:
    - /var/log2/*.log
  tags: ["log2"]

  # 只发送包含ERR,WARN字样的日志
  # include_lines: ['^ERR', '^WARN']
  # 不发送包含OK字样的日志
  # exclude_lines: ["^OK"]

​
# 输出的位置,直接输出到elastic的话,选第一个,输出到logstash的话,选第二个
#output.elasticsearch:
    # Array of hosts to connect to.
    #hosts: ["localhost:9200"]
   
output.logstash:
    # The Logstash hosts
    hosts: ["localhost:5044"] # 具体ip自己改

在logstash解压的文件下config建一个mytest.conf:

input {
  beats {
    port => 5044
  }
}

output {
# 如果要判断
#if [type] == "log1" {      #写入iislog日志到 es
#         elasticsearch{
#          hosts => ["172.16.1.176:9200"]
#          index => "iislog1-%{+YYYY.MM.dd}"  
#        }
#    }
#    if [type] == "log2" {      #写入iislog日志到 es
#         elasticsearch{
#          hosts => ["172.16.1.176:9200"]
#          index => "iislog2-%{+YYYY.MM.dd}"  
#       }
#    }
#不需要判断的话
  elasticsearch {
    hosts => ["http://172.16.1.176:9200"]
    index => "mytest-%{+YYYY.MM.dd}"
    # index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
    #user => "elastic"
    #password => "changeme"
  }
}

在screen里面启动logstash:

./bin/logstash -f ./config/mytest.conf

启动filebeat:

./filebeat -c ./mytest.yml

最后再你指定的日志路径写入日志:

echo "afjsfaisjfiapsijf"   > a.log # “内容瞎打的”

查看一下kibana


kibana

完成了
本博部分抄袭于此链接

相关文章

网友评论

      本文标题:centos7搭建ELK6.6.0(下)

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