开发排查系统问题用得最多的手段就是查看系统日志,ELK
是 Elastic
公司开源的实时日志处理与分析解决方案,已经为日志处理方案的主流选择。json
而在生产环境中,如何针对 ELK
进行监控,保证各个组件正常运行?如何知道目前的资源是否能承受线上的压力呢?本文主要是以 Elastic Stack 7.x
版本为例,介绍如何监控 ELK
自身的各个组件。vim
常见的 Elastic Stack
日志系统架构以下服务器
其中可以使用 Metricbeat
组件做为轻量级监视代理,经过HTTP端点收集各个组件的监控信息,并把监控数据落盘到 Elasticsearch
中,最终经过 Kibana
以图形化的方式展现各类监控数据。架构
建议在每台服务器上都运行 Metricbeat
收集指标,多个Metricbeat实例的指标将在 Elasticsearch
服务器上合并。app
下载对应版本的 Metricbeat
地址以下:ssh
https://www.elastic.co/cn/dow...elasticsearch
在 Metricbeat
中启用并配置 Elasticsearch x-pack
模块
从安装目录中,运行:spa
./metricbeat modules enable elasticsearch-xpack
默认状况下,模块从 http://localhost:9200 收集 Elasticsearch 指标。若是本地服务器有不一样的地址,请在 modules.d/elasticsearch-xpack.yml 中将其添加到主机设置。代理
在 Metricbeat
中启用并配置 Kibana x-pack
模块日志
./metricbeat modules enable kibana-xpack
该模块将默认从 http://localhost:5601 收集 Kibana 监测指标。若是本地 Kibana 实例有不一样的地址,则必须经过 modules.d/kibana-xpack.yml 文件中的 hosts 设置进行指定。
在 Metricbeat
中启用并配置 Logstash x-pack
模块
./metricbeat modules enable logstash-xpack
该模块将默认从 http://localhost:9600 收集 Logstash 监测指标。若是本地 Logstash 实例有不一样的地址,则必须经过 modules.d/logstash-xpack.yml 文件中的 hosts 设置进行指定。
全部类型的
Beats
配置都同样
须要开启 Beats
本身的HTTP端点输出监控数据,例如 Filebeat
修改 filebeat.yml
文件,在最后添加如下配置
http: enabled: true host: 0.0.0.0 port: 5066
在 Metricbeat
中启用并配置 Beat x-pack
模块
./metricbeat modules enable beat-xpack
该模块将默认从 http://localhost:5066 收集 beat 监测指标。若是正在监测的 beat 实例有不一样的地址,则必须经过 modules.d/beat-xpack.yml 文件中的 hosts 设置进行指定。
配置 Metricbeat
以发送至监测集群,在 metricbeat.yml
文件中修改如下内容
output.elasticsearch: hosts: ["http://localhost:9200"] ## Monitoring cluster # Optional protocol and basic auth credentials. #protocol: "https" #username: "elastic" #password: "changeme"
PS:地址、用户名和密码按实际状况修改
./metricbeat -e
使用 Filebeat
收集 Elasticsearch
自身的日志数据。
首先须要在 Elasticsearch
所在的服务器中安装 Filebeat
组件。
在 Filebeat
中启用并配置 Elasticsearch
模块,执行如下命令
./filebeat modules enable elasticsearch
修改es模块的配置信息,指定日志路径
vim modules.d/elasticsearch.yml
修改成如下内容
- module: elasticsearch server: enabled: true var.paths: - /app/elk/elasticsearch/logs/*_server.json gc: enabled: true var.paths: - /app/elk/elasticsearch/logs/gc.log.[0-9]* - /app/elk/elasticsearch/logs/gc.log audit: enabled: true var.paths: - /app/elk/elasticsearch/logs/*_audit.json slowlog: enabled: true var.paths: - /app/elk/elasticsearch/logs/*_index_search_slowlog.json - /app/elk/elasticsearch/logs/*_index_indexing_slowlog.json deprecation: enabled: true var.paths: - /app/elk/elasticsearch/logs/*_deprecation.json
PS:日志路径按实际状况修改
修改 filebeat.yml
文件,配置es相关信息
output.elasticsearch: hosts: ["localhost:9200"] # Optional protocol and basic auth credentials. #protocol: "https" #username: "elastic" #password: "changeme"
PS:地址、用户名和密码按实际状况修改
./filebeat -c filebeat.yml -e
进入 Kibana
的控制台界面,进入 堆栈监测
菜单
便可查看各个组件的监控信息
扫码关注有惊喜!