iLogtail

1769
下载
iLogtail 是阿里云日志服务(Log Service)中的一款高性能、可扩展的日志采集工具。它被设计用于实时收集、解析和传输各类日志数据,支持多种数据源和复杂的日志处理场景,广泛应用于分布式系统、Web 服务器、应用程序等环境中的日志管理。

Docker使用


使用前提

已安装docker

采集Docker容器日志

  1. 准备iLogtail配置目录 新建配置目录config目录,在目录中创建file_simple.yamlstdout_simple.yaml。 在file_simple.yaml中配置采集容器中的simple.log到标准输出。
enable: true
inputs:
- Type: input_file # 文件输入类型
FilePaths:
- ./simple.log
flushers:
- Type: flusher_stdout # 标准输出流输出类型
OnlyStdout: true

stdout_simple.yaml中配置采集容器标准输出并输出到simple.stdout文件。

enable: true
inputs:
- Type: service_docker_stdout # 容器标准输出流输入类型
Stderr: false # 不采集标准错误流
Stdout: true # 采集标准输出流
flushers:
- Type: flusher_stdout # 标准输出流输出类型
FileName: simple.stdout # 重定向文件名

您也可以直接从下面的地址下载示例配置。

Terminal window
mkdir config && cd config
wget https://raw.githubusercontent.com/alibaba/ilogtail/main/example_config/start_with_docker/config/file_simple.yaml
wget https://raw.githubusercontent.com/alibaba/ilogtail/main/example_config/start_with_docker/config/stdout_simple.yaml
cd -
  1. 启动iLogtail容器,并挂载iLogtail配置目录
Terminal window
docker run -d --name docker_ilogtail \
-v /:/logtail_host:ro \
-v /var/run:/var/run \
-v /var/lib/docker_ilogtail/checkpoint:/usr/local/ilogtail/checkpoint \
-v `pwd`/config:/usr/local/ilogtail/config/local \
sls-opensource-registry.cn-shanghai.cr.aliyuncs.com/ilogtail-community-edition/ilogtail:latest

第1行-d参数表示后台启动iLogtail容器,—name指定容器名称以便引用。
第2行将主机/目录挂载到iLogtail容器中,iLogtail依赖logtail_host路径采集容器日志。
第3行将主机/var/run目录挂载到iLogtail容器中,iLogtail依赖/var/run目录与容器引擎通信。
第4行将主机目录挂载到容器中iLogtail的checkpoint目录,使采集状态在容器重启时可恢复。
第5行将配置目录挂载到iLogtail容器中。

  1. 查看ilogtail_docker容器自身标准输出日志
Terminal window
docker logs docker_ilogtail

结果为

delay stop seconds: 0
ilogtail started. pid: 10
register fun v2 0xa34f3c 0xa34f86 0xa34fdc 0xa35576
2022/07/14 16:23:17 DEBUG Now using Go's stdlib log package (via loggers/mappers/stdlib).
load log config /usr/local/ilogtail/plugin_logger.xml
recover stderr
recover stdout
  1. 进入iLogtail容器
Terminal window
docker exec -it docker_ilogtail bash
  1. 查看采集到的标准输出
Terminal window
cat /usr/local/ilogtail/simple.stdout

结果为

2022-07-14 16:23:20 {"content":"delay stop seconds: 0","_time_":"2022-07-14T16:23:17.704235928Z","_source_":"stdout","_image_name_":"sls-opensource-registry.cn-shanghai.cr.aliyuncs.com/ilogtail-community-edition/ilogtail:1.1.0","_container_name_":"docker_ilogtail","_container_ip_":"172.17.0.2","__time__":"1657815797"}
2022-07-14 16:23:20 {"content":"ilogtail started. pid: 10","_time_":"2022-07-14T16:23:17.704404952Z","_source_":"stdout","_image_name_":"sls-opensource-registry.cn-shanghai.cr.aliyuncs.com/ilogtail-community-edition/ilogtail:1.1.0","_container_name_":"docker_ilogtail","_container_ip_":"172.17.0.2","__time__":"1657815797"}
2022-07-14 16:23:20 {"content":"recover stdout","_time_":"2022-07-14T16:23:17.847939016Z","_source_":"stdout","_image_name_":"sls-opensource-registry.cn-shanghai.cr.aliyuncs.com/ilogtail-community-edition/ilogtail:1.1.0","_container_name_":"docker_ilogtail","_container_ip_":"172.17.0.2","__time__":"1657815797"}
  1. 构造示例日志
Terminal window
echo 'Hello, iLogtail!' >> /root/simple.log
  1. 查看采集到的容器文件日志 跳出容器,在宿主机上执行
Terminal window
docker logs docker_ilogtail

结果相比第3步的结果,多了

2022-07-14 16:26:20 {"__tag__:__path__":"/root/simple.log","content":"Hello, iLogtail!","__time__":"1657815980"}

采集模版

了解采集配置结构:采集配置

参考更多可组合的日志采集和处理配置样例:https://github.com/alibaba/ilogtail/blob/main/example_config


observability.cn Authors 2024 | Documentation Distributed under CC-BY-4.0
Copyright © 2017-2024, Alibaba. All rights reserved. Alibaba has registered trademarks and uses trademarks.
浙ICP备2021005855号-32