apt -y install prometheus prometheus-node-exporternano /etc/prometheus/prometheus.yml
# add the following lines
external_labels:
monitor: 'your-monitor'systemctl enable prometheus prometheus-node-exporter
systemctl status prometheus prometheus-node-exporterFor 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:adminpromtool check web-config /etc/prometheus/web.yml
# you should see the following output
/etc/prometheus/web.yml SUCCESSnano /etc/default/prometheus
# add the following line
ARGS="--web.config.file=/etc/prometheus/web.yml"systemctl restart prometheus prometheus-node-exportercurl --head http://localhost:9090/graph
# you should see the following output
HTTP/1.1 401 Unauthorizedcurl -u admin:admin --head http://localhost:9090/graph
# you should see the following output
HTTP/1.1 200 OKjournalctl -u prometheuswget -qO loki-linux-amd64.zip https://github.com/grafana/loki/releases/download/v3.1.1/loki-linux-amd64.zipwget -qO loki-config.yaml https://raw.githubusercontent.com/grafana/loki/v3.1.1/cmd/loki/loki-local-config.yamlwget -qO promtail-linux-amd64.zip https://github.com/grafana/loki/releases/download/v3.1.1/promtail-linux-amd64.zipwget -qO promtail-config.yaml https://raw.githubusercontent.com/grafana/loki/v3.1.1/clients/cmd/promtail/promtail-local-config.yamlunzip -o loki-linux-amd64.zip
unzip -o promtail-linux-amd64.zipmv loki-linux-amd64 loki
mv promtail-linux-amd64 promtailrm -f loki-linux-amd64.zip promtail-linux-amd64.zipchmod a+x loki promtailln -s /opt/loki/loki /usr/local/bin/loki
ln -s /opt/loki/promtail /usr/local/bin/promtailcat <<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
EOFcat <<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
EOFsystemctl daemon-reload
systemctl enable loki
systemctl enable promtail
systemctl start loki
systemctl start promtailjournalctl -u loki -f
journalctl -u promtail -fsystemctl status loki
systemctl status promtailsystemctl 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/lokiapt update
apt install -y nginx apache2-utilshtpasswd -c /etc/nginx/.htpasswd adminhtpasswd /etc/nginx/.htpasswd grafana-readercat <<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;
}
}
EOFln -s /etc/nginx/sites-available/loki /etc/nginx/sites-enabled/lokisystemctl restart nginxsystemctl status nginxcurl -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"]
]
}
]
}'