#生成工作目录
sudo mkdir -p /app/loki/config
sudo mkdir -p /app/loki/data
sudo chmod -R 777 /app/loki
#下载配置
wget https://raw.githubusercontent.com/grafana/loki/v3.0.0/cmd/loki/loki-local-config.yaml -O /app/loki/config/loki-config.yaml
#添加配置到loki-config.yaml
limits_config:
volume_enabled: true
retention_period: 30d
#安装loki
docker run -d \
--restart=always \
-v /app/loki/config:/mnt/config \
-v /app/loki/data:/tmp/loki \
-p 3100:3100 \
--log-opt max-size=1g \
--log-opt max-file=2 \
--name=loki\
grafana/loki:3.0.0 -config.file=/mnt/config/loki-config.yaml
#下载promtail
sudo mkdir /app/promtail
sudo chmod 777 /app/promtail
cd /app/promtail
wget https://github.com/grafana/loki/releases/download/v3.0.0/promtail-linux-amd64.zip
unzip promtail-linux-amd64.zip
chmod +x promtail-linux-amd64
#下载promtail配置
wget https://raw.githubusercontent.com/grafana/loki/v3.0.0/clients/cmd/promtail/promtail-docker-config.yaml -O /app/promtail/promtail-config.yaml
#生成promtail服务文件
sudo tee /etc/systemd/system/promtail.service > /dev/null <<EOF
[Unit]
Description=Promtail Service
After=network.target
[Service]
ExecStart=/app/promtail/promtail-linux-amd64 -config.file=/app/promtail/promtail-config.yaml
Restart=always
[Install]
WantedBy=multi-user.target
EOF
#开启protail服务
sudo systemctl daemon-reload
sudo systemctl start promtail
sudo systemctl enable promtail