filebeat 配置新日志流程記錄文檔

背景:

在網(wǎng)上看過filebeat的很多文檔,可能因為時間原因或者filebeat使用者較少吧,總之不能滿足我的需求,所以記錄下,希望能幫到有需要的人吧.奧力給!

一共分為兩部分 第一部分為基礎(chǔ)說明,第二部分為真實演示流程,第三部分為碰到過的問題收集

一 基礎(chǔ)說明:

1 下載安裝filebeat,可以看之前的記錄
2 默認配置文件為filebeat.reference.yml,正式使用配置文件為filebeat.yml
3 配置文件基礎(chǔ)解讀:

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.
#每收集一個日志,需要配置一個type
- type: log
  enabled: true
  paths:
   - /home/work/dsp/log/webserver/access_log #日志路徑
  fields:
     type: "php-nginx-access" #自定義字段
  close_renamed: true #日志替換名字時,停止采集
  close_removed: true #日志移動時.停止采集
  scan_frequency: 10s #頻率 10s去檢測日志更新
#整塊注釋如上#
- type: log
  enabled: true
  paths:
   - /home/work/dsp/log/service/service.log
  fields:
     type: "service-log"
  close_renamed: true
  close_removed: true
  scan_frequency: 10s
#整塊注釋如上#

#- type: log
#  enabled: true
#  paths:
#   - /home/work/dsp/log/webserver/error_log.2019111217
#  fields:
#     type: "nginx-error"

#============================= Filebeat modules ===============================

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.template.settings:
#  index.number_of_shards: 3
  #index.number_of_replicas: 2
 # index:
  #  number_of_shards: 3
    #    #codec: best_compression
    #        #number_of_routing_shards: 30

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

#============================== Kibana =====================================

# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
# This requires a Kibana endpoint configuration.
setup.kibana:
    host: "10.19.145.2:5601"
    username: "YouName"
    password: "YourPassword"
  # Kibana Host


#-------------------------- Elasticsearch output ------------------------------
setup.ilm.enabled: false

setup.template.name: "php-nginx" # 給咱的模板起個名字,隨便喊
setup.template.pattern: "php-nginx-*" #調(diào)取的正則名稱
setup.template.settings: # 配置生成索引的分片與副本數(shù)
  index.number_of_shards: 3
  index.number_of_replicas: 1

setup.template.overwrite: true
setup.template.enabled: true

setup.template.name: "php-service"
setup.template.pattern: "php-service-*"
setup.template.settings:
  index.number_of_shards: 3
  index.number_of_replicas: 1

setup.template.overwrite: true
setup.template.enabled: true
#es 集群配置
output.elasticsearch:
  hosts: ["ip1:9200", "ip2.15:9200", "ip3:9200"]
  username: "youName"
  password: "YouPassword"
  index: "php-nginx-%{+yyyy.MM.dd}"
  indices:
    - index: "php-nginx-%{+yyyy.MM.dd}"
      when.equals:
        fields.type: "php-nginx-access"
    - index: "php-service-%{+yyyy.MM.dd}"
      when.equals:
        fields.type: "service-log"
  pipelines:
    - pipeline: "php-nginx-access"
      when.equals:
        fields.type: "php-nginx-access"
    - pipeline: "service-log"
      when.equals:
        fields.type: "service-log"
  


processors:
  - add_host_metadata: ~
  - add_cloud_metadata: ~

二 真實演示流程:

完整流程舉例: 添加nginx接入層日志采集
1 在filebeat.yml 添加type

- type: log
  enabled: true
  paths:
   - /home/work/nginx/logs/access_log
  fields:
     type: "nginx-access"
  close_renamed: true
  close_removed: true
  scan_frequency: 10s
  exclude_lines: ['\/static\/img\/', '\/static\/js\/', '\/static\/css\/', '\/static\/fonts\/'] #目的是為了過濾css,js等你想過濾的東西

2 在filebeat.yml 添加template

setup.template.overwrite: true
setup.template.name: "nginx-flow"
setup.template.pattern: "nginx-flow-*"
setup.template.fields: ${path.config}/nginx-template.yml
setup.template.enabled: false

3 構(gòu)建es管道

PUT _ingest/pipeline/nginx-flow
參數(shù)為:
{
  "nginx-access" : {
    "description" : "nginx-flow",
    "processors" : [
      {
        "grok" : {
          "ignore_failure" : true,
          "field" : "message",
          "patterns" : [
            """%{IPV4:remote_addr_ip} - (%{USERNAME:user_name}|-) \[%{HTTPDATE:log_timestamp:date}\] \"(?<method>[A-Z]+) (?<request_uri>[\s\S]*) (?<proto>[A-Za-z]+([A-Za-z0-9+\-./]+)+)\" (?<status>\d+) (?<body_size>\d+) \"(?<refer>(.*?))\" \"(?<cookie>(.*?))\" \"(?<user_agent_info>(.*?)*)\" %{NUMBER:cost_time} %{IPV4:remote_addr} %{IPV4:server_addr} (?<sock_path>[a-z0-9\.]+:(/?[a-z0-9\-]+)+(\.sock)?|-) (?<service_name>[a-z\d\.]+) \"(?<forwarded_foo>(.*?))\" (?<log_id>[\w\-]*) (?<log_id>[\w\-]*) %{NUMBER:time} %{NUMBER:time}"""
          ]
        }
      },
      {
        "date" : {
          "ignore_failure" : true,
          "field" : "log_timestamp",
          "formats" : [
            "dd/MMM/yyyy:HH:mm:ss Z"
          ],
          "timezone" : "Asia/Shanghai"
        }
      }
    ]
  }
}

4 在filebeat.yml 添加索引與es管道配置

output.elasticsearch:
  hosts: ["ip1:9200", "ip2:9200", "ip3:9200"]
  username: "YouName"
  password: "YouPassword"
  index: "php-nginx-%{+yyyy.MM.dd}"
  indices:
    - index: "php-nginx-%{+yyyy.MM.dd}"
      when.equals:
        fields.type: "php-nginx-access"
    - index: "php-service-%{+yyyy.MM.dd}"
      when.equals:
        fields.type: "service-log"
    #在原有配置上的新增行1 start ###
    - index: "nginx-flow-%{+yyyy.MM.dd}"
      when.equals:
        fields.type: "nginx-access"
     #在原有配置上的新增行1 end ###
  pipelines:
    - pipeline: "php-nginx-access"
      when.equals:
        fields.type: "php-nginx-access"
    - pipeline: "service-log"
      when.equals:
        fields.type: "service-log"
      #在原有配置上的新增行2 start ###
    - pipeline: "nginx-access"
      when.equals:
        fields.type: "nginx-access"
    #在原有配置上的新增行2 end ###

5 重啟filebeat服務(wù)

supervisorctl restart filebeat
# 或者
./filebeat -c filebeat.yml  -e -d '*'

三 碰到過的問題:

1 es 集群 cpu負載過高,集群內(nèi)每個節(jié)點的cpu負載都接近100%
解決手段: 1 在es管道配置中新增如下圖1中標紅參數(shù).
2 調(diào)整es的jvm gc參數(shù),如下圖2中

1.png
2.png

2 當采集日志數(shù)量>=2時,filebeat設(shè)置es索引分片與副本數(shù)失敗
解決手段: 采集日志數(shù)量>=2時,es的分片與副本數(shù)量收集需要在不同的模板下分別設(shè)置,否則會使設(shè)置參數(shù)失效.如下圖所示:

3.png

?

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市妻导,隨后出現(xiàn)的幾起案子岂津,更是在濱河造成了極大的恐慌缝呕,老刑警劉巖誓竿,帶你破解...
    沈念sama閱讀 222,627評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件贺辰,死亡現(xiàn)場離奇詭異煎殷,居然都是意外死亡蔼卡,警方通過查閱死者的電腦和手機喊崖,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,180評論 3 399
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來雇逞,“玉大人荤懂,你說我怎么就攤上這事√猎遥” “怎么了节仿?”我有些...
    開封第一講書人閱讀 169,346評論 0 362
  • 文/不壞的土叔 我叫張陵,是天一觀的道長掉蔬。 經(jīng)常有香客問我廊宪,道長,這世上最難降的妖魔是什么女轿? 我笑而不...
    開封第一講書人閱讀 60,097評論 1 300
  • 正文 為了忘掉前任箭启,我火速辦了婚禮,結(jié)果婚禮上蛉迹,老公的妹妹穿的比我還像新娘傅寡。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 69,100評論 6 398
  • 文/花漫 我一把揭開白布赏僧。 她就那樣靜靜地躺著大猛,像睡著了一般扭倾。 火紅的嫁衣襯著肌膚如雪淀零。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,696評論 1 312
  • 那天膛壹,我揣著相機與錄音驾中,去河邊找鬼。 笑死模聋,一個胖子當著我的面吹牛肩民,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播链方,決...
    沈念sama閱讀 41,165評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼持痰,長吁一口氣:“原來是場噩夢啊……” “哼镀虐!你這毒婦竟也來了蝇完?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 40,108評論 0 277
  • 序言:老撾萬榮一對情侶失蹤壁畸,失蹤者是張志新(化名)和其女友劉穎前酿,沒想到半個月后患雏,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,646評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡罢维,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,709評論 3 342
  • 正文 我和宋清朗相戀三年淹仑,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片肺孵。...
    茶點故事閱讀 40,861評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡匀借,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出平窘,到底是詐尸還是另有隱情吓肋,我是刑警寧澤,帶...
    沈念sama閱讀 36,527評論 5 351
  • 正文 年R本政府宣布初婆,位于F島的核電站蓬坡,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏磅叛。R本人自食惡果不足惜屑咳,卻給世界環(huán)境...
    茶點故事閱讀 42,196評論 3 336
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望弊琴。 院中可真熱鬧兆龙,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,698評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至聪铺,卻和暖如春化焕,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背铃剔。 一陣腳步聲響...
    開封第一講書人閱讀 33,804評論 1 274
  • 我被黑心中介騙來泰國打工撒桨, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人键兜。 一個月前我還...
    沈念sama閱讀 49,287評論 3 379
  • 正文 我出身青樓凤类,卻偏偏與公主長得像,于是被迫代替她去往敵國和親普气。 傳聞我的和親對象是個殘疾皇子谜疤,可洞房花燭夜當晚...
    茶點故事閱讀 45,860評論 2 361

推薦閱讀更多精彩內(nèi)容