@cdmonkey
2022-11-22T02:22:55.000000Z
字数 5188
阅读 735
Loki
创建用户:
useradd promtail -s /sbin/nologin -M
[root@myloki tools]# mkdir -pv /opt/promtail[root@myloki tools]# unzip promtail-linux-amd64.zip[root@myloki tools]# mv promtail-linux-amd64 /opt/promtail/
[root@myloki ~]# vim /etc/systemd/system/promtail.service[Unit]Description=Promtail serviceAfter=network.target[Service]Type=simpleUser=promtailExecStart=/opt/promtail/promtail-linux-amd64 -config.file /opt/promtail/promtail.ymlRestart=on-failureLimitNOFILE=100000LimitNPROC=100000[Install]WantedBy=multi-user.target
配置文件下载:
https://github.com/grafana/loki/tree/main/clients/cmd/promtail
# 配置 Promtail 服务端[server: <server_config>]# 描述 Promtail 怎样连接至 Loki 的多个实例,向每个实例发送日志。# WARNING:若是其中一个远程 Loki 服务器未能回应或回应时出有可重试的错误,这将影响其他配置的远程 Loki 服务器发送日志。# 发送是于单线程上完成的!# 若是你想向多个远程 Loki 实例发送,一般建议并行运行多个 Promtail 客户端。clients:- [<client_config>]# 描述了怎样将读入的文件偏移量保存至硬盘上[positions: <position_config>]scrape_configs:- [<scrape_config>]# 配置被 watch 的目标如何 tailed[target_config: <target_config>]
配置 Promtail 作为一个 http 服务器时的行为。
# 禁用 HTTP 及 GRPC 服务[disable: <boolean> | default = false][http_listen_address: <string>] # HTTP 服务监听的主机/地址[grpc_listen_address: <string>] # gRPC 服务监听的主机/地址[http_listen_port: <int> | default = 80] # HTTP 服务监听端口,0 表示随机[grpc_listen_port: <int> | default = 9095] # gRPC 服务监听端口,0 表示随机# 注册指标处理器 (/metrics, etc.)[register_instrumentation: <boolean> | default = true][graceful_shutdown_timeout: <duration> | default = 30s] # 优雅退出超时时间[http_server_read_timeout: <duration> | default = 30s] # HTTP 服务读出超时时间[http_server_write_timeout: <duration> | default = 30s] # HTTP 服务写入超时时间[http_server_idle_timeout: <duration> | default = 120s] # HTTP 服务空闲超时时间[grpc_server_max_recv_msg_size: <int> | default = 4194304] # 可接收之最大 gRPC 消息大小[grpc_server_max_send_msg_size: <int> | default = 4194304] # 可发送之最大 gRPC 消息大小# 对 gRPC 调用的并发流数量之限制 (0 = unlimited)[grpc_server_max_concurrent_streams: <int> | default = 100]# 只记录给定严重程度或以上之信息,可选值: debug, info, warn, error[log_level: <string> | default = "info"]# 所有 API 路由服务之基本路径 (e.g., /v1/)[http_path_prefix: <string>]# 目标管理器检测 Promtail 可读的标志,若是设置为 false 检查将被忽略[health_check_target: <bool> | default = true]
配置 Promtail 怎样连接至 Loki 的实例。
# 其实就是 Loki 监听之 URL,Loki 中表示为 http_listen_address、http_listen_port# 若是 Loki 于微服务模型下运行,这就是 Distributor 的 URL,需要包括 push API 路径# 就像: http://example.com:3100/loki/api/v1/pushurl: <string># 缺省租户 ID,用于推送日志至 Loki# 若是省略或是为空,则假设 Loki 于单租户模型下运行,不发送 X-Scope-OrgID 头信息[tenant_id: <string>]# 发送一批日志前的最大等待时间,即使该批次日志数据未满[batchwait: <duration> | default = 1s]# 向 Loki 发送批处理之前要积累之最大批处理量(单位为字节)[batchsize: <int> | default = 1048576]# 若使用了 basic auth 认证,则需要配置用户名及密码basic_auth:[username: <string>][password: <string>][password_file: <filename>] # 包含 basic auth 认证之密码文件# 可选的 OAuth 2.0 配置# 不能同 basic_auth、authorization 同时使用oauth2:[client_id: <string>][client_secret: <secret>][client_secret_file: <filename>]scopes: # 令牌请求的可选范围[ - <string> ... ]token_url: <string>endpoint_params: # 附加至令牌 URL 的可选参数[ <string>: <string> ... ][bearer_token: <secret>] # 发送给服务器的 Bearer token[bearer_token_file: <filename>] # 包含 Bearer token 的文件# 用来连接服务器的 HTTP 代理服务器[proxy_url: <string>]# 配置 TLStls_config:[ca_file: <string>][cert_file: <filename>][key_file: <filename>][server_name: <string>][insecure_skip_verify: <boolean> | default = false]# 配置于请求失败时要怎样重试对 Loki 之请求# 默认回退周期为: 0.5s, 1s, 2s, 4s, 8s, 16s, 32s, 64s, 128s, 256s(4.267m)# 于日志丢失之前的总时间为 511.5s(8.5m)backoff_config:[min_period: <duration> | default = 500ms] # 重试之间之初始回退时间[max_period: <duration> | default = 5m] # 重试之间之最大回退时间[max_retries: <int> | default = 10] # 重试之最大次数# 配置所有发送至 Loki 的日志中的静态标签# 使用一个类似于 {"foo": "bar"} 的映射来配置一个 foo 标签,值为 bar# 这些也能从命令行中指定: -client.external-labels=k1=v1,k2=v2 (或是 --client.external-labels 依赖操作系统)# 由命令行提供的标签将应用于所有在 "clients" 部分的配置# 注意:若是标签键相同,配置文件中的定义将替代命令行中相关配置external_labels:[ <labelname>: <labelvalue> ... ]# 等待服务器响应一个请求之最长时间[timeout: <duration> | default = 10s]# 要包含于流滞后指标 promtail_stream_lag_seconds 中的用逗号分隔之标签列表# 默认值为 filename。始终包含 host 标签# 流滞后指标指示哪些流落后于写入 Loki# 注意使用太多标签,因为它会增加基数[stream_lag_labels: <string> | default = "filename"]
配置了 Promtail 保存文件之位置,表示它已经读至文件什么程度。当 Promtail 重新启动时需要它,以允许它从中断处继续读入日志。
# Positions 文件之路径[filename: <string> | default = "/var/log/positions.yaml"]# 更新 positions 文件之周期[sync_period: <duration> | default = 10s]# 是否忽略并覆盖被破坏的 positions 文件[ignore_invalid_yaml: <boolean> | default = false]
配置了 Promtail 将怎样使用指定的发现方法从一系列目标中抓获日志。
# 用于 Promtail UI 中识别该抓获配置的名称job_name: <string># 配置如何对目标日志进行结构化[pipeline_stages: <pipeline_stages>][journal: <journal_config>] # 配置如何从 jounal 中抓获日志[syslog: <syslog_config>] # 配置如何从 syslog 中抓获日志# 配置如何通过 Loki Push API 接收日志(例如从其他 Promtail 或是 Docker Logging Driver 中获得的数据)[loki_push_api: <loki_push_api_config>]# 配置如何从 Windows 事件日志中抓获日志[windows_events: <windows_events_config>]# 配置如何通过消费者组从 Kafka 获得日志[kafka: <kafka_config>]# 配置如何 relabel 目标,以确定是否应该对其进行处置relabel_configs:- [<relabel_config>]# 抓获日志静态目标配置static_configs:- [<static_config>]# 包含要抓获的目标文件file_sd_configs:- [<file_sd_configs>]# 配置了如何发现于同一主机上运行的 Kubernetes 服务kubernetes_sd_configs:- [<kubernetes_sd_config>]# 配置如何使用 Consul Catalog API 发现注册至 Consul 集群的服务consul_sd_configs:[ - <consul_sd_config> ... ]# 配置如何使用 Consul Agent API 发现同 Promtail 运行于同一主机上的 consul 代理注册的服务consulagent_sd_configs:[ - <consulagent_sd_config> ... ]
用于控制从目标读入文件之行为。就是怎样从目标处读入文件内容。
# Period to resync directories being watched and files being tailed to discover# new ones or stop watching removed ones.sync_period: "10s"
参考内容:
https://jishuin.proginn.com/p/763bfbd5863b
https://cloud.tencent.com/developer/article/1824988
https://grafana.com/docs/loki/latest/clients/promtail/installation
https://grafana.com/docs/loki/latest/clients/promtail/configuration