-
Notifications
You must be signed in to change notification settings - Fork 2
/
install-promtail.yml
77 lines (59 loc) · 1.65 KB
/
install-promtail.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
echo "🚀 Starting Promtail installation..."
# Check and install unzip if not exists
if ! command -v unzip &> /dev/null; then
echo "🛠 Installing unzip..."
sudo apt update
sudo apt install -y unzip
fi
# Fetch system hostname
HOSTNAME=$(hostname)
# Download Promtail binary
wget https://github.com/grafana/loki/releases/download/v2.4.1/promtail-linux-amd64.zip -O promtail.zip
# Unzip and move to /usr/local/bin
unzip promtail.zip
chmod a+x promtail-linux-amd64
sudo mv promtail-linux-amd64 /usr/local/bin/promtail
# Create system user and group
sudo addgroup --system promtail
sudo adduser --system --ingroup promtail promtail
# Create config file
mkdir -p /etc/promtail
cat <<EOL > /etc/promtail/promtail-config.yaml
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: http://127.0.0.1:3100/loki/api/v1/push
scrape_configs:
- job_name: journal
journal:
max_age: 12h
labels:
job: systemd-journal
host: $HOSTNAME
relabel_configs:
- source_labels: ['__journal__systemd_unit']
target_label: 'unit'
EOL
# Adjust permissions
sudo chown -R promtail:promtail /etc/promtail
# Create systemd service
cat <<EOL > /etc/systemd/system/promtail.service
[Unit]
Description=Promtail service
After=network.target
[Service]
User=promtail
Group=promtail
ExecStart=/usr/local/bin/promtail -config.file /etc/promtail/promtail-config.yaml
[Install]
WantedBy=multi-user.target
EOL
# Reload systemd and start Promtail service
sudo systemctl daemon-reload
sudo systemctl enable promtail
sudo systemctl start promtail
echo "🎉 Promtail installation complete!"