本文目錄一覽:
efk簡單部署
EFK是由ElasticSearch(es)、Filebeat和Kiabana三個開源工具組成:
1.ElasticSearch是一個基於Lucence的開源分布式搜索服務器,它的特點有:分布式、零配置、自動發現、索引自動分片、索引副本機制、restful風格接口、多數據源、自動搜索負載等,提供了一個分布式多用戶能力的全文搜索引擎。
2.Filebeat 是基於原先 logstash-forwarder 的源碼改造出來的,安裝包10M左右。如果日誌的量很大,Logstash 會遇到資源佔用高的問題,為解決這個問題,這裡採用Filebeat。Filebeat 用 Golang 編寫,無需依賴 Java 環境,效率高,佔用內存和 CPU 比較少,非常適合作為 Agent 跑在服務器上
3.Kiabana是一個基於瀏覽器頁面的ElasticSearch前端展示工具,也是一個開源的工具,提供友好的web界面。
驗證是否成功
默認配置文件在如下,可以修改端口和地址,這裡修改配置,把ip改成本機
漢化
修改yml配置:
常用命令:
配置示例:
配置說明:
定義日誌文件路徑
配置輸出 :可以將其直接發送到es,也可以發送到Logstash以進行其他處理
目錄說明:
在kibana界面建立索引
參考資料:
如何在 Go 語言中用 Beats 開發 Logstash 插件
配置環境
在OSX系統上很容易安裝GO的可執行文件:
brew install go
雖然Java或Ruby (或者任何我知道的語言) 可以在本地文件系統的任何地方使用命令,,但是Go項目必須使用單一專用的地址,,並且在$GOPATH環境變量下可用。
第 1 段(可獲 1.54 積分)
R e; 7個月前
創建項目對於Logstash插件,Beats項目可以從模板創建。官方文檔的說明十分簡單。鑒於Go對文件系統上的位置的嚴格要求,只需按照以下說明生成一個新的即可使用的Go項目。默認模板代碼將在控制台中重複發送帶增量計數器的事件:./redditbeat -e -d “*”
2016/12/13 22:55:56.013362 beat.go:267: INFO
Home path: [/Users/i303869/projects/private/go/src/github.com/nfrankel/redditbeat]
Config path: [/Users/i303869/projects/private/go/src/github.com/nfrankel/redditbeat]
Data path: [/Users/i303869/projects/private/go/src/github.com/nfrankel/redditbeat/data]
Logs path: [/Users/i303869/projects/private/go/src/github.com/nfrankel/redditbeat/logs]
2016/12/13 22:55:56.013390 beat.go:177: INFO Setup Beat: redditbeat; Version: 6.0.0-alpha1
2016/12/13 22:55:56.013402 processor.go:43: DBG Processors:
2016/12/13 22:55:56.013413 beat.go:183: DBG Initializing output plugins
2016/12/13 22:55:56.013417 logp.go:219: INFO Metrics logging every 30s
2016/12/13 22:55:56.013518 output.go:167: INFO Loading template enabled. Reading template file:
/Users/i303869/projects/private/go/src/github.com/nfrankel/redditbeat/redditbeat.template.json
2016/12/13 22:55:56.013888 output.go:178: INFO Loading template enabled for Elasticsearch 2.x. Reading template file:
/Users/i303869/projects/private/go/src/github.com/nfrankel/redditbeat/redditbeat.template-es2x.json
2016/12/13 22:55:56.014229 client.go:120: INFO Elasticsearch url:
2016/12/13 22:55:56.014272 outputs.go:106: INFO Activated elasticsearch as output plugin.
2016/12/13 22:55:56.014279 publish.go:234: DBG Create output worker
2016/12/13 22:55:56.014312 publish.go:276: DBG No output is defined to store the topology.
The server fields might not be filled.
2016/12/13 22:55:56.014326 publish.go:291: INFO Publisher name: LSNM33795267A
2016/12/13 22:55:56.014386 async.go:63: INFO Flush Interval set to: 1s
2016/12/13 22:55:56.014391 async.go:64: INFO Max Bulk Size set to: 50
2016/12/13 22:55:56.014395 async.go:72: DBG create bulk processing worker (interval=1s, bulk size=50)
2016/12/13 22:55:56.014449 beat.go:207: INFO redditbeat start running.
2016/12/13 22:55:56.014459 redditbeat.go:38: INFO redditbeat is running! Hit CTRL-C to stop it.
2016/12/13 22:55:57.370781 client.go:184: DBG Publish: {
“@timestamp”: “2016-12-13T22:54:47.252Z”,
“beat”: {
“hostname”: “LSNM33795267A”,
“name”: “LSNM33795267A”,
“version”: “6.0.0-alpha1”
},
“counter”: 1,
“type”: “redditbeat”
}
第 2 段(可獲 0.73 積分)
R e; 7個月前
關於命令行參數:-e記錄到標準err,而-d“*”啟用所有調試選擇器。有關參數的完整列表,請鍵入./redditbeat –help。編碼Go代碼位於.go文件中(令人驚訝…)在$ GOPATH / src文件夾的項目子文件夾中。配置類型第一個有趣的文件是config / config.go,它定義了一個結構來聲明Beat的可能參數。至於前面的Logstash插件,讓我們添加一個subreddit參數,並設置它的默認值:type Config struct {
Period time.Duration `config:”period”`
Subreddit string `config:”subreddit”`
}
var DefaultConfig = Config {
Period: 15 * time.Second,
Subreddit: “elastic”,
}
第 3 段(可獲 0.89 積分)
R e; 7個月前
Beater TypeBeat本身的代碼在beater / redditbean.go中找到。默認模板為Beat和三個函數創建一個struct:Beat構造函數—用來讀取配置: func New(b *beat.Beat, cfg *common.Config) (beat.Beater, error) { … }
Run 函數- 需要覆蓋Beat的主要功能: func (bt *Redditbeat) Run(b *beat.Beat) error { … }
Stop 函數管理優雅關閉: func (bt *Redditbeat) Stop() { … }
Note 1:在Go中沒有明確的接口實現。實現了 interface 中的所有方法,即創建一個隱式繼承關係. 出於寫文檔的目的,這是 Beater 接口:type Beater interface {
Run(b *Beat) error
Stop()
}
第 4 段(可獲 0.93 積分)
R e; 7個月前
因此,由於Beat結構實現了Run和Stop,它是一個Beater。Note 2: 在Go中沒有類的概念,所以方法不能在一個具體類型上聲明。但是,它存在擴展函數的概念:可以添加行為到一個類型(在單個包中)的函數。它需要聲明receiver 類型:這是在fun關鍵字和函數名之間完成的 – 這裡是指Redditbeat類型(或者更準確地說,是一個指向Redditbeat類型的指針,但是這裡有一個隱式轉換)。構造函數和Stop函數可以保持不變,無論什麼特性都應該在Run函數中。在這種情況下,功能是調用Reddit REST API並為每個Reddit帖子發送一條消息。
第 5 段(可獲 1.59 積分)
R e; 7個月前
最終代碼如下所示:func (bt *Redditbeat) Run(b *beat.Beat) error {
bt.client = b.Publisher.Connect()
ticker := time.NewTicker(bt.config.Period)
reddit := “” + bt.config.Subreddit + “/.json”
client := http.Client {}
for {
select {
case -bt.done:
return nil
case -ticker.C:
}
req, reqErr := http.NewRequest(“GET”, reddit, nil)
req.Header.Add(“User-Agent”, “Some existing header to bypass 429 HTTP”)
if (reqErr != nil) {
panic(reqErr)
}
resp, getErr := client.Do(req)
if (getErr != nil) {
panic(getErr)
}
body, readErr := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if (readErr != nil) {
panic(readErr)
}
trimmedBody := body[len(prefix):len(body) – len(suffix)]
messages := strings.Split(string(trimmedBody), separator)
for i := 0; i len(messages); i ++ {
event := common.MapStr{
“@timestamp”: common.Time(time.Now()),
“type”: b.Name,
“message”: “{” + messages[i] + “}”,
}
bt.client.PublishEvent(event)
}
}
}
第 6 段(可獲 0.09 積分)
R e; 7個月前
這裡是對最重要的幾部分的解釋:line 4: 通過連接字符串創建Reddit REST URL,包括配置Subreddit參數。記住,它的默認值已在config.go文件中定義。line 5: 引用httpClient類型line 12: 創建新的HTTP請求。注意Go允許多個返回值。line 13: 如果沒有設置標準請求頭,Reddit的API將返回429狀態碼。line 14: Go標準錯誤不通過異常處理,而是隨着常規返回值返回。根據Golang wiki:指示調用者的錯誤條件,應通過返回錯誤值來完成line 15: panic() 函數類似於在Java中拋出異常, 被處理時推到棧頂。 有關詳細信息,請查看相關文檔。line 17: 執行HTTP請求。line 21: 將響應主體讀入字節數組。line 22: 關閉主體流。注意defer關鍵字:defer語句延遲函數的執行,直到環繞的函數返回。line 26: 創建整個響應主體字節數組的切片 – 對數組的一部分的引用。實質上,它刪除了前綴和後綴以保持相關的JSON值。之後將字節數組解析成JSON。line 27: 分割切片以單獨獲取每個JSON片段。line 29: 將消息創建為簡單的字典結構。line 34: 發送。
第 7 段(可獲 3.11 積分)
R e; 7個月前
配置, 構建, 運行默認配置參數可以在項目根目錄下的redditbeat.yml文件中找到。請注意,redditbeat.full.yml中列出了其他常見的Beat參數,以及相關注釋。關於Beats的一個有趣的事情是,他們的消息可以直接發送到Elasticsearch或Logstash進行進一步處理。這在上述配置文件中配置。redditbeat:
period: 10s
output.elasticsearch:
hosts: [“localhost:9200”]
output.logstash:
hosts: [“localhost:5044”]
enabled: true
第 8 段(可獲 0.78 積分)
R e; 7個月前
此配置片段將每10秒循環運行Run方法,並將消息發送到在localhost上運行的Logstash實例在端口5044上。這可以在運行Beat時被覆蓋(見下文)。注意:為了使Logstash接受來自Beats的消息,必須安裝Logstash Beat插件,並且必須為Beats配置Logstash的input:input {
beats {
port = 5044
}
}
要構建項目,請在項目的根目錄中鍵入make。它將創建一個可以運行的可執行文件。./redditbeat -e -E redditbeat.subreddit=java
-E參數可以覆蓋在的redditbeat.yml配置文件中找到的參數(見上文)。在這裡,它設置subreddit讀為“java”,而不是默認的“elastic”。
第 9 段(可獲 1.3 積分)
R e; 7個月前
輸出如下所示:2016/12/17 14:51:19.748329 client.go:184: DBG Publish: {
“@timestamp”: “2016-12-17T14:51:19.748Z”,
“beat”: {
“hostname”: “LSNM33795267A”,
“name”: “LSNM33795267A”,
“version”: “6.0.0-alpha1”
},
“message”: “{
\”kind\”: \”t3\”, \”data\”: {
\”contest_mode\”: false, \”banned_by\”: null,
\”domain\”: \”blogs.oracle.com\”, \”subreddit\”: \”java\”, \”selftext_html\”: null,
\”selftext\”: \”\”, \”likes\”: null, \”suggested_sort\”: null, \”user_reports\”: [],
\”secure_media\”: null, \”saved\”: false, \”id\”: \”5ipzgq\”, \”gilded\”: 0,
\”secure_media_embed\”: {}, \”clicked\”: false, \”report_reasons\”: null,
\”author\”: \”pushthestack\”, \”media\”: null, \”name\”: \”t3_5ipzgq\”, \”score\”: 11,
\”approved_by\”: null, \”over_18\”: false, \”removal_reason\”: null, \”hidden\”: false,
\”thumbnail\”: \”\”, \”subreddit_id\”: \”t5_2qhd7\”, \”edited\”: false,
\”link_flair_css_class\”: null, \”author_flair_css_class\”: null, \”downs\”: 0,
\”mod_reports\”: [], \”archived\”: false, \”media_embed\”: {}, \”is_self\”: false,
\”hide_score\”: false, \”spoiler\”: false,
\”permalink\”: \”/r/java/comments/5ipzgq/jdk_9_will_no_longer_bundle_javadb/\”,
\”locked\”: false, \”stickied\”: false, \”created\”: 1481943248.0,
\”url\”: \”\”,
\”author_flair_text\”: null, \”quarantine\”: false,
\”title\”: \”JDK 9 will no longer bundle JavaDB\”, \”created_utc\”: 1481914448.0,
\”link_flair_text\”: null, \”distinguished\”: null, \”num_comments\”: 4,
\”visited\”: false, \”num_reports\”: null, \”ups\”: 11
}
}”,
“type”: “redditbeat”
}
Drone 一些簡單的流水線配置(盡量持續更新)
盡量先去官網簡單看看。
drone官網:
drone插件的網址:
這裡記錄一些我使用的一些簡單的流水線配置:
.drone.yml文件同golang,主要將Dockerfile記錄一下
golang json:怎麼替代yaml:
安裝EasyDataTransform在Mac上就可以解決。
安裝EasyDataTransform在Mac上,開始輕鬆的數據轉換,將要顯示重複項的Excel電子表格拖到EasyDataTransform上。將添加一個粉紅色的輸入項請注意右側窗格中的JSON數據已自動“展平”到表格中。
您可以將右窗格中的Format下拉菜單設置為Long或Wide,具體取決於您希望表格具有更多行還是更多列,確保選擇了粉紅色的輸入項,單擊左窗格中的ToFile按鈕,將出現一個窗口。設置新文件名和位置。選擇YAML文件作為文件類型。添加並選擇了一個綠色輸出項。YAML文件會立即創建,無需“運行”任何內容您可以在右側窗格中更改YAML文件編碼。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/257384.html