- 8.1 安装 metricbeat
- 8.2 连接 Elastic Stack
- —————————————— Elasticsearch Output ——————————————
- Array of hosts to connect to.
- Protocol - either
http(default) orhttps. - protocol: “https”
- Authentication credentials - either API key or username/password.
- api_key: “id:api_key”
- 8.3 启用和配置指标收集模块
- Module: elasticsearch
- https://www.elastic.co/guide/en/beats/metricbeat/8.2/metricbeat-module-elasticsearch.html">Docs: https://www.elastic.co/guide/en/beats/metricbeat/8.2/metricbeat-module-elasticsearch.html
- 8.5 启动 metricbeat
8.1 安装 metricbeat
- 下载 metricbeat
https://www.elastic.co/cn/downloads/beats/metricbeat,下载 zip 版本
解压 zip 包,以管理员身份启动 PowerShell,进入目录,输入以下命令将 metricbeat 注册为 windows 服务
.\install-service-metricbeat.ps1

如果在系统上禁用了脚本执行,则需要为当前会话设置执行策略以允许脚本运行。例如:PowerShell.exe -ExecutionPolicy UnRestricted -File .\install-service-metricbeat.ps1
8.2 连接 Elastic Stack
打开 metricbeat.yml,设置连接 elasticsearch 相关配置,当您首次启动 Elasticsearch 时,默认情况下会启用 Elasticsearch 的网络加密(TLS)等安全功能。如果您使用的是 Elasticsearch 首次启动时生成的自签名证书,则需要在此处添加其指纹。指纹打印在 Elasticsearch 启动日志上。 ```yaml
—————————————— Elasticsearch Output ——————————————
output.elasticsearch:
Array of hosts to connect to.
hosts: [“https://172.18.1.31:1001","https://172.18.1.31:1002","https://172.18.1.31:1003“]
Protocol - either http (default) or https.
protocol: “https”
Authentication credentials - either API key or username/password.
api_key: “id:api_key”
username: “elastic” password: “5_QD9o4D-VZn0dUJDO=c” ssl: enabled: true ca_trusted_fingerprint: “22e8f9824c14c392fe403fe81f4a21790ce1026eebca02bb0a348c4038884483”
2. 设置连接 kibana 相关配置```yaml# =================================== Kibana ===================================# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.# This requires a Kibana endpoint configuration.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]:5601host: "172.18.1.31:5601"username: "elastic"password: "5_QD9o4D-VZn0dUJDO=c"# Kibana Space ID# ID of the Kibana Space into which the dashboards should be loaded. By default,# the Default Space will be used.#space.id:
8.3 启用和配置指标收集模块
确定需要启用的模块。要查看可用模块的列表,请运行:
.\metricbeat.exe modules list
启用 elasticsearch 模块,启动后,目录 modules.d 中的 elasticsearch-xpack.yml 后缀 disable会自行取消,变得可以配置
.\metricbeat.exe modules enable elasticsearch-xpack
修改 elasticsearch-xpack.yml ```yaml
Module: elasticsearch
Docs: https://www.elastic.co/guide/en/beats/metricbeat/8.2/metricbeat-module-elasticsearch.html
module: elasticsearch xpack.enabled: true period: 10s hosts: [“https://172.18.1.31:1001","https://172.18.1.31:1002","https://172.18.1.31:1003“] username: “elastic” password: “5_QD9o4D-VZn0dUJDO=c” ssl: enabled: true ca_trusted_fingerprint: “22e8f9824c14c392fe403fe81f4a21790ce1026eebca02bb0a348c4038884483”
<a name="FqXN5"></a># 8.4 加载索引模板供 Kibana 可视化在 kibana 运行的情况下,从安装目录中,运行:```bash.\metricbeat.exe setup -e
-e 的含义:日志直接命令行输出,而非日志。

执行成功后,会有如上的显示:”kibana dashboards successfully loaded.”。
如果:kibana 或者 elasticsearch 配置出错,都可能导致此步骤不成功。常见的错误包含但不限于:端口配置错误。
- 用户名或者密码错误。
8.5 启动 metricbeat
等上一步执行成功后,再启动 metricbeat
至此,整个 metricbeat 就全部配置完毕,登录 kibana,选择“堆栈监测”,看到所有节点监控均已联机.\metricbeat.exe -e


【注意】
- 以上演示为在集群状态下,一台物理机部署三个节点的情况,如果在多台物理机部署,则需要在每个节点部署一个 metricbeat,分别连接各自对应的节点即可
- 启动成功后,下次可以从 windows 服务启动和关闭 metricbeat
- 默认情况下,Windows 日志文件存储在 C:\ProgramData\metricbeat\Logs 中
