使用Metricbeat和Filebeat监控Nginx性能指标和日志
前言
本文描述了通过Metricbeat和Filebeat来分别监控Nginx的性能指标和日志,并将数据存储到Elasticsearch中,再通过Kibana进行可视化数据分析。
前置条件:
-
CentOS7 x86_64
-
Elastic Stack:
- 已以rpm方式安装Elastichsearch 7.4.0
- 已以rpm方式安装Kibana 7.4.0
如果还没有安装Elasticsearch和Kibana,可以参考:
目标机器:
- 已以rpm方式安装Nginx
安装和配置配置Metricbeat
参见:
下载Merticbeat
Metribeat 7.4.0:
Metricbeat 最新版:
下载Metricbeat 7.4.0 rpm和sha512:
# download rpm package
wget https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.4.0-x86_64.rpm
# download sha512
wget https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.4.0-x86_64.rpm.sha512
校验sha512:
sha512sum -c metricbeat-7.4.0-x86_64.rpm.sha512
安装Metricbeat
安装Metricbeat:
rpm -ivh metricbeat-7.4.0-x86_64.rpm
Metricbeat目录
Metricbeat目录:
参见:
配置目录为/etc/metricbeat
:
metricbeat.yml
为Metricbeat主配置文件。modules.d/*.yml
为Meticbeat module配置文件
程序目录为/usr/share/metricbeat
:
bin
目录为可执行文件目录。
数据目录为/var/lib/metricbeat
,日志目录为/var/log/metricbeat
。
配置连接Elasticsearch和Kibana
如果Metricbeat和Elasticsearch和Kibana安装在同一台机器上,则不需要修改配置。
编辑·/etc/metricbeat/metricbeat.yml
,设置Elasticsearch和Kibana的连接。
修改前:
output.elasticsearch:
# Array of hosts to connect to.
hosts: ["localhost:9200"]
# Optional protocol and basic auth credentials.
#protocol: "https"
#username: "elastic"
#password: "changeme"
setup.kibana:
# Kibana Host
# Scheme and port can be left out and will be set to the default (http and 5601)
# In case you specify and additional path, the scheme is required: http://localhost:5601/path
# IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
#host: "localhost:5601"
# Kibana Space ID
# ID of the Ki