Promtail

出自Gea-Suan Lin's Wiki
跳至導覽 跳至搜尋

Promtail是Log傳輸軟體,屬於GrafanaLoki生態系。

安裝

Ubuntu上可以透過官方的APT repository安裝:

sudo curl -L -o /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key; echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list; sudo apt update; sudo apt install -y promtail; sudo apt clean

設定

先建立狀態目錄:

sudo mkdir /var/lib/promtail; sudo chown promtail:nogroup /var/lib/promtail

/etc/promtail/config.yml裡面把狀態檔案放到/var/lib/promtail下:

positions:
  filename: /var/lib/promtail/positions.yaml

另外把Loki預設的位置改成實際的位置:

clients:
  - url: http://loki.example.com:3100/loki/api/v1/push

把本來的/var/log/*log改成更廣的/var/log/**/*log

scrape_configs:
- job_name: system
  static_configs:
  - targets:
      - localhost
    labels:
      job: varlogs
      __path__: /var/log/**/*log

最後要開權限給promtail讀,包括admroot兩個group:

sudo usermod -aG adm promtail; sudo usermod -aG root promtail

然後重新啟動:

sudo service promtail restart

Cheatsheet

這邊需要把loki.example.com改成自己的Loki服務位置:

sudo curl -L -o /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key; echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list; sudo apt update; sudo apt install -y promtail; sudo apt clean; sudo mkdir /var/lib/promtail; sudo chown promtail:nogroup /var/lib/promtail; sudo sed -i -e 's@filename: /tmp/positions.yaml@filename: /var/lib/promtail/positions.yaml@' -e 's@http://localhost@http://loki.example.com@' -e 's@/var/log/\*log@/var/log/**/*log@' /etc/promtail/config.yml; sudo usermod -aG adm promtail; sudo usermod -aG root promtail; sudo service promtail restart

相關連結

外部連結