「Promtail」:修訂間差異

出自Gea-Suan Lin's Wiki
跳至導覽 跳至搜尋
本頁面具有訪問限制。如果您看見此訊息,這代表您沒有訪問本頁面的權限。
(创建页面,内容为“'''Promtail'''是Log傳輸軟體,屬於GrafanaLoki生態系。 == 相關連結 == * Grafana * Loki == 外部連結 == * {{Official|https://grafana.com/docs/loki/latest/clients/promtail/}} {{en}} Category:軟體”)
 
 
(未顯示同一使用者於中間所作的 17 次修訂)
行 1: 行 1:
'''Promtail'''是Log傳輸軟體,屬於[[Grafana]]的[[Loki]]生態系。
'''Promtail'''是Log傳輸軟體,屬於[[Grafana]]的[[Loki]]生態系。
== 安裝 ==
在[[Ubuntu]]上可以透過官方的APT repository安裝:
<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
</syntaxhighlight>
== 設定 ==
先建立狀態目錄:
<syntaxhighlight lang="bash">
sudo mkdir /var/lib/promtail; sudo chown promtail:nogroup /var/lib/promtail
</syntaxhighlight>
在<code>/etc/promtail/config.yml</code>裡面把狀態檔案放到<code>/var/lib/promtail</code>下:
<syntaxhighlight lang="yaml">
positions:
  filename: /var/lib/promtail/positions.yaml
</syntaxhighlight>
另外把[[Loki]]預設的位置改成實際的位置:
<syntaxhighlight lang="yaml">
clients:
  - url: http://loki.example.com:3100/loki/api/v1/push
</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">
sudo usermod -aG adm promtail; sudo usermod -aG root promtail
</syntaxhighlight>
然後重新啟動:
<syntaxhighlight lang="bash">
sudo service promtail restart
</syntaxhighlight>
== Cheatsheet ==
這邊需要把<code>loki.example.com</code>改成自己的[[Loki]]服務位置:
<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@' -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>


== 相關連結 ==
== 相關連結 ==

於 2023年6月28日 (三) 08:02 的最新修訂

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

相關連結

外部連結