- 作用:代理,监控日志文件,将日志内容传输到loki中
安装在产生日志的服务器上
安装promtail
安装promtail包
解压
创建config.yml文件
curl -O -L "https://github.com/grafana/loki/releases/download/v2.9.1/promtail-linux-amd64.zip"
apt install unzip
unzip promtail-linux-amd64.zip
chmod +x promtail-linux-amd64
sudo mv promtail-linux-amd64 /usr/local/bin/promtail
cd /etc
mkdir promtail
cd promtail
vim config.yml
创建配置文件
config.yml
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /var/log/positions.yaml
clients:
- url: http://{收集日志的loki服务器ip}/loki/api/v1/push
batchsize: 1048576
batchwait: 5s
scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: job_name # 该日志的标签名
__path__: /data/log # 需要监控传输的日志文件
注意loki的url,如果配置了nginx,注意nginx转发问题
创建systemd 服务文件
vim /etc/systemd/system/promtail.service
promtail.service
[Unit]
Description=Promtail service
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/promtail -config.file /etc/promtail/config.yml # promtail的config配置文件路径
Restart=on-failure
MemoryLimit=128M
[Install]
WantedBy=multi-user.target
启动promtail服务
systemctl daemon-reload
systemctl start promtail
systemctl enable promtail
systemctl status promtail 查看状态
# systemctl restart promtail 重启服务
# journalctl -u promtail.service -f 查看启动日志