apt -y install prometheus prometheus-node-exporter
nano /etc/prometheus/prometheus.yml
# add the following lines
external_labels:
monitor: 'your-monitor'
systemctl enable prometheus prometheus-node-exporter
systemctl status prometheus prometheus-node-exporter
For easy password generation, you can use the following website: https://bcrypt-generator.com
nano /etc/prometheus/web.yml
# add the following lines
basic_auth_users:
admin: $2a$12$g.S1Ge35P2fMyi7wrQGTxeE3v.RhdDAtCr3BEeOTcc.a/CnrZSLG6 # admin:admin
promtool check web-config /etc/prometheus/web.yml
# you should see the following output
/etc/prometheus/web.yml SUCCESS
nano /etc/default/prometheus
# add the following line
ARGS="--web.config.file=/etc/prometheus/web.yml"
systemctl restart prometheus prometheus-node-exporter
curl --head http://localhost:9090/graph
# you should see the following output
HTTP/1.1 401 Unauthorized
curl -u admin:admin --head http://localhost:9090/graph
# you should see the following output
HTTP/1.1 200 OK
journalctl -u prometheus
wget -qO loki-linux-amd64.zip https://github.com/grafana/loki/releases/download/v3.1.1/loki-linux-amd64.zip
wget -qO loki-config.yaml https://raw.githubusercontent.com/grafana/loki/v3.1.1/cmd/loki/loki-local-config.yaml
wget -qO promtail-linux-amd64.zip https://github.com/grafana/loki/releases/download/v3.1.1/promtail-linux-amd64.zip
wget -qO promtail-config.yaml https://raw.githubusercontent.com/grafana/loki/v3.1.1/clients/cmd/promtail/promtail-local-config.yaml
unzip -o loki-linux-amd64.zip
unzip -o promtail-linux-amd64.zip
mv loki-linux-amd64 loki
mv promtail-linux-amd64 promtail
rm -f loki-linux-amd64.zip promtail-linux-amd64.zip
chmod a+x loki promtail
ln -s /opt/loki/loki /usr/local/bin/loki
ln -s /opt/loki/promtail /usr/local/bin/promtail
cat <<EOF > /etc/systemd/system/loki.service
[Unit]
Description=Loki service
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/loki -config.file=/opt/loki/loki-config.yaml
Restart=always
[Install]
WantedBy=multi-user.target
EOF
cat <<EOF > /etc/systemd/system/promtail.service
[Unit]
Description=Promtail service
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/promtail -config.file=/opt/loki/promtail-config.yaml
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable loki
systemctl enable promtail
systemctl start loki
systemctl start promtail
journalctl -u loki -f
journalctl -u promtail -f
systemctl status loki
systemctl status promtail
systemctl stop loki
systemctl stop promtail
systemctl disable loki
systemctl disable promtail
rm -f /etc/systemd/system/loki.service
rm -f /etc/systemd/system/promtail.service
rm -f /usr/local/bin/loki
rm -f /usr/local/bin/promtail
rm -rf /opt/loki
apt update
apt install -y nginx apache2-utils
htpasswd -c /etc/nginx/.htpasswd admin
htpasswd /etc/nginx/.htpasswd grafana-reader
cat <<EOF > /etc/nginx/sites-available/loki
server {
listen 80;
server_name loki.monitoring.diegocornejo.com;
location / {
proxy_pass http://localhost:3100;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}
EOF
ln -s /etc/nginx/sites-available/loki /etc/nginx/sites-enabled/loki
systemctl restart nginx
systemctl status nginx
curl -u admin:password -X POST "http://loki.monitoring.diegocornejo.com/loki/api/v1/push" \
-H "Content-Type: application/json" \
-d '{
"streams": [
{
"stream": {
"job": "test-job",
"host": "localhost"
},
"values": [
["1725558605429055936", "log line for testing"],
["1725558605429055936", "another log line for testing"]
]
}
]
}'