自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

使用Loki promtail 收集Linux原生部署應(yīng)用日志

系統(tǒng) Linux
Promtail是Loki的客戶端代理,它負(fù)責(zé)在Linux服務(wù)器上收集日志。通過在每個(gè)Linux服務(wù)器上安裝和配置Promtail,我們可以將業(yè)務(wù)系統(tǒng)的日志數(shù)據(jù)發(fā)送到Loki進(jìn)行集中存儲(chǔ)和分析。

在Kubernetes集群中部署Loki后,默認(rèn)只能收集Kubernetes集群中的系統(tǒng)日志。然而,對(duì)于在Linux服務(wù)器上原生部署的業(yè)務(wù)系統(tǒng),無法直接進(jìn)行日志收集。這就導(dǎo)致了在日常業(yè)務(wù)交互中需要查詢這些系統(tǒng)的日志時(shí)存在困難。為了解決這個(gè)問題,我們計(jì)劃在Linux服務(wù)器上安裝Promtail來收集日志,并將其推送到Loki,以實(shí)現(xiàn)統(tǒng)一的日志分析和檢索。

Promtail是Loki的客戶端代理,它負(fù)責(zé)在Linux服務(wù)器上收集日志。通過在每個(gè)Linux服務(wù)器上安裝和配置Promtail,我們可以將業(yè)務(wù)系統(tǒng)的日志數(shù)據(jù)發(fā)送到Loki進(jìn)行集中存儲(chǔ)和分析。

圖片圖片

1. 前置依賴

  • Loki 集群,如果不知如何按照,請(qǐng)參考:10分鐘在K8s中部署輕量級(jí)日志系統(tǒng)Loki
  • Linux 服務(wù)器可以訪問Loki集群

2. 下載安裝 promtail

wget https://github.com/grafana/loki/releases/download/v2.7.3/promtail-linux-amd64.zip

3. 解壓并遷移文件至/usr/local/promtail文件夾下

unzip promtail-linux-amd64.zip
mkdir /usr/local/promtail
mv promtail-linux-amd64 /usr/local/promtail

圖片

4. 創(chuàng)建并修改配置文件

vi config.yaml

server:
  http_listen_port: 9080
  grpc_listen_port: 0
#讀取位置保存文件
positions:
  filename: /opt/promtail/positions.yaml # This location needs to be writeable by Promtail.

## 指定推送Loki地址
clients:
  - url: http://172.18.1.47:31300/loki/api/v1/push

scrape_configs:
 - job_name: system
   pipeline_stages:
   #日志換行,匹配開頭
      - multiline:
          firstline: ^\d{1,2}:\d{2}:\d{2}.\d{1,3}
          max_lines: 128
          max_wait_time: 3s   
   #靜態(tài)配置          
   static_configs:
   - targets:
      - localhost
     #定義靜態(tài)標(biāo)簽 
     labels:
      job: smartpark-agent  # A `job` label is fairly standard in prometheus and useful for linking metrics and logs.
      node_name: 172.17.1.55  # A `host` label will help identify logs from this machine vs others
      app: smartpark-agent
      __path__: /data/logs/*log    # The path matching uses a third party library: https://github.com/bmatcuk/doublestar

3.編譯自啟動(dòng)腳本

cat > /usr/lib/systemd/system/promtail.service <<EOF
[Unit]
Descriptinotallow=promtail
Documentatinotallow=https://github.com/grafana/loki/tree/master
After=network.target
 
[Service]
Type=simple
User=root
ExecStart=/usr/local/promtail/promtail-linux-amd64 -config.file=/usr/local/promtail/config.yaml
Restart=on-failure
 
[Install]
WantedBy=multi-user.target
EOF

4.啟動(dòng)命令

#啟動(dòng)
systemctl start promtail
#查看狀態(tài)
systemctl status promtail
#設(shè)置開機(jī)啟動(dòng)
systemctl enable promtail

圖片圖片

5. 查看驗(yàn)證

登錄Grafana在Explore 中選擇標(biāo)簽 app = smartpark-agent, 可以查詢到相關(guān)日志,如下圖

圖片圖片

責(zé)任編輯:武曉燕 來源: 架構(gòu)成長(zhǎng)指南
相關(guān)推薦

2022-12-29 08:00:26

Loki網(wǎng)絡(luò)設(shè)備

2022-06-28 08:40:16

LokiPromtail日志報(bào)警

2025-01-06 10:38:04

2021-05-18 07:30:36

開發(fā)Spring Boot日志

2023-08-31 07:46:54

KubernetesLoki

2024-02-04 00:00:00

Loki性能查詢

2023-12-25 11:18:12

OpenTeleme應(yīng)用日志Loki

2022-06-27 07:33:19

微服務(wù)Loki

2022-05-11 10:58:11

MetricKitiOS13系統(tǒng)崩潰診斷

2022-06-12 21:28:26

Fluentd開源

2025-03-26 08:01:18

2021-07-20 08:32:16

Kubernetes日志平臺(tái)

2021-07-19 09:18:07

KubernetesELK Stackk8s

2021-06-02 06:02:50

Loki 源碼分析日志

2025-02-10 02:00:00

2018-03-09 09:15:16

Linuxsyslog-ng日志

2015-10-19 09:47:39

history企業(yè)日志Linux

2015-10-27 15:54:29

message日志分析Linux

2022-01-10 09:35:50

日志語言解析器

2021-09-13 08:20:13

Loki日志系統(tǒng)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)