自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

一篇文章教你搞懂日志采集利器Filebeat

運(yùn)維 系統(tǒng)運(yùn)維
本文使用的Filebeat是7.7.0的版本,文章將從如下幾個(gè)方面說明。一起來看一下吧。

 本文使用的Filebeat是7.7.0的版本,文章將從如下幾個(gè)方面說明:

    Filebeat是什么,可以用來干嘛

    Filebeat的原理是怎樣的,怎么構(gòu)成的

    Filebeat應(yīng)該怎么玩

Filebeat是什么

Filebeat和Beats的關(guān)系

首先Filebeat是Beats中的一員。

Beats在是一個(gè)輕量級(jí)日志采集器,其實(shí)Beats家族有6個(gè)成員,早期的ELK架構(gòu)中使用Logstash收集、解析日志,但是Logstash對(duì)內(nèi)存、CPU、io等資源消耗比較高。相比Logstash,Beats所占系統(tǒng)的CPU和內(nèi)存幾乎可以忽略不計(jì)。

目前Beats包含六種工具:

  •  Packetbeat:網(wǎng)絡(luò)數(shù)據(jù)(收集網(wǎng)絡(luò)流量數(shù)據(jù))
  •  Metricbeat:指標(biāo)(收集系統(tǒng)、進(jìn)程和文件系統(tǒng)級(jí)別的CPU和內(nèi)存使用情況等數(shù)據(jù))
  •  Filebeat:日志文件(收集文件數(shù)據(jù))
  •  Winlogbeat:Windows事件日志(收集Windows事件日志數(shù)據(jù))
  •  Auditbeat:審計(jì)數(shù)據(jù)(收集審計(jì)日志)
  •  Heartbeat:運(yùn)行時(shí)間監(jiān)控(收集系統(tǒng)運(yùn)行時(shí)的數(shù)據(jù))

Filebeat是什么

Filebeat是用于轉(zhuǎn)發(fā)和集中日志數(shù)據(jù)的輕量級(jí)傳送工具。Filebeat監(jiān)視您指定的日志文件或位置,收集日志事件,并將它們轉(zhuǎn)發(fā)到Elasticsearch或 Logstash進(jìn)行索引。

Filebeat的工作方式如下:?jiǎn)?dòng)Filebeat時(shí),它將啟動(dòng)一個(gè)或多個(gè)輸入,這些輸入將在為日志數(shù)據(jù)指定的位置中查找。對(duì)于Filebeat所找到的每個(gè)日志,F(xiàn)ilebeat都會(huì)啟動(dòng)收集器。每個(gè)收集器都讀取單個(gè)日志以獲取新內(nèi)容,并將新日志數(shù)據(jù)發(fā)送到libbeat,libbeat將聚集事件,并將聚集的數(shù)據(jù)發(fā)送到為Filebeat配置的輸出。

工作的流程圖如下:

Filebeat和Logstash的關(guān)系

因?yàn)長(zhǎng)ogstash是JVM跑的,資源消耗比較大,所以后來作者又用Golang寫了一個(gè)功能較少但是資源消耗也小的輕量級(jí)的logstash-forwarder。不過作者只是一個(gè)人,加入http://elastic.co公司以后,因?yàn)镋S公司本身還收購(gòu)了另一個(gè)開源項(xiàng)目Packetbeat,而這個(gè)項(xiàng)目專門就是用Golang的,有整個(gè)團(tuán)隊(duì),所以ES公司干脆把logstash-forwarder的開發(fā)工作也合并到同一個(gè)Golang團(tuán)隊(duì)來搞,于是新的項(xiàng)目就叫Filebeat了。

Filebeat原理是什么

Filebeat的構(gòu)成

Filebeat結(jié)構(gòu):由兩個(gè)組件構(gòu)成,分別是inputs(輸入)和harvesters(收集器),這些組件一起工作來跟蹤文件并將事件數(shù)據(jù)發(fā)送到您指定的輸出,harvester負(fù)責(zé)讀取單個(gè)文件的內(nèi)容。harvester逐行讀取每個(gè)文件,并將內(nèi)容發(fā)送到輸出。為每個(gè)文件啟動(dòng)一個(gè)harvester。harvester負(fù)責(zé)打開和關(guān)閉文件,這意味著文件描述符在harvester運(yùn)行時(shí)保持打開狀態(tài)。如果在收集文件時(shí)刪除或重命名文件,F(xiàn)ilebeat將繼續(xù)讀取該文件。這樣做的副作用是,磁盤上的空間一直保留到harvester關(guān)閉。默認(rèn)情況下,F(xiàn)ilebeat保持文件打開,直到達(dá)到close_inactive。

關(guān)閉harvester可以會(huì)產(chǎn)生的結(jié)果:

  •  文件處理程序關(guān)閉,如果harvester仍在讀取文件時(shí)被刪除,則釋放底層資源。
  •  只有在scan_frequency結(jié)束之后,才會(huì)再次啟動(dòng)文件的收集。
  •  如果該文件在harvester關(guān)閉時(shí)被移動(dòng)或刪除,該文件的收集將不會(huì)繼續(xù)。

一個(gè)input負(fù)責(zé)管理harvesters和尋找所有來源讀取。如果input類型是log,則input將查找驅(qū)動(dòng)器上與定義的路徑匹配的所有文件,并為每個(gè)文件啟動(dòng)一個(gè)harvester。每個(gè)input在它自己的Go進(jìn)程中運(yùn)行,F(xiàn)ilebeat當(dāng)前支持多種輸入類型。每個(gè)輸入類型可以定義多次。日志輸入檢查每個(gè)文件,以查看是否需要啟動(dòng)harvester、是否已經(jīng)在運(yùn)行harvester或是否可以忽略該文件。

Filebeat如何保存文件的狀態(tài)

Filebeat保留每個(gè)文件的狀態(tài),并經(jīng)常將狀態(tài)刷新到磁盤中的注冊(cè)表文件中。該狀態(tài)用于記住harvester讀取的最后一個(gè)偏移量,并確保發(fā)送所有日志行。如果無法訪問輸出(如Elasticsearch或Logstash),F(xiàn)ilebeat將跟蹤最后發(fā)送的行,并在輸出再次可用時(shí)繼續(xù)讀取文件。當(dāng)Filebeat運(yùn)行時(shí),每個(gè)輸入的狀態(tài)信息也保存在內(nèi)存中。當(dāng)Filebeat重新啟動(dòng)時(shí),來自注冊(cè)表文件的數(shù)據(jù)用于重建狀態(tài),F(xiàn)ilebeat在最后一個(gè)已知位置繼續(xù)每個(gè)harvester。對(duì)于每個(gè)輸入,F(xiàn)ilebeat都會(huì)保留它找到的每個(gè)文件的狀態(tài)。由于文件可以重命名或移動(dòng),文件名和路徑不足以標(biāo)識(shí)文件。對(duì)于每個(gè)文件,F(xiàn)ilebeat存儲(chǔ)唯一的標(biāo)識(shí)符,以檢測(cè)文件是否以前被捕獲。

Filebeat何如保證至少一次數(shù)據(jù)消費(fèi)

Filebeat保證事件將至少傳遞到配置的輸出一次,并且不會(huì)丟失數(shù)據(jù)。是因?yàn)樗鼘⒚總€(gè)事件的傳遞狀態(tài)存儲(chǔ)在注冊(cè)表文件中。在已定義的輸出被阻止且未確認(rèn)所有事件的情況下,F(xiàn)ilebeat將繼續(xù)嘗試發(fā)送事件,直到輸出確認(rèn)已接收到事件為止。如果Filebeat在發(fā)送事件的過程中關(guān)閉,它不會(huì)等待輸出確認(rèn)所有事件后再關(guān)閉。當(dāng)Filebeat重新啟動(dòng)時(shí),將再次將Filebeat關(guān)閉前未確認(rèn)的所有事件發(fā)送到輸出。這樣可以確保每個(gè)事件至少發(fā)送一次,但最終可能會(huì)有重復(fù)的事件發(fā)送到輸出。通過設(shè)置shutdown_timeout選項(xiàng),可以將Filebeat配置為在關(guān)機(jī)前等待特定時(shí)間。

Filebeat怎么玩

壓縮包方式安裝

本文采用壓縮包的方式安裝,Linux版本,filebeat-7.7.0-linux-x86_64.tar.gz。 

  1. curl-L-Ohttps://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.7.0-linux-x86_64.tar.gz  
  2. tar -xzvf filebeat-7.7.0-linux-x86_64.tar.gz 

配置示例文件:filebeat.reference.yml(包含所有未過時(shí)的配置項(xiàng))

配置文件:filebeat.yml

基本命令

詳情見官網(wǎng):https://www.elastic.co/guide/en/beats/filebeat/current/command-line-options.html 

  1. export   #導(dǎo)出  
  2. run      #執(zhí)行(默認(rèn)執(zhí)行)  
  3. test     #測(cè)試配置  
  4. keystore #秘鑰存儲(chǔ)  
  5. modules  #模塊配置管理  
  6. setup    #設(shè)置初始環(huán)境 

例如:./filebeat test config #用來測(cè)試配置文件是否正確

輸入輸出

支持的輸入組件:

Multilinemessages,Azureeventhub,CloudFoundry,Container,Docker,GooglePub/Sub,HTTPJSON,Kafka,Log,MQTT,NetFlow,Office 365 Management Activity API,Redis,s3,Stdin,Syslog,TCP,UDP(最常用的就是Log)

支持的輸出組件:

Elasticsearch,Logstash,Kafka,Redis,F(xiàn)ile,Console,ElasticCloud,Changetheoutputcodec(最常用的就是Elasticsearch,Logstash)

keystore的使用

keystore主要是防止敏感信息被泄露,比如密碼等,像ES的密碼,這里可以生成一個(gè)key為ES_PWD,值為ES的password的一個(gè)對(duì)應(yīng)關(guān)系,在使用ES的密碼的時(shí)候就可以使用${ES_PWD}使用。

  •  創(chuàng)建一個(gè)存儲(chǔ)密碼的keystore:filebeat keystore create
  •  然后往其中添加鍵值對(duì),例如:filebeatk eystore add ES_PWD
  •  使用覆蓋原來鍵的值:filebeat key store add ES_PWD–force
  •  刪除鍵值對(duì):filebeat key store remove ES_PWD
  •  查看已有的鍵值對(duì):filebeat key store list

例如:后期就可以通過${ES_PWD}使用其值,例如:

  1. output.elasticsearch.password:"${ES_PWD}" 

filebeat.yml配置(Log輸入類型為例)

詳情見官網(wǎng):https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-input-log.html 

  1. type: log #input類型為log  
  2. enable: true #表示是該log類型配置生效  
  3. paths:     #指定要監(jiān)控的日志,目前按照Go語言的glob函數(shù)處理。沒有對(duì)配置目錄做遞歸處理,比如配置的如果是:  
  4. - /var/log/* /*.log  #則只會(huì)去/var/log目錄的所有子目錄中尋找以".log"結(jié)尾的文件,而不會(huì)尋找/var/log目錄下以".log"結(jié)尾的文件。  
  5. recursive_glob.enabled: #啟用全局遞歸模式,例如/foo/**包括/foo, /foo/*, /foo/*/*  
  6. encoding:#指定被監(jiān)控的文件的編碼類型,使用plain和utf-8都是可以處理中文日志的  
  7. exclude_lines: ['^DBG'] #不包含匹配正則的行  
  8. include_lines: ['^ERR', '^WARN']  #包含匹配正則的行  
  9. harvester_buffer_size: 16384 #每個(gè)harvester在獲取文件時(shí)使用的緩沖區(qū)的字節(jié)大小  
  10. max_bytes: 10485760 #單個(gè)日志消息可以擁有的最大字節(jié)數(shù)。max_bytes之后的所有字節(jié)都被丟棄而不發(fā)送。默認(rèn)值為10MB (10485760)  
  11. exclude_files: ['\.gz$']  #用于匹配希望Filebeat忽略的文件的正則表達(dá)式列表  
  12. ingore_older: 0 #默認(rèn)為0,表示禁用,可以配置2h,2m等,注意ignore_older必須大于close_inactive的值.表示忽略超過設(shè)置值未更新的  
  13. 文件或者文件從來沒有被harvester收集  
  14. close_* #close_ *配置選項(xiàng)用于在特定標(biāo)準(zhǔn)或時(shí)間之后關(guān)閉harvester。 關(guān)閉harvester意味著關(guān)閉文件處理程序。 如果在harvester關(guān)閉  
  15. 后文件被更新,則在scan_frequency過后,文件將被重新拾取。 但是,如果在harvester關(guān)閉時(shí)移動(dòng)或刪除文件,F(xiàn)ilebeat將無法再次接收文件 
  16. ,并且harvester未讀取的任何數(shù)據(jù)都將丟失。  
  17. close_inactive  #啟動(dòng)選項(xiàng)時(shí),如果在制定時(shí)間沒有被讀取,將關(guān)閉文件句柄  
  18. 讀取的最后一條日志定義為下一次讀取的起始點(diǎn),而不是基于文件的修改時(shí)間  
  19. 如果關(guān)閉的文件發(fā)生變化,一個(gè)新的harverster將在scan_frequency運(yùn)行后被啟動(dòng)  
  20. 建議至少設(shè)置一個(gè)大于讀取日志頻率的值,配置多個(gè)prospector來實(shí)現(xiàn)針對(duì)不同更新速度的日志文件  
  21. 使用內(nèi)部時(shí)間戳機(jī)制,來反映記錄日志的讀取,每次讀取到最后一行日志時(shí)開始倒計(jì)時(shí)使用2h 5m 來表示  
  22. close_rename #當(dāng)選項(xiàng)啟動(dòng),如果文件被重命名和移動(dòng),filebeat關(guān)閉文件的處理讀取  
  23. close_removed #當(dāng)選項(xiàng)啟動(dòng),文件被刪除時(shí),filebeat關(guān)閉文件的處理讀取這個(gè)選項(xiàng)啟動(dòng)后,必須啟動(dòng)clean_removed  
  24. close_eof #適合只寫一次日志的文件,然后filebeat關(guān)閉文件的處理讀取  
  25. close_timeout #當(dāng)選項(xiàng)啟動(dòng)時(shí),filebeat會(huì)給每個(gè)harvester設(shè)置預(yù)定義時(shí)間,不管這個(gè)文件是否被讀取,達(dá)到設(shè)定時(shí)間后,將被關(guān)閉  
  26. close_timeout 不能等于ignore_older,會(huì)導(dǎo)致文件更新時(shí),不會(huì)被讀取如果output一直沒有輸出日志事件,這個(gè)timeout是不會(huì)被啟動(dòng)的,  
  27. 至少要要有一個(gè)事件發(fā)送,然后haverter將被關(guān)閉  
  28. 設(shè)置0 表示不啟動(dòng)  
  29. clean_inactived #從注冊(cè)表文件中刪除先前收獲的文件的狀態(tài)  
  30. 設(shè)置必須大于ignore_older+scan_frequency,以確保在文件仍在收集時(shí)沒有刪除任何狀態(tài)  
  31. 配置選項(xiàng)有助于減小注冊(cè)表文件的大小,特別是如果每天都生成大量的新文件  
  32. 此配置選項(xiàng)也可用于防止在Linux上重用inode的Filebeat問題  
  33. clean_removed #啟動(dòng)選項(xiàng)后,如果文件在磁盤上找不到,將從注冊(cè)表中清除filebeat  
  34. 如果關(guān)閉close removed 必須關(guān)閉clean removed 
  35. scan_frequency #prospector檢查指定用于收獲的路徑中的新文件的頻率,默認(rèn)10s  
  36. tail_files:#如果設(shè)置為true,F(xiàn)ilebeat從文件尾開始監(jiān)控文件新增內(nèi)容,把新增的每一行文件作為一個(gè)事件依次發(fā)送,  
  37. 而不是從文件開始處重新發(fā)送所有內(nèi)容。  
  38. symlinks:#符號(hào)鏈接選項(xiàng)允許Filebeat除常規(guī)文件外,可以收集符號(hào)鏈接。收集符號(hào)鏈接時(shí),即使報(bào)告了符號(hào)鏈接的路徑,  
  39. Filebeat也會(huì)打開并讀取原始文件。 
  40. backoff: #backoff選項(xiàng)指定Filebeat如何積極地抓取新文件進(jìn)行更新。默認(rèn)1s,backoff選項(xiàng)定義Filebeat在達(dá)到EOF之后  
  41. 再次檢查文件之間等待的時(shí)間。  
  42. max_backoff: #在達(dá)到EOF之后再次檢查文件之前Filebeat等待的最長(zhǎng)時(shí)間  
  43. backoff_factor: #指定backoff嘗試等待時(shí)間幾次,默認(rèn)是2  
  44. harvester_limit:#harvester_limit選項(xiàng)限制一個(gè)prospector并行啟動(dòng)的harvester數(shù)量,直接影響文件打開數(shù)  
  45. tags #列表中添加標(biāo)簽,用過過濾,例如:tags: ["json"]  
  46. fields #可選字段,選擇額外的字段進(jìn)行輸出可以是標(biāo)量值,元組,字典等嵌套類型  
  47. 默認(rèn)在sub-dictionary位置  
  48. filebeat.inputs:  
  49. fields:  
  50. app_id: query_engine_12  
  51. fields_under_root #如果值為ture,那么fields存儲(chǔ)在輸出文檔的頂級(jí)位置  
  52. multiline.pattern #必須匹配的regexp模式  
  53. multiline.negate #定義上面的模式匹配條件的動(dòng)作是 否定的,默認(rèn)是false  
  54. 假如模式匹配條件'^b',默認(rèn)是false模式,表示講按照模式匹配進(jìn)行匹配 將不是以b開頭的日志行進(jìn)行合并  
  55. 如果是true,表示將不以b開頭的日志行進(jìn)行合并  
  56. multiline.match # 指定Filebeat如何將匹配行組合成事件,在之前或者之后,取決于上面所指定的negate  
  57. multiline.max_lines #可以組合成一個(gè)事件的最大行數(shù),超過將丟棄,默認(rèn)500  
  58. multiline.timeout #定義超時(shí)時(shí)間,如果開始一個(gè)新的事件在超時(shí)時(shí)間內(nèi)沒有發(fā)現(xiàn)匹配,也將發(fā)送日志,默認(rèn)是5s  
  59. max_procs #設(shè)置可以同時(shí)執(zhí)行的最大CPU數(shù)。默認(rèn)值為系統(tǒng)中可用的邏輯CPU的數(shù)量。  
  60. name #為該filebeat指定名字,默認(rèn)為主機(jī)的hostname 

實(shí)例一:Logstash作為輸出

filebeat.yml配置: 

  1. #=========================== Filebeat inputs =============================  
  2. filebeat.inputs:  
  3. # Each - is an input. Most options can be set at the input level, so  
  4. # you can use different inputs for various configurations.  
  5. # Below are the input specific configurations.  
  6. - type: log  
  7.   # Change to true to enable this input configuration.  
  8.   enabled: true  
  9.   # Paths that should be crawled and fetched. Glob based paths.  
  10.   paths:  #配置多個(gè)日志路徑  
  11.     -/var/logs/es_aaa_index_search_slowlog.log  
  12.     -/var/logs/es_bbb_index_search_slowlog.log  
  13.     -/var/logs/es_ccc_index_search_slowlog.log  
  14.     -/var/logs/es_ddd_index_search_slowlog.log  
  15.     #- c:\programdata\elasticsearch\logs\*  
  16.   # Exclude lines. A list of regular expressions to match. It drops the lines that are  
  17.   # matching any regular expression from the list.  
  18.   #exclude_lines: ['^DBG']  
  19.   # Include lines. A list of regular expressions to match. It exports the lines that are  
  20.   # matching any regular expression from the list.  
  21.   #include_lines: ['^ERR', '^WARN']  
  22.   # Exclude files. A list of regular expressions to match. Filebeat drops the files that  
  23.   # are matching any regular expression from the list. By default, no files are dropped.  
  24.   #exclude_files: ['.gz$']  
  25.   # Optional additional fields. These fields can be freely picked  
  26.   # to add additional information to the crawled log files for filtering  
  27.   #fields:  
  28.   #  level: debug  
  29.   #  review: 1  
  30.   ### Multiline options  
  31.   # Multiline can be used for log messages spanning multiple lines. This is common  
  32.   # for Java Stack Traces or C-Line Continuation  
  33.   # The regexp Pattern that has to be matched. The example pattern matches all lines starting with [  
  34.   #multiline.pattern: ^\[  
  35.   # Defines if the pattern set under pattern should be negated or not. Default is false.  
  36.   #multiline.negate: false  
  37.   # Match can be set to "after" or "before". It is used to define if lines should be append to a pattern  
  38.   # that was (not) matched before or after or as long as a pattern is not matched based on negate.  
  39.   # Note: After is the equivalent to previous and before is the equivalent to to next in Logstash  
  40.   #multiline.match: after  
  41. #================================ Outputs =====================================  
  42. #----------------------------- Logstash output --------------------------------  
  43. output.logstash:  
  44.   # The Logstash hosts #配多個(gè)logstash使用負(fù)載均衡機(jī)制  
  45.   hosts: ["192.168.110.130:5044","192.168.110.131:5044","192.168.110.132:5044","192.168.110.133:5044"]    
  46.   loadbalance: true  #使用了負(fù)載均衡  
  47.   # Optional SSL. By default is off.  
  48.   # List of root certificates for HTTPS server verifications  
  49.   #ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]  
  50.   # Certificate for SSL client authentication  
  51.   #ssl.certificate: "/etc/pki/client/cert.pem"   
  52.   # Client Certificate Key  
  53.   #ssl.key: "/etc/pki/client/cert.key" 

./filebeat -e #啟動(dòng)filebeat

Logstash的配置: 

  1. input {  
  2.   beats {  
  3.     port => 5044    
  4.   }  
  5.  
  6. output {  
  7.   elasticsearch {  
  8.     hosts => ["http://192.168.110.130:9200"] #這里可以配置多個(gè)  
  9.     index => "query-%{yyyyMMdd}"   
  10.   }  

實(shí)例二:Elasticsearch作為輸出

filebeat.yml的配置: 

  1. ###################### Filebeat Configuration Example #########################  
  2. # This file is an example configuration file highlighting only the most common  
  3. # options. The filebeat.reference.yml file from the same directory contains all the  
  4. # supported options with more comments. You can use it as a reference. 
  5.  
  6. # You can find the full configuration reference here:  
  7. # https://www.elastic.co/guide/en/beats/filebeat/index.html  
  8. # For more available modules and options, please see the filebeat.reference.yml sample  
  9. # configuration file.  
  10. #=========================== Filebeat inputs =============================  
  11. filebeat.inputs:  
  12. # Each - is an input. Most options can be set at the input level, so  
  13. # you can use different inputs for various configurations.  
  14. # Below are the input specific configurations.  
  15. - type: log  
  16.   # Change to true to enable this input configuration.  
  17.   enabled: true  
  18.   # Paths that should be crawled and fetched. Glob based paths.  
  19.   paths:  
  20.     -/var/logs/es_aaa_index_search_slowlog.log  
  21.     -/var/logs/es_bbb_index_search_slowlog.log  
  22.     -/var/logs/es_ccc_index_search_slowlog.log  
  23.     -/var/logs/es_dddd_index_search_slowlog.log  
  24.     #- c:\programdata\elasticsearch\logs\*  
  25.   # Exclude lines. A list of regular expressions to match. It drops the lines that are  
  26.   # matching any regular expression from the list.  
  27.   #exclude_lines: ['^DBG']  
  28.   # Include lines. A list of regular expressions to match. It exports the lines that are  
  29.   # matching any regular expression from the list.  
  30.   #include_lines: ['^ERR', '^WARN']  
  31.   # Exclude files. A list of regular expressions to match. Filebeat drops the files that  
  32.   # are matching any regular expression from the list. By default, no files are dropped.  
  33.   #exclude_files: ['.gz$']  
  34.   # Optional additional fields. These fields can be freely picked  
  35.   # to add additional information to the crawled log files for filtering 
  36.   #fields:  
  37.   #  level: debug  
  38.   #  review: 1   
  39.   ### Multiline options   
  40.   # Multiline can be used for log messages spanning multiple lines. This is common 
  41.   # for Java Stack Traces or C-Line Continuation  
  42.   # The regexp Pattern that has to be matched. The example pattern matches all lines starting with [  
  43.   #multiline.pattern: ^\[  
  44.   # Defines if the pattern set under pattern should be negated or not. Default is false.  
  45.   #multiline.negate: false  
  46.   # Match can be set to "after" or "before". It is used to define if lines should be append to a pattern  
  47.   # that was (not) matched before or after or as long as a pattern is not matched based on negate.  
  48.   # Note: After is the equivalent to previous and before is the equivalent to to next in Logstash 
  49.   #multiline.match: after   
  50. #============================= Filebeat modules =============================== 
  51. filebeat.config.modules:  
  52.   # Glob pattern for configuration loading 
  53.   path: ${path.config}/modules.d/*.yml  
  54.   # Set to true to enable config reloading  
  55.   reload.enabled: false 
  56.   # Period on which files under path should be checked for changes  
  57.   #reload.period: 10s  
  58. #==================== Elasticsearch template setting ==========================  
  59. #================================ General =====================================  
  60. # The name of the shipper that publishes the network data. It can be used to group  
  61. # all the transactions sent by a single shipper in the web interface.  
  62. name: filebeat222  
  63. # The tags of the shipper are included in their own field with each  
  64. # transaction published. 
  65. #tags: ["service-X", "web-tier"]  
  66. # Optional fields that you can specify to add additional information to the  
  67. # output.  
  68. #fields:  
  69. #  env: staging  
  70. #cloud.auth:  
  71. #================================ Outputs =====================================  
  72. #-------------------------- Elasticsearch output ------------------------------  
  73. output.elasticsearch:  
  74.   # Array of hosts to connect to.  
  75.   hosts: ["192.168.110.130:9200","92.168.110.131:9200"]  
  76.   # Protocol - either `http` (default) or `https`.  
  77.   #protocol: "https"  
  78.   # Authentication credentials - either API key or username/password.  
  79.   #api_key: "id:api_key"  
  80.   username: "elastic"  
  81.   password: "${ES_PWD}"   #通過keystore設(shè)置密碼 

./filebeat -e #啟動(dòng)Filebeat

查看Elasticsearch集群,有一個(gè)默認(rèn)的索引名字filebeat-%{[beat.version]}-%{+yyyy.MM.dd}

Filebeat模塊

官網(wǎng):https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-modules.html

這里我使用Elasticsearch模式來解析ES的慢日志查詢,操作步驟如下,其他的模塊操作也一樣:

前提:安裝好Elasticsearch和Kibana兩個(gè)軟件,然后使用Filebeat。

具體的操作官網(wǎng)有:https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-modules-quickstart.html

第一步,配置filebeat.yml文件: 

  1. #============================== Kibana =====================================  
  2. # Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.  
  3. # This requires a Kibana endpoint configuration.  
  4. setup.kibana:  
  5.   # Kibana Host  
  6.   # Scheme and port can be left out and will be set to the default (http and 5601)  
  7.   # In case you specify and additional path, the scheme is required: http://localhost:5601/path  
  8.   # IPv6 addresses should always be defined as: https://[2001:db8::1]:5601  
  9.   host: "192.168.110.130:5601"  #指定kibana  
  10.   username: "elastic"   #用戶  
  11.   password: "${ES_PWD}"  #密碼,這里使用了keystore,防止明文密碼  
  12.   # Kibana Space ID  
  13.   # ID of the Kibana Space into which the dashboards should be loaded. By default,  
  14.   # the Default Space will be used.  
  15.   #space.id:  
  16. #================================ Outputs =====================================  
  17. # Configure what output to use when sending the data collected by the beat.  
  18. #-------------------------- Elasticsearch output ------------------------------ 
  19. output.elasticsearch:  
  20.   # Array of hosts to connect to.  
  21.   hosts: ["192.168.110.130:9200","192.168.110.131:9200"]  
  22.   # Protocol - either `http` (default) or `https`.  
  23.   #protocol: "https" 
  24.   # Authentication credentials - either API key or username/password.  
  25.   #api_key: "id:api_key"  
  26.   username: "elastic"  #es的用戶  
  27.   password: "${ES_PWD}" # es的密碼  
  28.   #這里不能指定index,因?yàn)槲覜]有配置模板,會(huì)自動(dòng)生成一個(gè)名為filebeat-%{[beat.version]}-%{+yyyy.MM.dd}的索引 

第二步,配置Elasticsearch的慢日志路徑:

  1. cd filebeat-7.7.0-linux-x86_64/modules.d 

vim elasticsearch.yml:

第三步,生效ES模塊: 

  1. ./filebeat modules elasticsearch 

查看生效的模塊: 

  1. ./filebeat modules list 

第四步,初始化環(huán)境:

  1. ./filebeat setup -e 

第五步,啟動(dòng)Filebeat: 

  1. ./filebeat -e 

查看Elasticsearch集群,如下圖所示,把慢日志查詢的日志都自動(dòng)解析出來了:

到這里,Elasticsearch這個(gè)module就實(shí)驗(yàn)成功了。 

 

責(zé)任編輯:龐桂玉 來源: 運(yùn)維派
相關(guān)推薦

2017-09-05 08:52:37

Git程序員命令

2020-06-03 11:06:26

DNS域名緩存

2022-10-08 15:07:06

ChatOps運(yùn)維

2019-07-15 07:58:10

前端開發(fā)技術(shù)

2017-07-20 16:55:56

Android事件響應(yīng)View源碼分析

2021-08-02 10:01:09

Iterator接口Java項(xiàng)目開發(fā)

2024-10-23 16:02:40

JavaScriptPromiserejection

2021-05-18 09:00:28

Pythonclass

2021-08-17 09:55:05

JavaScript MicrotaskPromise

2021-05-27 09:01:14

Python文件讀寫Python基礎(chǔ)

2021-08-30 10:01:01

Map接口HashMap

2020-03-31 08:37:31

遞歸單鏈表反轉(zhuǎn)

2019-07-23 08:55:46

Base64編碼底層

2023-11-01 15:52:35

2020-07-28 17:27:53

Nginx 負(fù)載均衡模塊

2020-06-23 16:28:25

Nginx負(fù)載均衡服務(wù)器

2019-08-13 09:00:01

內(nèi)網(wǎng)外網(wǎng)通信

2020-10-09 08:15:11

JsBridge

2020-07-08 13:38:10

NginxApache服務(wù)器

2021-05-21 09:01:56

Python繼承多態(tài)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)