iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 7
1
DevOps

遠離 DevOops系列 第 7

[Day 7] Oops!Gitea - Container log to ELK

Q:要將gitea上面的Log輸出到ELK上做查詢分析要怎麼做呢?

由於我們裝gitea的方式是使用docker安裝的,那麼我們只需要透過Filebeat來幫我們將Log輸出到Elasticsearch 就好囉!

Filebeat

Filebeat是用於轉發和集中日誌數據的輕量級傳送程序。作為服務器上的代理安裝,Filebeat監視您指定的日誌文件或位置,收集日誌事件,並將它們轉發到Elasticsearch或 Logstash進行索引。

1. 先ssh進去gitea VM內

2. 先建立 filebeat_docker.yml

這裡先放個簡單的filebeat設定檔

filebeat.config:
  modules:
    path: ${path.config}/modules.d/*.yml
    reload.enabled: false

filebeat.autodiscover:
  providers:
    - type: docker
      hints.enabled: true

processors:
- add_cloud_metadata: ~

setup.template.name: "gitea"
setup.template.pattern: "gitea-*"
setup.ilm.enabled: false

logging.json: true
logging.metrics.enabled: false

output.elasticsearch:
  hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}'
  username: '${ELASTICSEARCH_USERNAME:}'
  password: '${ELASTICSEARCH_PASSWORD:}'
  index: "gitea-%{+yyyy.MM.dd}"

另外有很多設定可以參照官方文件
https://www.elastic.co/guide/en/beats/filebeat/current/elasticsearch-output.html

3. docker command run filebeat


docker run -d \
  --name=filebeat \
  --user=root \
  --volume="$(pwd)/filebeat_docker.yml:/usr/share/filebeat/filebeat.yml:ro" \
  --volume="/mnt/disks/docker/docker/containers:/var/lib/docker/containers:ro" \
  --volume="/var/run/docker.sock:/var/run/docker.sock:ro" \
  docker.elastic.co/beats/filebeat:7.7.1 filebeat -e -strict.perms=false \
  -E output.elasticsearch.hosts=["xxx.xxx.xxx.xxx:9200"]

驗證

這樣 Filebeat 就會把 container log 送到 Elasticsearch 上
之後再依照自訂定義的index去撈出log來看,大概就會長這樣子
https://ithelp.ithome.com.tw/upload/images/20200914/201152890AWYUUP7CQ.png

今日小結

今日我們就先完成gitea container log 輸出到 ELK的步驟囉,是不是很簡單呢?
另外對ELK有想要更了解的讀者們,我推薦 Elastic Stack 是一把梭,用起來再說 系列
/images/emoticon/emoticon01.gif


上一篇
[Day 6] Oops!Gitea - WebHook
下一篇
[Day 8] Oops!Gitea - 專案怎麼那麼肥!?
系列文
遠離 DevOops30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言