8.1 安装 metricbeat

  1. 下载 metricbeat

https://www.elastic.co/cn/downloads/beats/metricbeat,下载 zip 版本
image.png

  1. 解压 zip 包,以管理员身份启动 PowerShell,进入目录,输入以下命令将 metricbeat 注册为 windows 服务

    1. .\install-service-metricbeat.ps1

    image.png

    如果在系统上禁用了脚本执行,则需要为当前会话设置执行策略以允许脚本运行。例如:

    1. PowerShell.exe -ExecutionPolicy UnRestricted -File .\install-service-metricbeat.ps1

    8.2 连接 Elastic Stack

  2. 打开 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”

  1. 2. 设置连接 kibana 相关配置
  2. ```yaml
  3. # =================================== Kibana ===================================
  4. # Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
  5. # This requires a Kibana endpoint configuration.
  6. setup.kibana:
  7. # Kibana Host
  8. # Scheme and port can be left out and will be set to the default (http and 5601)
  9. # In case you specify and additional path, the scheme is required: http://localhost:5601/path
  10. # IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
  11. host: "172.18.1.31:5601"
  12. username: "elastic"
  13. password: "5_QD9o4D-VZn0dUJDO=c"
  14. # Kibana Space ID
  15. # ID of the Kibana Space into which the dashboards should be loaded. By default,
  16. # the Default Space will be used.
  17. #space.id:

8.3 启用和配置指标收集模块

  1. 确定需要启用的模块。要查看可用模块的列表,请运行:

    1. .\metricbeat.exe modules list
  2. 启用 elasticsearch 模块,启动后,目录 modules.d 中的 elasticsearch-xpack.yml 后缀 disable会自行取消,变得可以配置

    1. .\metricbeat.exe modules enable elasticsearch-xpack
  3. 修改 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”

    1. <a name="FqXN5"></a>
    2. # 8.4 加载索引模板供 Kibana 可视化
    3. 在 kibana 运行的情况下,从安装目录中,运行:
    4. ```bash
    5. .\metricbeat.exe setup -e

    -e 的含义:日志直接命令行输出,而非日志。
    image.png
    执行成功后,会有如上的显示:”kibana dashboards successfully loaded.”。
    如果:kibana 或者 elasticsearch 配置出错,都可能导致此步骤不成功。常见的错误包含但不限于:

  • 端口配置错误。

  • 用户名或者密码错误。

    8.5 启动 metricbeat

    等上一步执行成功后,再启动 metricbeat
    1. .\metricbeat.exe -e
    至此,整个 metricbeat 就全部配置完毕,登录 kibana,选择“堆栈监测”,看到所有节点监控均已联机
    image.png
    image.png
    【注意】
  1. 以上演示为在集群状态下,一台物理机部署三个节点的情况,如果在多台物理机部署,则需要在每个节点部署一个 metricbeat,分别连接各自对应的节点即可
  2. 启动成功后,下次可以从 windows 服务启动和关闭 metricbeat
  3. 默认情况下,Windows 日志文件存储在 C:\ProgramData\metricbeat\Logs 中