最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Nginx access 日志通過(guò) Filebeat 8.15.5 寫(xiě)入 Elasticsearch 8 實(shí)戰(zhàn)流程

 更新時(shí)間:2025年12月23日 17:04:27   作者:Energet!c  
本文基于 Filebeat 8.15.5 版本,詳細(xì)實(shí)現(xiàn)了Nginx access日志到ES 8的采集流程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

在日志分析場(chǎng)景中,Nginx訪問(wèn)日志(access.log)包含了豐富的用戶行為、請(qǐng)求性能等關(guān)鍵數(shù)據(jù),將其高效采集并寫(xiě)入Elasticsearch(ES)是實(shí)現(xiàn)日志檢索、分析與可視化的基礎(chǔ)。本文基于Filebeat 8.15.5和ES 8環(huán)境,結(jié)合實(shí)際部署經(jīng)驗(yàn),詳細(xì)拆解從環(huán)境準(zhǔn)備到服務(wù)上線的完整流程,同時(shí)解答部署過(guò)程中常見(jiàn)的坑點(diǎn)與解決方案。

一、環(huán)境說(shuō)明

  • 操作系統(tǒng):Rocky Linux(兼容CentOS、RHEL等主流Linux發(fā)行版)
  • 核心組件版本:Filebeat 8.15.5、Elasticsearch 8.x
  • 日志源:Nginx/OpenResty訪問(wèn)日志(雙路徑:/mnt/data/openresty2/nginx/logs/access.log/mnt/data/openresty/nginx/logs/access.log
  • ES配置:地址 http://1.2.3.4:5678,索引格式 nginx_%{+yyyyMMdd},預(yù)處理管道 pipeline-nginx-plaintext

二、部署步驟與深度解析

步驟1:創(chuàng)建Filebeat工作目錄

cd /mnt/data
mkdir filebeat-es
cd filebeat-es/

解析:?
工作目錄選擇 /mnt/data:通常 /mnt 目錄用于掛載數(shù)據(jù)盤,存儲(chǔ)空間充足,適合存放 Filebeat 安裝包、配置文件及臨時(shí)數(shù)據(jù),避免因系統(tǒng)盤空間不足導(dǎo)致服務(wù)異常,后續(xù)的filebeat日志也在這個(gè)地方存儲(chǔ),以便于排查錯(cuò)誤。?
獨(dú)立目錄 filebeat-es:便于統(tǒng)一管理 Filebeat 相關(guān)文件,后續(xù)遷移、升級(jí)時(shí)更高效,也能與其他應(yīng)用目錄區(qū)分,提升系統(tǒng)整潔度。?

步驟 2:下載并解壓 Filebeat 安裝包?

# 下載filbeat 到/mnt/data/filebeat-es
# 下載地址:https://www.elastic.co/downloads/past-releases/filebeat-8-15-5
tar -zxvf filebeat-8.15.5-linux-x86_64.tar.gz -C ./?
mv filebeat-8.15.5-linux-x86_64 filebeat-es?
cd filebeat-es/?

?解析:?
解壓參數(shù)說(shuō)明:tar -zxvf 中,z 表示解壓 gz 壓縮包,x 表示提取文件,v 顯示解壓過(guò)程,f 指定目標(biāo)文件;-C ./ 表示將文件解壓到當(dāng)前目錄,避免文件混亂。?
重命名目錄:將默認(rèn)的 filebeat-8.15.5-linux-x86_64 改為 filebeat-es,名稱更簡(jiǎn)潔且明確用途(用于對(duì)接 ES),后續(xù)操作更易識(shí)別。?

步驟 3:filebeat.yml 核心配置文件?

vi filebeat.yml?
###################### Filebeat Configuration Example #########################
# This file is an example configuration file highlighting only the most common
# options. The filebeat.reference.yml file from the same directory contains all the
# supported options with more comments. You can use it as a reference.
#
# You can find the full configuration reference here:
# https://www.elastic.co/guide/en/beats/filebeat/index.html
# For more available modules and options, please see the filebeat.reference.yml sample
# configuration file.
#=========================== Filebeat inputs =============================
filebeat.inputs:
# Each - is an input. Most options can be set at the input level, so
# you can use different inputs for various configurations.
# Below are the input specific configurations.
# 這里定義類型是log
- type: log
  # Change to true to enable this input configuration.
  enabled: true
  # Paths that should be crawled and fetched. Glob based paths.
  # 這個(gè)地方是nginx日志的實(shí)際路徑,可以根據(jù)實(shí)際進(jìn)行修改
  paths:
    - /mnt/data/openresty/nginx/logs/access.log
    #- c:\programdata\elasticsearch\logs\*
  # 這個(gè)地方是從末尾開(kāi)始讀取寫(xiě)入ES,通常nginx的日志文件很大 耗費(fèi)CPU資源,歷史的log不再處理
  tail_files: true
  offset:
    initial: end
  # Exclude lines. A list of regular expressions to match. It drops the lines that are
  # matching any regular expression from the list.
  # exclude_lines: ['^127.0.0.1']
  # Include lines. A list of regular expressions to match. It exports the lines that are
  # matching any regular expression from the list.
  #include_lines: ['^ERR', '^WARN']
  # Exclude files. A list of regular expressions to match. Filebeat drops the files that
  # are matching any regular expression from the list. By default, no files are dropped.
  #exclude_files: ['.gz$']
  # Optional additional fields. These fields can be freely picked
  # to add additional information to the crawled log files for filtering
  # 這個(gè)地方是給采集日志添加logtype列,通過(guò)es查詢的時(shí)候可以辨別 類似自定義標(biāo)簽,可以修改
  # 比如某個(gè)主機(jī)上安裝了兩個(gè)用途不同的openresty實(shí)例,或者多個(gè)實(shí)例組成的負(fù)載,用于辨別。
  fields:
    logtype: "mynginx01_openresty"
  #  level: debug
  #  review: 1
  fields_under_root: true
  json.enabled: true
  json.keys_under_root: true
  ### Multiline options
  # Multiline can be used for log messages spanning multiple lines. This is common
  # for Java Stack Traces or C-Line Continuation
  # The regexp Pattern that has to be matched. The example pattern matches all lines starting with [
  # multiline.pattern: ^\[
  # multiline.pattern: '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\s-'
  # Defines if the pattern set under pattern should be negated or not. Default is false.
  # multiline.negate: true
  # Match can be set to "after" or "before". It is used to define if lines should be append to a pattern
  # that was (not) matched before or after or as long as a pattern is not matched based on negate.
  # Note: After is the equivalent to previous and before is the equivalent to to next in Logstash
  # multiline.match: after
#------------------------------------------------------------------------------------------
- type: log
  # Change to true to enable this input configuration.
  enabled: true
  # Paths that should be crawled and fetched. Glob based paths.
  # 這個(gè)地方是我第二個(gè)nginx日志的實(shí)際路徑,可以根據(jù)實(shí)際進(jìn)行修改或者刪除
  paths:
    - /mnt/data/openresty2/nginx/logs/access.log
    #- c:\programdata\elasticsearch\logs\*
  # 參考第一段
  tail_files: true
  offset:
    initial: end
  # Exclude lines. A list of regular expressions to match. It drops the lines that are
  # matching any regular expression from the list.
  # exclude_lines: ['^127.0.0.1']
  # Include lines. A list of regular expressions to match. It exports the lines that are
  # matching any regular expression from the list.
  #include_lines: ['^ERR', '^WARN']
  # Exclude files. A list of regular expressions to match. Filebeat drops the files that
  # are matching any regular expression from the list. By default, no files are dropped.
  #exclude_files: ['.gz$']
  # Optional additional fields. These fields can be freely picked
  # to add additional information to the crawled log files for filtering
  fields:
     logtype: "mynginx01_openresty2"
  #  level: debug
  #  review: 1
  fields_under_root: true
  json.enabled: true
  json.keys_under_root: true
  ### Multiline options
  # Multiline can be used for log messages spanning multiple lines. This is common
  # for Java Stack Traces or C-Line Continuation
  # The regexp Pattern that has to be matched. The example pattern matches all lines starting with [
  # multiline.pattern: ^\[
  # multiline.pattern: '^[0-9]{4}/[0-9]{2}/[0-9]{2}\s[0-9]{2}:[0-9]{2}:[0-9]{2}\s'
  # Defines if the pattern set under pattern should be negated or not. Default is false.
  # multiline.negate: true
  # Match can be set to "after" or "before". It is used to define if lines should be append to a pattern
  # that was (not) matched before or after or as long as a pattern is not matched based on negate.
  # Note: After is the equivalent to previous and before is the equivalent to to next in Logstash
  # multiline.match: after
#============================= Filebeat modules ===============================
filebeat.shutdown_timeout: 5s
filebeat.config.modules:
  # Glob pattern for configuration loading
  path: ${path.config}/modules.d/*.yml
  # Set to true to enable config reloading
  reload.enabled: false
  # Period on which files under path should be checked for changes
  #reload.period: 10s
#==================== Elasticsearch template setting ==========================
setup.ilm.enabled: false
setup.data_streams.enabled: false
setup.template.name: "nginx_template"
setup.template.pattern: "nginx*"
setup.template.priority: 200
setup.template.settings:
index.number_of_shards: 5
  #index.codec: best_compression
  #_source.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:
# The tags of the shipper are included in their own field with each
# transaction published.
#tags: ["service-X", "web-tier"]
# Optional fields that you can specify to add additional information to the
# output.
#fields:
#  env: staging
#============================== Dashboards =====================================
# These settings control loading the sample dashboards to the Kibana index. Loading
# the dashboards is disabled by default and can be enabled either by setting the
# options here or by using the `setup` command.
#setup.dashboards.enabled: false
# The URL from where to download the dashboards archive. By default this URL
# has a value which is computed based on the Beat name and version. For released
# versions, this URL points to the dashboard archive on the artifacts.elastic.co
# website.
#setup.dashboards.url:
#============================== 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: "localhost:5601"
  # 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:
#============================= Elastic Cloud ==================================
# These settings simplify using filebeat with the Elastic Cloud (https://cloud.elastic.co/).
# The cloud.id setting overwrites the `output.elasticsearch.hosts` and
# `setup.kibana.host` options.
# You can find the `cloud.id` in the Elastic Cloud web UI.
#cloud.id:
# The cloud.auth setting overwrites the `output.elasticsearch.username` and
# `output.elasticsearch.password` settings. The format is `<user>:<pass>`.
#cloud.auth:
#================================ Outputs =====================================
# Configure what output to use when sending the data collected by the beat.
#-------------------------- Elasticsearch output ------------------------------
output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["1.2.3.4:5678"]
  data_stream: false
  pipeline: "pipeline-nginx-plaintext"
  index: "nginx_%{+yyyyMMdd}"
  preset: balanced
  # Optional protocol and basic auth credentials.
  #protocol: "https"
  #username: "elastic"
  #password: "changeme"
#----------------------------- Logstash output --------------------------------
#output.logstash:
  # The Logstash hosts
  #hosts: ["localhost:5044"]
  # Optional SSL. By default is off.
  # List of root certificates for HTTPS server verifications
  #ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]
  # Certificate for SSL client authentication
  #ssl.certificate: "/etc/pki/client/cert.pem"
  # Client Certificate Key
  #ssl.key: "/etc/pki/client/cert.key"
#================================ Processors =====================================
#================================ Logging =====================================
logging.level: info
logging.to_files: true
logging.files:
  path: /mnt/data/filebeat-es
  name: filebeat.log
  keepfiles: 3
  permissions: 0644
# Sets log level. The default log level is info.
# Available log levels are: error, warning, info, debug
#logging.level: debug
# At debug level, you can selectively enable logging only for some components.
# To enable all selectors use ["*"]. Examples of other selectors are "beat",
# "publish", "service".
#logging.selectors: ["*"]
#============================== Xpack Monitoring ===============================
# filebeat can export internal metrics to a central Elasticsearch monitoring
# cluster.  This requires xpack monitoring to be enabled in Elasticsearch.  The
# reporting is disabled by default.
# Set to true to enable the monitoring reporter.
#xpack.monitoring.enabled: false
# Uncomment to send the metrics to Elasticsearch. Most settings from the
# Elasticsearch output are accepted here as well. Any setting that is not set is
# automatically inherited from the Elasticsearch output configuration, so if you
# have the Elasticsearch output configured, you can simply uncomment the
# following line.
#xpack.monitoring.elasticsearch:
#================================= Migration ==================================
# This allows to enable 6.7 migration aliases
#migration.6_to_7.enabled: true

?以下是逐段詳細(xì)解釋:

輸入配置 (filebeat.inputs)

這部分定義了數(shù)據(jù)源。你配置了兩個(gè)獨(dú)立的輸入塊(inputs),分別對(duì)應(yīng)兩個(gè)不同的 Nginx 實(shí)例(openresty 和 openresty2)。?

- type: log
  enabled: true
  paths:
    - /mnt/data/openresty/nginx/logs/access.log
  # --------------------------------------------------------
  # ?? 性能優(yōu)化核心配置:解決 CPU 飆升問(wèn)題
  # --------------------------------------------------------
  tail_files: true       # 啟動(dòng)時(shí)忽略文件中的舊數(shù)據(jù),只看新產(chǎn)生的數(shù)據(jù)
  offset:
    initial: end         # 配合 tail_files,明確指定偏移量從文件末尾開(kāi)始
  # --------------------------------------------------------
  # ??? 標(biāo)簽與分類:區(qū)分不同業(yè)務(wù)來(lái)源
  # --------------------------------------------------------
  fields:
    logtype: "mynginx01_openresty" # 給該日志打上特定標(biāo)簽,用于后續(xù)生成索引名
  fields_under_root: true           # 將 logtype 字段放在根節(jié)點(diǎn),而不是 fields.logtype
  # --------------------------------------------------------
  # ?? JSON 解析:在 Agent 端直接解析
  # --------------------------------------------------------
  json.enabled: true         # 開(kāi)啟 JSON 解析
  json.keys_under_root: true # 解析后的字段(如 status, uri)直接放在根節(jié)點(diǎn)
  • 雙輸入設(shè)計(jì):監(jiān)控了兩個(gè)路徑。通過(guò) fields.logtype 字段進(jìn)行區(qū)分。
  • tail_files & offset:這是你解決 “大文件導(dǎo)致 CPU 高” 的關(guān)鍵設(shè)置。它告訴 Filebeat:“不要管以前那數(shù)據(jù),只盯著文件尾部,有新行才發(fā)”。
  • json.keys_under_root: true:這非常重要。它意味著 Filebeat 發(fā)給 ES 的數(shù)據(jù)已經(jīng)是結(jié)構(gòu)化的(例如 {“status”: 200, “clientip”: “…”}),而不是包含一整行 JSON 字符串的 message 字段。

模板與兼容性設(shè)置 (setup.template & setup.ilm)

這部分是為了讓 Filebeat 兼容 Elasticsearch 8.x,并允許你使用自定義的索引名稱。

# ==================== Elasticsearch template setting ==========================
setup.ilm.enabled: false          # 禁用索引生命周期管理 (ILM)
setup.data_streams.enabled: false # 禁用數(shù)據(jù)流 (Data Streams)
# 定義模板
setup.template.name: "nginx_template"   # 模板名稱
setup.template.pattern: "nginx*"        # 模板匹配的索引模式
setup.template.priority: 200            # 優(yōu)先級(jí) 200 (默認(rèn)是 150),確保你的模板覆蓋系統(tǒng)默認(rèn)模板
setup.template.settings:
  index.number_of_shards: 5             # 強(qiáng)制設(shè)置每個(gè)索引有 5 個(gè)主分片
  • 什么要禁用 ILM 和 Data Streams?

在 ES 8 中,默認(rèn)強(qiáng)制使用 Data Streams(索引名類似 .ds-logs-nginx-…)。

為了使用你自定義的索引名 nginx_%{+yyyyMMdd},必須顯式禁用這兩個(gè)功能。

  • 優(yōu)先級(jí) 200:非常關(guān)鍵。這防止了 Filebeat 自身的默認(rèn)模板覆蓋你的設(shè)置,確保分片數(shù)設(shè)置為 5 生效。

輸出配置 (output.elasticsearch)

定義數(shù)據(jù)發(fā)送到哪里以及如何命名。

output.elasticsearch:
  hosts: ["1.2.3.4:5678"]
  data_stream: false               # 再次確認(rèn)禁用數(shù)據(jù)流輸出
  # ?? 關(guān)鍵點(diǎn):Ingest Pipeline
  pipeline: "pipeline-nginx-plaintext" 
  # 索引命名規(guī)則
  index: "nginx_%{+yyyyMMdd}"      # 按天生成索引,例如 nginx_20251217
  preset: balanced                 # 性能預(yù)設(shè),平衡吞吐量和資源消耗
  • index:這里你設(shè)置了 nginx_%{+yyyyMMdd}。
  • 注意:你之前的配置使用了 %{[logtype]} 變量(如 nginx_public_…),但在這個(gè)配置中去掉了 logtype。這意味著兩個(gè) Nginx 實(shí)例的日志會(huì)寫(xiě)入同一個(gè)索引 nginx_20251217 中。如果這是有意為之的(為了減少分片數(shù)量),那是沒(méi)問(wèn)題的;如果想分開(kāi),需要改回 nginx_%{[logtype]}_%{+yyyyMMdd}
  • pipeline: 這里指定了 pipeline-nginx-plaintext。
  • 潛在沖突提醒:你的 Input 已經(jīng)開(kāi)啟了 JSON 解析,但 Pipeline 名字叫 “plaintext”(純文本)。通常 plaintext pipeline 用 Grok 解析原始文本。如果 Filebeat 發(fā)送的是已經(jīng)解析好的 JSON 字段,而 Pipeline 還在嘗試解析 message 文本,可能會(huì)報(bào)錯(cuò)或失效。

日志配置 (logging)

定義 Filebeat 自身的運(yùn)行日志(用于排查 Filebeat 報(bào)錯(cuò))。

logging.level: info
logging.to_files: true
logging.files:
  path: /mnt/data/filebeat-es  # 日志存放路徑
  name: filebeat.log
  keepfiles: 3                 # 只保留最近 3 個(gè)文件,防止占滿磁盤
  permissions: 0644

這份配置非常成熟,適合生產(chǎn)環(huán)境。它解決了大文件讀取、多實(shí)例區(qū)分和 ES 8 兼容性問(wèn)題。

步驟 4:校驗(yàn)配置文件語(yǔ)法與 ES 連接?

./filebeat test config -c filebeat.yml
./filebeat test output -c filebeat.yml

?
解析:?

  • 語(yǔ)法校驗(yàn) test config:檢查 filebeat.yml 是否存在縮進(jìn)錯(cuò)誤、字段拼寫(xiě)錯(cuò)誤等語(yǔ)法問(wèn)題。輸出 Config OK 表示語(yǔ)法無(wú)錯(cuò);若報(bào)錯(cuò),需根據(jù)提示修正(如 type mismatch 通常是字段格式錯(cuò)誤)。?
  • 輸出連接測(cè)試 test output:驗(yàn)證 Filebeat 能否正常連接 ES。成功會(huì)顯示 ES 版本、連接狀態(tài)等信息;若報(bào)錯(cuò) connection refused,需檢查 ES 地址 / 端口是否正確、防火墻是否放行 12200 端口。?
?輸出說(shuō)明:
? 連接正常:輸出類似以下內(nèi)容(顯示 ES 版本、連接成功):
elasticsearch: http://1.2.3.4:5678...
  parse url... OK
  connection...
    parse host... OK
    dns lookup... OK
    addresses: 1.2.3.4
    dial up... OK
  TLS... WARN secure connection disabled
  talk to server... OK
  version: 8.15.5 

步驟 5:遷移 Filebeat 到系統(tǒng)標(biāo)準(zhǔn)目錄?

cd ..
mv filebeat-es /usr/local/

解析:?
遷移到 /usr/local/:Linux 系統(tǒng)中,/usr/local 是默認(rèn)的第三方應(yīng)用安裝目錄,符合系統(tǒng)目錄規(guī)范,便于后續(xù)管理(如統(tǒng)一升級(jí)、權(quán)限控制)。?
注意:遷移后需確保目錄權(quán)限正確,后續(xù)啟動(dòng)服務(wù)時(shí)避免權(quán)限不足問(wèn)題。?

步驟 6:創(chuàng)建 Systemd 服務(wù)

vi /usr/lib/systemd/system/filebeat-es.service

服務(wù)文件內(nèi)容:?

[Unit]
Description=Filebeat sends log data to Elasticsearch
Documentation=https://www.elastic.co/docs/beats/filebeat
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/filebeat-es/filebeat -c /usr/local/filebeat-es/filebeat.yml
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
RestartSec=5
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target

?解析:?
Systemd 服務(wù)優(yōu)勢(shì):相比傳統(tǒng)的 init.d 腳本,Systemd 支持開(kāi)機(jī)自啟、狀態(tài)管理、日志聚合等功能,更適合生產(chǎn)環(huán)境的服務(wù)管理。?
關(guān)鍵配置說(shuō)明:After=network-online.target 確保服務(wù)在網(wǎng)絡(luò)完全就緒后啟動(dòng),避免因 ES 未訪問(wèn)導(dǎo)致啟動(dòng)失??;Restart=always 提高服務(wù)可用性,異常退出后自動(dòng)恢復(fù);LimitNOFILE=65535 解決 Filebeat 處理大量日志時(shí)的文件句柄限制問(wèn)題。?

步驟 7:?jiǎn)?dòng)服務(wù)并設(shè)置開(kāi)機(jī)自啟?

systemctl daemon-reload 
systemctl start filebeat-es
systemctl status filebeat-es
systemctl enable filebeat-es

?解析:?
daemon-reload:重新加載 Systemd 配置,讓新創(chuàng)建的 filebeat-es.service 生效,修改服務(wù)文件后必須執(zhí)行此命令。?
start 與 status:?jiǎn)?dòng)服務(wù)后,通過(guò) status 查看運(yùn)行狀態(tài)。若顯示 active (running) 表示啟動(dòng)成功;若失敗,可通過(guò) journalctl -u filebeat-es -f 查看詳細(xì)錯(cuò)誤日志。?
enable:設(shè)置開(kāi)機(jī)自啟,避免服務(wù)器重啟后需手動(dòng)啟動(dòng)服務(wù),確保日志采集不中斷。?

三、常見(jiàn)問(wèn)題與解決方案?

配置校驗(yàn)報(bào)錯(cuò) type mismatch accessing 'filebeat.inputs.0.file_identity’?

原因:file_identity 是對(duì)象類型,錯(cuò)誤配置為字符串(如 file_identity: path)。?
解決方案:刪除該錯(cuò)誤配置(默認(rèn)按路徑標(biāo)識(shí)文件,無(wú)需顯式聲明),或改為正確對(duì)象格式:?

file_identity:
  path: ~

ES 寫(xiě)入失敗 no matching index template found?

原因:Filebeat 配置的模板未在 ES 中創(chuàng)建。?
解決方案:通過(guò) Filebeat 自動(dòng)推送模板:?

?/usr/local/filebeat-es/filebeat setup --index-management -c /usr/local/filebeat-es/filebeat.yml

或手動(dòng)通過(guò) ES API 創(chuàng)建:?

?curl -X PUT "http://1.2.3.4:5678/_template/nginx_template" -H "Content-Type: application/json" -d '{
  "index_patterns": ["nginx_*"],
  "settings": {"index.number_of_shards":1,"index.number_of_replicas":0},
  "mappings": {"dynamic": true}
}'

首次啟動(dòng) CPU 飆升?

原因:Filebeat 全量掃描大日志文件(如 8GB + 的 access.log)。?
解決方案:確保配置中包含 offset.initial: end,并清理注冊(cè)表文件:?

?rm -rf /usr/local/filebeat-es/data/registry/filebeat/filestream/*
systemctl restart filebeat-es

?4. 日志采集成功但 ES 中無(wú)數(shù)據(jù)?
原因:ES 預(yù)處理管道 pipeline-nginx-plaintext 不存在或配置錯(cuò)誤。?
解決方案:創(chuàng)建基礎(chǔ)管道測(cè)試:?

?curl -X PUT "http://1.2.3.4:5678/_ingest/pipeline/pipeline-nginx-plaintext" -H "Content-Type: application/json" -d '{
  "description": "Nginx日志解析管道",
  "processors": [
    {"grok": {"field": "message", "patterns": ["%{HTTPDATE:time_local_str}"]}},
    {"date": {"field": "time_local_str", "target_field": "time_local", "formats": ["dd/MMM/yyyy:HH:mm:ss Z"]}}
  ]
}'

四、總結(jié)?

本文基于 Filebeat 8.15.5 版本,詳細(xì)實(shí)現(xiàn)了 Nginx access 日志到 ES 8 的采集流程,核心亮點(diǎn)包括:

  • 優(yōu)化大日志文件采集:通過(guò) offset.initial: end 避免 CPU 飆升;
  • 規(guī)范配置與服務(wù)管理:采用 Systemd 實(shí)現(xiàn)開(kāi)機(jī)自啟,確保服務(wù)穩(wěn)定性;
  • 避坑指南:針對(duì)模板匹配、管道配置、權(quán)限等常見(jiàn)問(wèn)題提供解決方案。
  • 通過(guò)這套流程,可實(shí)現(xiàn) Nginx 日志的高效、穩(wěn)定采集,為后續(xù)的日志分析、可視化(如 Kibana 儀表盤)奠定基礎(chǔ)。如需擴(kuò)展,可進(jìn)一步配置日志過(guò)濾、字段加工、ES 索引生命周期管理等功能。

到此這篇關(guān)于Nginx access 日志通過(guò) Filebeat 8.15.5 寫(xiě)入 Elasticsearch 8 實(shí)戰(zhàn)流程的文章就介紹到這了,更多相關(guān)nginx access日志到ES 8內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Nginx如何代理本地文件

    Nginx如何代理本地文件

    這篇文章主要介紹了Nginx如何代理本地文件問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-03-03
  • 詳解Nginx服務(wù)器的配置中開(kāi)啟文件Gzip壓縮的方法

    詳解Nginx服務(wù)器的配置中開(kāi)啟文件Gzip壓縮的方法

    這篇文章主要介紹了Nginx服務(wù)器的配置中開(kāi)啟文件Gzip壓縮的方法,可以對(duì)CSS和JavaScript以及各種圖片等web傳輸?shù)奈募M(jìn)行壓縮,需要的朋友可以參考下
    2016-01-01
  • Nginx部署SpringBoot項(xiàng)目的實(shí)現(xiàn)

    Nginx部署SpringBoot項(xiàng)目的實(shí)現(xiàn)

    本文主要介紹了Nginx部署SpringBoot項(xiàng)目的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • Nginx部署vue項(xiàng)目和配置代理的問(wèn)題解析

    Nginx部署vue項(xiàng)目和配置代理的問(wèn)題解析

    這篇文章主要介紹了Nginx部署vue項(xiàng)目和配置代理,需本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,要的朋友可以參考下
    2021-08-08
  • nginx負(fù)載均衡下的webshell上傳的實(shí)現(xiàn)

    nginx負(fù)載均衡下的webshell上傳的實(shí)現(xiàn)

    本文主要介紹了nginx負(fù)載均衡下的webshell上傳的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • OpenResty是什么,OpenResty和Nginx的區(qū)別?

    OpenResty是什么,OpenResty和Nginx的區(qū)別?

    Nginx作為一款輕量級(jí)、高性能的Web服務(wù)器,傳統(tǒng)局限性也很明顯:靜態(tài)配置、邏輯擴(kuò)展依賴C模塊開(kāi)發(fā),使得它在需要?jiǎng)討B(tài)業(yè)務(wù)邏輯的場(chǎng)景中顯得捉襟見(jiàn)肘,<BR>而OpenResty的出現(xiàn),打破了這一僵局,它通過(guò)將Lua腳本深度集成到Nginx中,將“靜態(tài)代理服務(wù)器”升級(jí)為“動(dòng)態(tài)應(yīng)用平臺(tái)”
    2025-04-04
  • 寶塔+Nginx多站點(diǎn)配置指南實(shí)踐

    寶塔+Nginx多站點(diǎn)配置指南實(shí)踐

    本文深入解析了在寶塔面板下利用Nginx的include語(yǔ)句實(shí)現(xiàn)多站點(diǎn)模塊化配置的實(shí)戰(zhàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2026-03-03
  • nginx轉(zhuǎn)發(fā)內(nèi)網(wǎng)圖片的代碼示例

    nginx轉(zhuǎn)發(fā)內(nèi)網(wǎng)圖片的代碼示例

    這篇文章主要給大家介紹了nginx轉(zhuǎn)發(fā)內(nèi)網(wǎng)圖片,文章通過(guò)代碼示例介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,感興趣的小伙伴可以自己動(dòng)手試一下
    2023-10-10
  • 使用goaccess分析nginx日志的詳細(xì)方法

    使用goaccess分析nginx日志的詳細(xì)方法

    goaccess 工具提供快速、多樣的HTTP狀態(tài)統(tǒng)計(jì),可以令管理員不再糾結(jié)于統(tǒng)計(jì)各類數(shù)據(jù),和繁雜的指令以及一大堆管道/正則表達(dá)式說(shuō)再見(jiàn),今天通過(guò)本文給大家介紹goaccess 分析nginx 日志的方法,需要的朋友一起看看吧
    2021-07-07
  • 在Nginx用htpasswd對(duì)網(wǎng)站進(jìn)行密碼保護(hù)的設(shè)置方法

    在Nginx用htpasswd對(duì)網(wǎng)站進(jìn)行密碼保護(hù)的設(shè)置方法

    很多時(shí)候我們需要對(duì)一些網(wǎng)站進(jìn)行密碼保護(hù),比如團(tuán)隊(duì)內(nèi)部的站點(diǎn)、demo站點(diǎn)等等。這里所說(shuō)的密碼保護(hù)是服務(wù)器級(jí)的,并非網(wǎng)站應(yīng)用層的注冊(cè)登錄那一套,而是利用服務(wù)器配置和htpasswd文件來(lái)實(shí)現(xiàn)訪問(wèn)的密碼驗(yàn)證
    2013-06-06

最新評(píng)論

广饶县| 叶城县| 镇宁| 兴国县| 桐梓县| 通渭县| 喜德县| 肥城市| 沂源县| 巴林右旗| 衡南县| 博兴县| 郎溪县| 东台市| 赤峰市| 嵩明县| 慈利县| 松溪县| 扎兰屯市| 阿坝县| 大丰市| 纳雍县| 休宁县| 元江| 安仁县| 滦平县| 乳山市| 阿克陶县| 波密县| 宿迁市| 海晏县| 南城县| 枣强县| 上栗县| 镇康县| 井陉县| 鹤壁市| 九寨沟县| 辽宁省| 岳西县| 黄平县|