目录




官网手册:​​https://www.elastic.co/guide/en/beats/winlogbeat/7.5/winlogbeat-installation.html​

​回到顶部​

【1】下载安装 winlogbeat

Download Link: ​​https://www.elastic.co/downloads/beats/winlogbeat​

我们可以根据自己的版本(和Elasticsearch一样的版本)来进行下载。(这里我的是7.5.1)

  winlogbeat采集windows系统日志_数据


 如上图,历史版本需要点一下,不然下的默认是最新版本,现在已经是 7.15.2 了

下载后,解压缩内容并将生成的Winlogbeat文件夹放置在系统上您认为合适的任何位置。

比如针对我的设置,我解压到如下的目录:

  winlogbeat采集windows系统日志_elasticsearch_02


​回到顶部​

【2】修改配置文件 winlogbeat.yml


(2.0)总配置查看


#======================= Winlogbeat specific options 
# The supported keys are name (required), tags, fields, fields_under_root,
# forwarded, ignore_older, level, event_id, provider, and include_xml. Please
# visit the documentation for the complete details of each option.
# https://go.es.io/WinlogbeatConfig

winlogbeat.event_logs:
- name: Application
- name: Microsoft-Windows-PowerShell/Operational
- name: Windows PowerShell
- name: Microsoft-Windows-WMI-Activity/Operational
- name: Microsoft-Windows-PowerShell/Admin
ignore_older: 72h

- name: System
ignore_older: 72h

- name: Security
processors:
- script:
lang: javascript
id: security
file: ${path.home}/module/security/config/winlogbeat-security.js

- name: Microsoft-Windows-Sysmon/Operational
processors:
- script:
lang: javascript
id: sysmon
file: ${path.home}/module/sysmon/config/winlogbeat-sysmon.js

#==================== Elasticsearch template settings ==========================

setup.template.settings:
index.number_of_shards: 3
#index.codec: best_compression
#_source.enabled: false


setup.template.enabled: true
setup.template.overwrite: true
setup.template.name: "windows"
setup.template.pattern: "windows-*"
setup.dashboards.index: "windows-*"
setup.ilm.enabled: false

#================================ General =====================================

# The name of the shipper that publishes the network data. It can be used to group
# all the transactions sent by a single shipper in the web interface.
name: "mssql"

# The tags of the shipper are included in their own field with each
# transaction published.
tags: ["192.168.191.80","windows2005 test"]

# Optional fields that you can specify to add additional information to the
# output.
fields:
source: windows

#============================== 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]:5601
host: "115.238.30.132:5601"

#-------------------------- Elasticsearch output ------------------------------
output.elasticsearch:
# Array of hosts to connect to.
hosts: ["115.238.30.132:9200"]

# Configure processors to enhance or manipulate events generated by the beat.

processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
- add_docker_metadata: ~
index: "windows-%{+yyyy.MM.dd}"



(2.1)Winlogbeat specific options 配置实际收集日志模块

  winlogbeat采集windows系统日志_elasticsearch_03


(2.2)Elasticsearch template settings ES模板设置

  winlogbeat采集windows系统日志_数据_04

索引是3个主分片,副本分片随集群定义生成,一般是1个主分片对应一个副本分片啦

 这里我们把新建了一个索引模板叫 windows

setup.template.pattern 为哪些名称的索引会引用该模板


(2.3)General 通用配置(自定义字段)

  winlogbeat采集windows系统日志_elasticsearch_05

 很重要啊,这个我们采集过来的日志是没有描述和IP地址的,到时候就算告警,这也不知道啊;

所以我们这里可以尽情加字段什么的;无论是查阅还是告警就是好用的啊


(2.4)kibana

  winlogbeat采集windows系统日志_数据_06

 kibana 地址


(2.5)Elasticsearch output 输出到ES配置

  winlogbeat采集windows系统日志_elasticsearch_07


 (2.6)【参考】指定数据、日志文件存储目录

logging.to_files: true
logging.files:
path: C:/ProgramData/winlogbeat/Logs
logging.level: info



​回到顶部​

【3】启动


(3.1)初始化、装载模板到kibana

在主机上以管理员身份打开 PowerShell 窗口。 我们想要将必要的 Winlogbeat 模板上载到 Elastic 栈中,以进行正确的解析。

在此窗口中,导航到Winlogbeat 文件夹并运行以下命令:

这个会测试与es、与kibana的连通性与配置是否成功,仔细查看相关信息有没有 error 等字样

# 切换到下载目录
d:
cd D:\dba_tools\software\winlogbeat-7.5.1-windows-x86_64
.\winlogbeat.exe setup -e


(3.2)正式启动

.\winlogbeat.exe -e -c winlogbeat.yml


  winlogbeat采集windows系统日志_javascript_08


会弹出很多信息,毕竟我们 -e 参数就是把信息打印到屏幕上;

初次使用调试的时候很实用


(3.3)通过kibana 查看验证

先在kibana加上我们这个自定义的 mssql-* 的索引模板

  winlogbeat采集windows系统日志_elasticsearch_09


然后点击发现

如下图,我们可以看到一直有数据过来

  winlogbeat采集windows系统日志_elasticsearch_10

索引也有了;如下图:

  但我们发现好像有好几个日期,这是因为保存的文件有好几个

  winlogbeat采集windows系统日志_elasticsearch_11


(3.4)把 winlogbeat 封装成服务启动(额外)

如下图,我们可以看到文件夹里有封装成服务器的PS脚本;

  winlogbeat采集windows系统日志_javascript_12 


如下图,直接执行就安装好了

   winlogbeat采集windows系统日志_javascript_13


我们启动一下:

  winlogbeat采集windows系统日志_javascript_14



怎么知道数据去哪里了呢?日志怎么看呢?

我们看看 这个安装脚本 install-service-filebeat.ps1 的内容,如下图


winlogbeat采集windows系统日志_javascript_15

如上图,同时我们可以看到服务 把数据目录放到 c:\ProgramData\winlogbeat\data  ,日志目录也相差不多; 

这个文件夹是隐藏文件夹 直接看看不到,设置了文件夹选项后才能看到,藏的真深

  winlogbeat采集windows系统日志_elasticsearch_16

  winlogbeat采集windows系统日志_javascript_17


​回到顶部​

【参考文档】


极易上手搭建自己日志采集服务器分析日志(winlogbeat+Elasticsearch+Kibana)​​​

elastic 中国社区:Beats:如何使用 Winlogbea​

​ELK+Beats实现Windows服务器系统日志监控​