#ensure apache log directory and error.log exists mkdir -p /var/log/apache2/ touch /var/log/apache2/error.log #create data directory promtail to store information about which logs have already been processed(notified) mkdir -p /data/loki/ #updates repositories, to ensure we are up to date sudo apt-get update -y #install unzip to unzip to extract archive that constain the promtail release sudo apt-get install unzip -y #gets newest release for promtail on x64 architecture - check https://github.com/grafana/loki/releases for available architectures and platforms sudo curl -s https://api.github.com/repos/grafana/loki/releases/latest | grep browser_download_url | cut -d '"' -f 4 | grep promtail-linux-amd64.zip | wget -i - #extracts the downloaded archive sudo unzip promtail-linux-amd64.zip #move the extracted binary to be on path sudo mv promtail-linux-amd64 /usr/local/bin/promtail #create configuration directory mkdir -p /etc/promtail/ #write configuration file echo "server: disable: true positions: filename: /data/loki/positions.yaml clients: - url: https://lognotifier.com/api/users/[INSERT_YOUR_ID_HERE]/log/ scrape_configs: - job_name: system static_configs: - targets: - localhost labels: job: varlogs __path__: /var/log/apache2/error.log" > /etc/promtail/promtail-local-config.yaml #Create promtail service. Alternatively simply run /usr/local/bin/promtail -config.file /etc/promtail/promtail-local-config.yaml echo "[Unit] Description=Promtail service After=network.target [Service] Type=simple User=root ExecStart=/usr/local/bin/promtail -config.file /etc/promtail/promtail-local-config.yaml [Install] WantedBy=multi-user.target" > /etc/systemd/system/promtail.service #reloads daemon configurations sudo systemctl daemon-reload #enables service on startup sudo systemctl enable promtail.service #starts service sudo systemctl start promtail.service