Promtail 部署
目前promtail支持docker、kubernetes、helm、二进制等方式部署
因为是用的是小鸡,没有docker这些环境所以只能选择使用二进制安装
二进制安装
- 从GitHub Release页面下载二进制: https://github.com/grafana/loki/releases
- 编辑配置文件,因为是白嫖Grafana 50G,需要先去申请账号获取token最后生成配置文件
server:
http_listen_port: 0
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: https://660292:{{generate_token}}@{{url}}/loki/api/v1/push
scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
__path__: /var/log/*.log
- 测试运行
./promtail -config.file /etc/promail/config.yaml
level=info ts=2023-12-21T04:08:52.104321127Z caller=promtail.go:133 msg="Reloading configuration file" md5sum=71b22e75632703d90a329f758fb174e9
level=info ts=2023-12-21T04:08:52.106567909Z caller=server.go:334 http=[::]:42697 grpc=[::]:44267 msg="server listening on addresses"
level=info ts=2023-12-21T04:08:52.107374432Z caller=main.go:174 msg="Starting Promtail" version="(version=2.8.7, branch=HEAD, revision=1dfdc432c)"
level=warn ts=2023-12-21T04:08:52.107617798Z caller=promtail.go:265 msg="enable watchConfig"
level=info ts=2023-12-21T04:08:57.107133441Z caller=filetargetmanager.go:358 msg="Adding target" key="/var/log/sonic/*.log:{job=\"varlogs\"}"
level=info ts=2023-12-21T04:08:57.107606881Z caller=filetarget.go:285 msg="watching new directory" directory=/var/log/sonic
ts=2023-12-21T04:08:57.108067581Z caller=log.go:168 level=info msg="Seeked /var/log/sonic/sonic.log - &{Offset:464553 Whence:0}"
level=info ts=2023-12-21T04:08:57.108211575Z caller=tailer.go:143 component=tailer msg="tail routine: started" path=/var/log/sonic/sonic.log
在Grafana上面查看Loki源是否收到
Systemd管理Promtail
将上一步解压出来的Promtail二进制复制到/usr/local/bin/
,添加systemd管理
cat > /etc/systemd/system/promtail.service << EOF
[Unit]
Description=Promtail Service
Documentation=https://github.com/grafana/loki
After=network.target nss-lookup.target
[Service]
User=root
ExecStart=/usr/local/bin/promtail -config.file /etc/promail/config.yaml
Restart=on-failure
RestartPreventExitStatus=23
[Install]
WantedBy=multi-user.target
EOF
设置开机自启动
systemctl enable promtail
# 启动promtail
systemctl start promtail
# 查看状态
systemctl status promtail
至此就可以开始快乐的白嫖Grafana Lab 50G了~
除了日志,还可以收集Trace、Metrics等数据,做成告警~