x213212
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# ELK 日誌分析 服務 ![](https://i.imgur.com/B6HfPUc.png) 本來想用kafka 看看的,睡醒在弄看看吧 ![](https://i.imgur.com/U1tqb5j.png) 目前整個架構就這樣 # 初步介紹 查看日誌的傳統方法是:登錄操作系統,使用命令工具如cat、tail、sed、awk、grep等等進行過濾輸出後分析,處理少量日誌還好,日誌量大處理效率就沒那麼高了。而且很多情況下開發人員需要查看並分析日誌進行排錯,但他們對Linux命令又不是太熟悉,而且有時候又不能賦予他們服務器權限,更多時候是運維把日誌文件導出來發給開發人員,這無疑會給我們增加工作量。 ELK(Elasticsearch+Logstash+Kibana)架構就是專門為採集、分析、存儲日誌所設計的: Elasticsearch:基於Lucenne的搜索服務器,提供一個分佈式多用戶的全文搜索引擎,能過做到實時搜索。 Logstash:可以對日誌進行採集、過濾、輸出。 Kibana:可以匯總、分析、搜索日誌數據並提供友好的web界面。 工作流程:logstash agent監控並過濾日誌,為了保證日誌的完整性先將日誌內容輸出到RabbitMQ進行存儲;logstash indexer再把RabbitMQ上的日誌隊列收集後發送給全文搜索服務器Elasticsearch,然後可以用Elasticsearch進行自定義搜索,再通過Kibana來結合自定義搜索進行頁面展示。 # 安裝 ELK 這邊我們使用 docker 主要就是 解決 維運和 開發工程師 環境的不同而弄出來的東西,在微服務時代中可以快速部屬(好像是這樣 然後我也懶得架在linux 開發版了,直接用 docker 比較快一點 順便複習一下 **docker **,之前在安裝 **redis** 有用到, 參考:https://www.jianshu.com/p/18778a8ee6f0 玩了快一天 : windows10 subsystem Linux不行 ai開發版不行 windows 10 home 家用版 不行 終於可以 關hyper 開 docker 可以 下次我要灌專業版了,目前灌的是預覽版 一堆正常 docker 都不能裝 elk 我找了半天 找了台灣人 https://github.com/twtrubiks/docker-elk-tutorial 只能她的 docker 可以用 ,其他版本的 elk 記憶體要求過大 ,還沒進容器裡就掛了,他裡面還有用 docker-compose 我來小魔改一下,最下面有蒐集的 資料大該就那些範圍 # docker docker 的網路有三種模式,先挖坑, 這邊的容器可以看到跟一般不同,學習一下這種方式, 我用 docker tool 是不能把端口映射到我的電腦上, 除非 nginx (創辦人好像被告了 或其他 gateway https://github.com/x213212/elk 安裝只要 ``` docker-compose up docker-compose down ``` 他預設會抓docker-compose.yml 也就是下面的東東 ``` version: '2' services: elasticsearch: build: context: elasticsearch/ volumes: - ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro ports: - "9200:9200" - "9300:9300" environment: ES_JAVA_OPTS: "-Xmx256m -Xms256m" networks: - elk logstash: build: context: logstash/ volumes: - ./logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml:ro - ./logstash/pipeline:/usr/share/logstash/pipeline:ro ports: - "5000:5000" environment: LS_JAVA_OPTS: "-Xmx256m -Xms256m" networks: - elk depends_on: - elasticsearch kibana: build: context: kibana/ volumes: - ./kibana/config/:/usr/share/kibana/config:ro ports: - "5601:5601" networks: - elk depends_on: - elasticsearch rabbitmq : build: context: rabbitmq / volumes: - ./rabbitmq/config/:/usr/share/rabbitmq/config:ro ports: - "5672:5672" - "15672:15672" networks: - elk depends_on: - elasticsearch networks: elk: driver: bridge ``` 這個解決完後大概他會去抓四個程式 rabbitmq Elasticsearch Logstash Kibana ![](https://i.imgur.com/J0fLq4i.png) 沒意外 ,我都調好了 # Logstash.conf 這個真的雷 全形半形沒log 可以除錯只能用猜的 ```conf input { tcp { port => 5000 } rabbitmq { type => "all" durable => true exchange => "ex_logstash" exchange_type => "direct" key => "lgstash" host => "192.168.99.100" user => guest password => guest queue => "faceJob-logstash" auto_delete => false } } ## Add your filters / logstash plugins configuration here output { elasticsearch { hosts => "elasticsearch:9200" } } ``` # Kibana.yml ```yml --- ## Default Kibana configuration from kibana-docker. ## from https://github.com/elastic/kibana-docker/blob/master/build/kibana/config/kibana.yml # server.name: kibana server.host: "0" elasticsearch.url: http://elasticsearch:9200 ``` # Elasticsearch ``` --- ## Default Elasticsearch configuration from elasticsearch-docker. ## from https://github.com/elastic/elasticsearch-docker/blob/master/build/elasticsearch/elasticsearch.yml # cluster.name: "docker-cluster" network.host: 0.0.0.0 # minimum_master_nodes need to be explicitly set when bound on a public IP # set to 1 to allow single node clusters # Details: https://github.com/elastic/elasticsearch/pull/17288 discovery.zen.minimum_master_nodes: 1 ## Use single node discovery in order to disable production mode and avoid bootstrap checks ## see https://www.elastic.co/guide/en/elasticsearch/reference/current/bootstrap-checks.html # discovery.type: single-node ``` 好了之後配置我們的 logback # logback-spring.xml 有用log的地方都可以加,依樣放在 resources ``` <?xml version="1.0" encoding="UTF-8"?> <configuration> <!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径--> <property name="LOG_HOME" value="d:/" /> <!-- 控制台输出 --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <!--格式化输出,%d:日期;%thread:线程名;%-5level:级别,从左显示5个字符宽度;%msg:日志消息;%n:换行符--> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> </encoder> </appender> <appender name="RABBITMQ" class="org.springframework.amqp.rabbit.logback.AmqpAppender"> <layout> <pattern><![CDATA[ %d %p %t [%c] - <%m>%n ]]></pattern> </layout> <!--rabbitmq地址 --> <addresses>192.168.99.100:5672</addresses> <username>guest</username> <password>guest</password> <declareExchange>true</declareExchange> <exchangeType>direct</exchangeType> <exchangeName>ex_logstash</exchangeName> <routingKeyPattern>lgstash</routingKeyPattern> <generateId>true</generateId> <charset>UTF-8</charset> <durable>true</durable> <deliveryMode>NON_PERSISTENT</deliveryMode> <autoDelete>false</autoDelete> </appender> <logger name="com.light.rabbitmq" level="info" additivity="false"> <appender-ref ref="STDOUT"/> <appender-ref ref="RABBITMQ"/> </logger> <!-- 日志输出级别,level 默认值 DEBUG,root 其实是 logger,它是 logger 的根 --> <root level="INFO"> <appender-ref ref="STDOUT" /> <appender-ref ref="RABBITMQ" /> </root> </configuration> ``` 這個原理日後再探討,又是另一個坑了下次再玩先把框架先大致弄完 # rabbitmq 記得加我們的 Excanges ![](https://i.imgur.com/Jkh4KRg.png) 還有我們的 Quenues ![](https://i.imgur.com/Y7RJNgC.png) 這邊設定好就差不多了 最重要的binding ![](https://i.imgur.com/c7Czrzd.png) # 啟動 elasticsearch ![](https://i.imgur.com/MVjStnD.png) rabbitmq ![](https://i.imgur.com/AbabwXZ.png) kibana ![](https://i.imgur.com/f0hVJBV.png) # debug 區 ![](https://i.imgur.com/raUDbIq.png) gg ![](https://i.imgur.com/1C3iQMi.png) arm開發版目前不支援 目前版本 用 vm囉裡面再用 docker 我們裝在 win10子系統 https://www.itread01.com/content/1543061166.html https://blog.walterlv.com/post/how-to-install-wsl2.html 切成 WSL2 https://www.pigo.idv.tw/archives/3359 之前的 WSL 不能跑 DOCKER 現在 切成 WSL2 就可以跑了 https://blog.yowko.com/cannot-connect-docker-daemon/ https://medium.com/faun/docker-running-seamlessly-in-windows-subsystem-linux-6ef8412377aa ``` ![](https://i.imgur.com/zw2hL5H.png) ```code docker pull sebp/elk docker run -p 5601:5601 -p 9200:9200 -p 5044:5044 -e ES_MIN_MEM=128m  -e ES_MAX_MEM=1024m -it --name elk sebp/elk ``` ![](https://i.imgur.com/TAYcnbB.png) ![](https://i.imgur.com/4orRMD2.png) 1、执行命令:docker pull sebp/elk 将镜像pull到本地来; 2、执行命令:docker run -p 5601:5601 -p 9200:9200 -p 5044:5044 -e ES_MIN_MEM=128m  -e ES_MAX_MEM=1024m -it --name elk sebp/elk 将镜像运行为容器,由于我本机内存不符合安装要求,为了保证ELK能够正常运行,加了-e参数限制使用最小内存及最大内存。 3、打开浏览器,输入:http://<your-host>:5601,看到图形化解面即安装成功 vm.max_map_count至少需要262144.否則啟動時會報錯。 設定方式: sudo vi /etc/sysctl.conf 增加 : vm.max_map_count = 262144 fs.file-max = 65536 docker exec -it elk /bin/bash ![](https://i.imgur.com/8wV8KzI.png)

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully