惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
月光博客
月光博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
博客园 - Franky
The GitHub Blog
The GitHub Blog
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog
B
Blog RSS Feed
云风的 BLOG
云风的 BLOG
小众软件
小众软件
罗磊的独立博客
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
美团技术团队
H
Hackread – Cybersecurity News, Data Breaches, AI and More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
C
Check Point Blog
WordPress大学
WordPress大学
博客园 - 【当耐特】
博客园 - 司徒正美
D
Docker

灰叶的笔记

Linux逻辑卷2-扩容/常用命令汇总 | 灰叶的笔记 Dockerfile 容器镜像构建 | 灰叶的笔记 Linux 查看内存和实际物理内存大小不一致 | 灰叶的笔记 GCP创建泛域名证书(域名托管在CloudFlare) | 灰叶的笔记 Docker基础指令-镜像相关 | 灰叶的笔记 Docker基础指令-容器相关 | 灰叶的笔记 GCP和AWS使用PCCW专线互联 | 灰叶的笔记 vim编辑器常用操作 | 灰叶的笔记 Linux主机是否被入侵的11个排查步骤 | 灰叶的笔记 Ubuntu 安装 Docker-CE | 灰叶的笔记 Fail2Ban-Linux防SSH暴力破解工具 | 灰叶的笔记 公用云Linux快照创建磁盘挂载问题 | 灰叶的笔记 ubuntu 安装图形化桌面 | 灰叶的笔记 iptables基础命令与filter表相关命令 | 灰叶的笔记 Linux逻辑卷 | 灰叶的笔记 UCloud CentOS6.X修改hostname | 灰叶的笔记 软件源安装Dokcer | 灰叶的笔记 Ubuntu系统启用root用户ssh远程登录 | 灰叶的笔记 Windows Server关闭IE增强 | 灰叶的笔记 windows云服务器开启媒体声音 | 灰叶的笔记 MySQL5.7多实例部署 | 灰叶的笔记 nc网络工具 | 灰叶的笔记 WinServer2008云服务器系统盘可压缩空间不足 | 灰叶的笔记 Rocky Linux8.5 UCloud官方镜像进入单用户模式 | 灰叶的笔记 UCloud官方Linux 镜像进入单用户模式汇总 | 灰叶的笔记 Debian10 UCloud官方镜像进入单用户模式 | 灰叶的笔记 CentOS6 UCloud官方镜像进入单用户模式 | 灰叶的笔记 CentOS7/8 UCloud官方镜像进入单用户模式 | 灰叶的笔记 Ubuntu UCloud官方镜像进入单用户模式 | 灰叶的笔记 几个检查本机的网络连接的工具(linux) | 灰叶的笔记
使用 OpenTelemetry 采集日志推送至 GCP Cloud Logging | 灰...
huiye · 2025-04-02 · via 灰叶的笔记

背景

本文档面向 GCP 平台,旨在帮助工程师快速安装部署 openTelemetry 工具,进行本地或者多云机器的系统日志采集并推送至 GCP cloud logging

准备步骤

说明:若已创建过服务账号并已有JSON密钥文件,此步骤可以略过

1、创建服务账号

在 IAM 和管理 的 服务账号 中创建具有 Logging AdminMonitoring Metric Writer 权限的服务账号

2、创建密钥

二、安装 otelcol-contrib

下载对应版本的 otelcol-contrib 并安装。其他版本安装包见 参考 [4]。步骤二、三 建议使用 root 用户操作

Debian/Ubuntu x86_64

wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.121.0/otelcol-contrib_0.121.0_linux_amd64.deb
sudo dpkg -i otelcol-contrib_0.121.0_linux_amd64.deb

REHL/CentOS/Rocky x86_64

wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.121.0/otelcol-contrib_0.121.0_linux_amd64.rpm
rpm -ivh otelcol-contrib_0.121.0_linux_amd64.rpm

三、设置 otelcol-contrib

1、修改 otelcol-contrib 配置文件

配置文件路径

/etc/otelcol-contrib/config.yaml

一个简单的系统日志采集配置文件参考。更多配置项见 参考[1]

receivers:
  filelog:
    include:
      - /var/log/1.log      #指定监听的日志路径,可用通配符
      - /var/log/2.log      #可指定多个日志文件
processors:
  batch:
    send_batch_size: 1000
    timeout: 10s
  resourcedetection:
    detectors: [system, env]
    system:
      hostname_sources: [os]

exporters:
  googlecloud:
    log:
      default_log_name: rocky-log-test  #日志名称可自定义,方便在cloudlogging里查询

service:
  pipelines:
    logs:
      receivers: [filelog]
      processors: [resourcedetection, batch]
      exporters: [googlecloud]

2、设置 otelcol-contrib systemd服务

将步骤一里申请的密钥上传至服务器,并设置 otelcol-contrib 服务

vim /usr/lib/systemd/system/otelcol-contrib.service

在 [Service] 下将 User 和 Group 修改为 root ,再添加一行 Environment,指定密钥文件路径,如下所示

[Unit]
Description=OpenTelemetry Collector Contrib
After=network.target

[Service]
EnvironmentFile=/etc/otelcol-contrib/otelcol-contrib.conf
ExecStart=/usr/bin/otelcol-contrib $OTELCOL_OPTIONS
KillMode=mixed
Restart=on-failure
Type=simple
User=root
Group=root
Environment="GOOGLE_APPLICATION_CREDENTIALS=/path/xxxxx.json"

[Install]
WantedBy=multi-user.target

修改完成后重载 systemd

3、启动 otelcol-contrib

systemctl start otelcol-contrib

四、Cloud Logging 上查看日志

在 cloud logging 中可使用设置的 default_log_name 去查询对应机器的日志

参考

[1] opentelemetry-collector-contrib-GoogleCloudExporter:

https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/exporter/googlecloudexporter/README.md

[2] 为本地或其他云服务提供商设置 ADC:

https://cloud.google.com/docs/authentication/set-up-adc-on-premises?hl=zh-cn

[3] opentelemetry官方文档:

https://opentelemetry.io/docs

[4] opentelemetry github下载地址:

https://github.com/open-telemetry/opentelemetry-collector-releases/releases