当前位置: 首页 > ai >正文

Promtail采集服务器本地日志存储到Loki

✅ 一、前提条件

  1. 已安装 Loki 服务

  2. 日志文件目录可访问(如 /var/log)

  3. 具备 sudo 权限

🧩 二、下载 Promtail 二进制文件

# 替换为你想要的版本
VERSION="3.5.1"# 创建目录
sudo mkdir -p /opt/promtail
cd /opt/promtail# 下载并解压
curl -LO "https://github.com/grafana/loki/releases/download/v${VERSION}/promtail-linux-amd64.zip"
unzip promtail-linux-amd64.zip
mv promtail-linux-amd64 promtail
chmod +x promtail

📦 三、配置 Promtail

创建配置文件 /etc/promtail/promtail.yaml ,示例内容如下:

server:http_listen_port: 9080grpc_listen_port: 0positions:filename: /opt/promtail/positions.yamlclients:- url: http://10.55.2.40:31000/loki/api/v1/pushscrape_configs:- job_name: yarn_logsstatic_configs:- targets:- localhostlabels:job: yarn_logs__path__: /data/yarn/logs/**/**/*.out- targets:- localhostlabels:job: yarn_logs__path__: /data/yarn/logs/**/**/*.err- targets:- localhostlabels:job: yarn_logs__path__: /data/yarn/logs/**/**/*.log

🛠 四、创建 systemd 服务

创建服务文件 /etc/systemd/system/promtail.service:

[Unit]
Description=Promtail service
After=network.target[Service]
Type=simple
ExecStart=/opt/promtail/promtail -config.file=/etc/promtail/promtail.yaml >> /var/log/promtail.log 2>> /var/log/promtail-error.log
Restart=on-failure[Install]
WantedBy=multi-user.target

🚀 五、启动服务

sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable --now promtail

检查状态:

systemctl status promtail

📋 六、验证日志采集

  1. 访问 Loki,确认数据已经送达。

  2. 使用 Grafana 中的 Explore 功能查看日志(需要已连接 Loki 数据源)。

# 移动到日志采集的目录下
[root@uhadoop-1cef6n08gzqc-core1 ~]# cd  /data/yarn/logs/application_1748242101840_0048/container_1748242101840_0048_01_000002 
# 手动写入到sunwenbo.log 日志文件中
[root@uhadoop-1cef6n08gzqc-core1 container_1748242101840_0048_01_000002]# echo "sunwenbo test" >  sunwenbo.log 

http://www.xdnf.cn/news/11870.html

相关文章:

  • 《最长单调子序列》题集
  • 细说C语言将格式化输出到FILE *stream流的函数fprintf、_fprintf_I、fwprintf、_fwprintf_I
  • 轴承排列自动运行 定时器 外中断 PWM部分程序
  • 使用 systemctl 实现程序自启动与自动重启
  • RAG技术解析:实现高精度大语言模型知识增强
  • 【运维实战】Rsync将一台主Web服务器上的文件和目录同步到另一台备份服务器!
  • 数据库基础篇
  • 文件解读|检索页(附:新版知网国内刊检索页下载方法!)
  • cv::FileStorage用法
  • 多线程爬虫使用代理IP指南
  • Java面试题及答案整理( 2025年最新版,持续更新...)
  • PARADISE:用于新生儿缺氧缺血性脑病(HIE)疾病识别与分割的个性化和区域适应性方法|文献速递-深度学习医疗AI最新文献
  • GMS地下水数值模拟及溶质(包含反应性溶质)运移模拟技术
  • Python爬虫之数据提取
  • JavaScript性能优化实战技术
  • LeetCode-934. 最短的桥
  • 【uniapp开发】picker组件的使用
  • 二叉数-965.单值二叉数-力扣(LeetCode)
  • JavaWeb:前端工程化-Vue
  • 舵机在弹簧刀无人机中的作用是什么?
  • Linux 进程调度与管理:从内核管理到调度机制的深度解析
  • 【前端AI实践】泛谈AI在前端领域的应用场景
  • Vue-Todo-list 案例
  • 【QT】-信号传输数组跨线程段错误处理
  • Go语言依赖管理与版本控制-《Go语言实战指南》
  • 【使用 Loki + Promtail + Grafana 搭建轻量级容器日志分析平台】
  • 【Linux系统】命令行参数 和 环境变量(含内建命令介绍)
  • NLP常用工具包
  • video-audio-extractor【源码版】
  • 出口合规管理