「Promtail」:修訂間差異
跳至導覽
跳至搜尋
(未顯示同一使用者於中間所作的 5 次修訂) | |||
第31行: | 第31行: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
最後 | 把本來的<code>/var/log/*log</code>改成更廣的<code>/var/log/**/*log</code>: | ||
<syntaxhighlight lang="yaml"> | |||
scrape_configs: | |||
- job_name: system | |||
static_configs: | |||
- targets: | |||
- localhost | |||
labels: | |||
job: varlogs | |||
__path__: /var/log/**/*log | |||
</syntaxhighlight> | |||
最後要開權限給promtail讀,包括<code>adm</code>與<code>root</code>兩個group: | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
sudo | sudo usermod -aG adm promtail; sudo usermod -aG root promtail | ||
</syntaxhighlight> | </syntaxhighlight> | ||
第48行: | 第61行: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
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@' /etc/promtail/config.yml; sudo service promtail restart | 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 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
於 2023年6月28日 (三) 08:02 的最新修訂
Promtail是Log傳輸軟體,屬於Grafana的Loki生態系。
安裝
在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讀,包括adm
與root
兩個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
相關連結
外部連結
- 官方網站 (英文)