`
bingtang5
  • 浏览: 12353 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ELK日志分析平台搭建 + Beats

阅读更多

ELK

E = Elasticsearch,一款基于的Lucene的分布式搜索引擎,我们熟悉的github,就是由ElastiSearch提供的搜索,据传已经有10TB+的数据量。 

L = Logstash , 一款分布式日志收集系统,支持多输入源,并内置一些过滤操作,支持多输入元 

K = Kibana , 一款配合ElasticSearch的web可视化界面,内置非常各种查询,聚合操作,并拥有漂亮的图形化展示功能 

官网地址:https://www.elastic.co

这里再介绍一个很好用的轻量级的产品 Beats,支持同logstash和elasticsearch进行交互

Filebeat   Real-time insight into log data.
Packetbeat   Analyze network packet data.
Winlogbeat   Analyze Windows event logs.
Metricbeat   Ship and analyze metrics.

下面是官方的产品结构图

由上图可见可以用K+E+Logstash

也可以 K+E+Beats组成

下面将一一介绍搭建方法

本例介绍如何搭建配置最新的 5.0版本

环境搭建

ELK的搭建

环境依赖 java 1.8 及以上版本

yum -y install java-1.8.0-openjdk

 

本例在Centos7 x64上root用户yum方式安装,也可以自己下载tar包解压手动运行,具体安装方式见官网教程

https://www.elastic.co/guide/en/logstash/current/installing-logstash.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html

https://www.elastic.co/guide/en/kibana/current/install.html

 

配置repo源

vim /etc/yum.repos.d/elastic.repo

添加下面内容

[elasticsearch-5.x]
name=Elasticsearch repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

:x

然后安装

yum -y install elasticsearch kibana logstash

到此安装结束

 

EKB的搭建

配置好repo源后

yum -y install elasticsearch kibana

然后下载 beat的rpm包或者tar包,这里介绍rpm包安装

需要依赖curl,没有的yum安装

Filebeats

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.0.1-x86_64.rpm
rpm -vi filebeat-5.0.1-x86_64.rpm

Metricbeats

curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-5.0.1-x86_64.rpm
rpm -vi metricbeat-5.0.1-x86_64.rpm

到此EKB安装结束

 

环境配置

 

elastic的产品都用yaml做的配置,所以配置文件都是目录下的 .yml文件

产品的配置文件分别是

/etc/elasticsearch/elasticsearch.yml

/etc/kibana/kibana.yml

/etc/logstash/logstash.yml

/etc/filebeat/filebeat.yml

/etc/metricbeat/metricbeat.yml

 

下面列出各个组件中需要注意的地方

 

Kibana配置

server.port: 5601

server.host: "localhost" 

elasticsearch.url: "http://localhost:9200"

需要配置ssl的里边有相应项目,自己看吧不列举了

 

Elasticsearch配置

network.host: 192.168.0.1

http.port: 9200

 

Logstash配置

这个本身yml文件需要配置的不多,主要是跟elastic链接的配置

logstash的配置文件目录 /etc/logstash/conf.d/

新建 nb-pipeline.conf

input {
  beats {
    port => 5044
  }
  file {
        path => "/path/to/target/file"
    }
}
 
output {
  elasticsearch {
    hosts => ["http://localhost:9200"]
    index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
    document_type => "%{[@metadata][type]}"
  }
}

input

input可以是beats可以是file,支持multiple的

具体见官网详细介绍吧

https://www.elastic.co/guide/en/logstash/current/input-plugins.html

output

同样支持很多种输出,定义index,不过一般都输出到elasticsearch,不多做介绍,见官网

https://www.elastic.co/guide/en/logstash/current/output-plugins.html

 

Filebeat配置

文件的位置

- input_type: log

# Paths that should be crawled and fetched. Glob based paths.
paths:
- /var/log/*.log

这里有两处output位置,根据需要自己选择

#----------------------------- Logstash output --------------------------------

hosts: ["localhost:5043"]

#-------------------------- Elasticsearch output ------------------------------

hosts: ["localhost:9200"]

 

更多的配置见这里

https://www.elastic.co/guide/en/beats/filebeat/current/configuring-howto-filebeat.html

 

Metricbeat配置

Modules配置

支持很多,默认的是system,还支持mongodb(当前版本有个小问题)

本例采用默认的,其他见官网

https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-modules.html

 

output

同样输出到elasticsearch

output.elasticsearch:
# Array of hosts to connect to.
hosts: ["10.10.6.83:9200"]

 

导入Dashboard

Metric beat内置了几种Dashboard,可以直接导入显示

操作方法

/usr/share/metricbeat/scripts/import_dashboards -es http://localhost:9200

详细参照

https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-sample-dashboards.html

 

TroubleShooting

kibana安装完成后,无法创建索引

默认的索引是logstash-*,并且是按时间检索的

如果logstash直接解析传给elasticsearch的那没有问题,可以创建成功

如果是beat穿过去的,需要自己定义

比如filebeat传过去的,索引要用“filebeat-*”

metricbeat传过去的,索引用“metricbeat-*”

 

 

这里只是简单的介绍,ELK功能很强大,欢迎有兴趣的童鞋深入研究

https://www.elastic.co/guide/index.html

 

 

贴两张图

Filebeat > logstash > E > K

 

Metricbeat > E > K 监控windows进程

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics