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

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.lqws.cn/news/120403.html

相关文章:

  • LeetCode 3370.仅含置位位的最小整数
  • 使用Virtual Serial Port Driver+com2tcp(tcp2com)进行两台电脑的串口通讯
  • AlphaFold3服务器安装与使用(非docker)(1)
  • 模拟搭建私网访问外网、外网访问服务器服务的实践操作
  • Orthanc:轻量级PACS服务器与DICOMweb支持的技术详解
  • Spring Framework 中 UriComponentsBuilder工具类
  • Educational Codeforces Round 179 (Rated for Div. 2)(A-E)
  • Python训练营打卡DAY44
  • DuckDB + Spring Boot + MyBatis 构建高性能本地数据分析引擎
  • 掌握 MotionLayout:交互动画开发
  • UniApp 全生命周期钩子详解
  • python版若依框架开发:python版若依部署
  • 【后端开发】goland分布式锁的几种实现方式(mysql,redis,etcd,zookeeper,mq,s3)
  • #Java篇:学习node后端之sql常用操作
  • 前端面试三之控制语句
  • Linux kill 暂停命令
  • vue3+elementplus表格表头加图标及文字提示
  • Starrocks中RoaringBitmap杂谈
  • Spring Boot MVC自动配置与Web应用开发详解
  • 低代码采购系统搭建:鲸采云+能源行业订单管理自动化案例
  • 国产三维CAD皇冠CAD在「金属压力容器制造」建模教程:蒸汽锅炉
  • setting up Activiti BPMN Workflow Engine with Spring Boot
  • 一起学Spring AI:核心概念
  • 沉金PCB电路板制造有哪些操作要点需要注意?
  • 中小制造企业转型:低成本国产工业软件替代方案实践
  • 力扣刷题Day 70:在排序数组中查找元素的第一个和最后一个位置(34)
  • 如何借助Hyper - V在Windows 10中构建安全软件测试环境
  • parquet :开源的列式存储文件格式
  • [蓝桥杯]密文搜索
  • ios版本的Tiktok二次安装不上,提示:Unable to Install “TikTok”