開(kāi)發(fā)必知必會(huì)的幾套方案
eflk
elasticsearch+filebeat、metricbeat+logstash+kibana
用于日志查詢(xún)
Elasticsearch是一個(gè)基于Lucene的搜索服務(wù)器。提供一個(gè)分布式多用戶(hù)能力的全文搜索引擎。
Kibana是開(kāi)源的分析與可視化平臺(tái),能夠讓您對(duì) Elasticsearch 數(shù)據(jù)進(jìn)行可視化。
Logstash是一個(gè)開(kāi)源數(shù)據(jù)收集引擎,具有實(shí)時(shí)管道功能。Logstash可以動(dòng)態(tài)地將來(lái)自不同數(shù)據(jù)源的數(shù)據(jù)統(tǒng)一起來(lái),并將數(shù)據(jù)標(biāo)準(zhǔn)化到你所選擇的目的地。(相當(dāng)于專(zhuān)一而不是通用化的ELT工具)

Beats在是一個(gè)輕量級(jí)日志采集器,相比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ù))。
(Logstash是JVM語(yǔ)言,F(xiàn)ilebeat是Go語(yǔ)言寫(xiě)的,這也能說(shuō)明一點(diǎn)在語(yǔ)言層面的選擇性吧),這里用到Filebeat、Metricbeat。
1. 程序日志

2. mysql慢查詢(xún)?nèi)罩?/span>

3. Nginx日志


4. 系統(tǒng)指標(biāo)監(jiān)控

安裝Elasticsearch+Kibana+密碼配置:
鏡像docker pull docker.elastic.co/elasticsearch/elasticsearch:7.10.0啟動(dòng)docker run --name localEs -d -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.10.0配置docker exec -it localEs bashcd configvi elasticsearch.yml//配置http.cors.enabled: truehttp.cors.allow-origin: "*"http.cors.allow-headers: Authorizationxpack.security.enabled: truexpack.security.transport.ssl.enabled: true//配置密碼-重啟容器elasticsearch-setup-passwords interactive//安裝kibinadocker pull docker.elastic.co/kibana/kibana:7.10.0docker run --name kibana -d --link localEs:elasticsearch -p 5601:5601 docker.elastic.co/kibana/kibana:7.10.0//配置docker exec -it kibana bashcd configvi kibana.yml//配置server.name: kibanaserver.host: "0.0.0.0"elasticsearch.hosts: [ "http://{IpAddress}:9200" ]//docker inspect es查看es容器內(nèi)部的ip地址monitoring.ui.container.elasticsearch.enabled: trueelasticsearch.username: "elastic"elasticsearch.password: "zmx111222"i18n.locale: "zh-CN"重啟容器
安裝Logstash
1.下載 https://www.elastic.co/downloads/logstashhttps://artifacts.elastic.co/downloads/logstash/logstash-7.13.1-linux-x86_64.tar.gz2.配置編輯 /opt/logstash/logstash-7.13.1/config/logstash.yml配置文件修改如下內(nèi)容:node.name: aliyun2corepath.data: /opt/logstash/plugin-dataconfig.reload.automatic: trueconfig.reload.interval: 10http.host: "47.96.74.110"3.可以直接讀取日志、也可以從插件讀取-例如Filebeat、Jdbc(logstash 有非常多插件https://www.elastic.co/guide/en/logstash/current/index.html3.1安裝logstash-input-jdbc 和logstash-input-beats-master 插件(暫緩測(cè)試)./bin/logstash-plugin install logstash-input-jdbc./logstash-plugin install logstash-input-beats3.2 codec插件 codec解決日志換行的問(wèn)題在logstash讀入的時(shí)候,通過(guò)codec編碼解析日志為相應(yīng)格式,從logstash輸出的時(shí)候,通過(guò)codec解碼成相應(yīng)格式。3.3 grok插件 支持以正則表達(dá)式的方式提取日志信息用于將非結(jié)構(gòu)化數(shù)據(jù)解析為結(jié)構(gòu)化和可查詢(xún)的數(shù)據(jù)。https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html4.啟動(dòng)nohup ./logstash -f ../config/logstash.conf &
安裝filebeat
1.下載https://www.elastic.co/cn/downloads/beats/filebeatcurl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.13.1-linux-x86_64.tar.gztar xzvf filebeat-7.13.1-linux-x86_64.tar.gzcd filebeat-7.13.1-linux-x86_642.編輯配置修改 filebeat.yml 以設(shè)置連接信息:output.elasticsearch:hosts: ["<es_url>"]username: "elastic"password: "<password>"setup.kibana:host: "<kibana_url>"monitoring.enabled: true #開(kāi)啟服務(wù)監(jiān)控-需要 Elasticsearch 配合開(kāi)啟xpack monitoring=》編輯輸入log日志路徑:/opt/nifi/nifi-1.13.2/logs/nifi-app.log3.啟用和配置 apache 模塊./filebeat modules enable apache在 modules.d/apache.yml 文件中修改設(shè)置。4.啟動(dòng) Filebeat./filebeat setup./filebeat -enohup ./filebeat -e -c filebeat.yml -d "publish" & > nohup.out提示:1.fileBeat可以從日志流直接獲取日志信息 2.可以輸出到logstash中
安裝 metricbeat
下載:https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.13.1-linux-x86_64.tar.gz配置:修改 /etc/metricbeat/metricbeat.yml 以設(shè)置連接信息:output.elasticsearch:hosts: ["<es_url>"]username: "elastic"password: "<password>"setup.kibana:host: "<kibana_url>"啟用和配置 system 模塊(其他模板差不多流程)sudo ./metricbeat modules enable system配置系統(tǒng)服務(wù)在 /etc/metricbeat/modules.d/system.yml 文件中修改設(shè)置。啟動(dòng)服務(wù)sudo metricbeat setupsudo service metricbeat startnohup ./metricbeat -e -c metricbeat.yml -d "publish" & > nohup.outkibana上查看數(shù)據(jù)
Prometheus+grafana
用于指標(biāo)監(jiān)控
Grafana是一款用Go語(yǔ)言開(kāi)發(fā)的開(kāi)源數(shù)據(jù)可視化工具。相比于Kibana和
Chronograf,Grafana在可視化展示層面更優(yōu)秀非常多。數(shù)據(jù)源支持非常廣,包括InfluxDB和mysql。
Prometheus是由SoundCloud開(kāi)發(fā)的開(kāi)源監(jiān)控報(bào)警系統(tǒng)和時(shí)序列數(shù)據(jù)庫(kù)。從字面上理解,Prometheus由兩個(gè)部分組成,一個(gè)是監(jiān)控報(bào)警系統(tǒng),另一個(gè)是自帶的時(shí)序數(shù)據(jù)庫(kù)(TSDB)。
可以看出EFLK和普羅米修斯(Prometheus)+Grafana在日志查詢(xún)和監(jiān)控領(lǐng)域是有重疊的,不過(guò),目前來(lái)選的話,EFLK用于日志監(jiān)控檢索,PG用于系統(tǒng)監(jiān)控是不錯(cuò)的選擇。
1. 系統(tǒng)監(jiān)控

2. JVM監(jiān)控


安裝node-exporter、prometheus、grafana
=》僅僅提取系統(tǒng)指標(biāo)docker run -d -p 9100:9100 \-v "/proc:/host/proc:ro" \-v "/sys:/host/sys:ro" \-v "/:/rootfs:ro" \--net="host" \prom/node-exporter=》elt轉(zhuǎn)移、存儲(chǔ)指標(biāo)mkdir /opt/prometheuscd /opt/prometheus/vim prometheus.yml配置global:scrape_interval: 60sevaluation_interval: 60sscrape_configs:job_name: prometheusstatic_configs:targets: ['localhost:9090']labels:instance: prometheusjob_name: linuxstatic_configs:targets: ['ip:9100']labels:instance: localhost啟動(dòng)dockerdocker run -d \-p 9090:9090 \-v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \prom/prometheus展示:docker run -d --name=grafana -p 3000:3000 grafana/grafana
TICK
Telegraf + influxdb+Chronograf+Kapacitor
用于時(shí)序數(shù)據(jù)存儲(chǔ)和監(jiān)控
influxdb是一個(gè)開(kāi)源分布式時(shí)序、時(shí)間和指標(biāo)數(shù)據(jù)庫(kù),使用 Go 語(yǔ)言編寫(xiě),無(wú)需外部依賴(lài)。其設(shè)計(jì)目標(biāo)是實(shí)現(xiàn)分布式和水平伸縮擴(kuò)展。
Telegraf 是收集和報(bào)告指標(biāo)和數(shù)據(jù)的代理。有非常多的插件。Go語(yǔ)言編寫(xiě)。
Kapacitor 是一個(gè)用來(lái)處理、監(jiān)控和警告時(shí)間序列數(shù)據(jù)的開(kāi)源框架。
Chronograf是InfluxData的TICK堆棧的用戶(hù)界面組件。

這一套可視化能力弱于grafana和Kibana,但優(yōu)勢(shì)在于時(shí)序數(shù)據(jù)庫(kù)influxdb以及Telegraf 、Kapacitor。用于物聯(lián)設(shè)備數(shù)據(jù)的存儲(chǔ)還是非常香的。

1. 集成哨兵Sentinel


安裝InfluxDB-默認(rèn)集成其他組件
docker run -d -p 8083:8083 -p 8086:8086 --name my_influxdb influxdb:latestNifi or Kettle
ELT技術(shù)棧,用于業(yè)務(wù)數(shù)據(jù)流轉(zhuǎn)
1. 處理http請(qǐng)求

2. 訂閱binlog實(shí)時(shí)同步

3. 消息中間件交互

4. 文件系統(tǒng)

5. 其他
這里還想整理下Nifi整合Flink的模板,只能以后再搞了。

整理完上述組件,發(fā)現(xiàn)Go語(yǔ)言寫(xiě)的叫得上名的應(yīng)用又增加了不少。Go優(yōu)勢(shì)還是不少呀。這里以后可以看看Go插件化方案,Grafana的前端大屏方案。
往日文章:
