Skip to content

Instantly share code, notes, and snippets.

@chrisedrego
Last active November 9, 2022 15:18
Show Gist options
  • Save chrisedrego/e636f43caf1e777e68a7c9e3cb4d6549 to your computer and use it in GitHub Desktop.
Save chrisedrego/e636f43caf1e777e68a7c9e3cb4d6549 to your computer and use it in GitHub Desktop.
Prometheus installation
apt-get && apt upgrade -y
groupadd prometheus
useradd -s /sbin/nologin --system -g prometheus prometheus
for i in rules rules.d files_sd; do sudo mkdir -p /etc/prometheus/${i}; done
apt install curl -y
mkdir -p /tmp/prometheus
cd /tmp/prometheus
PROM_LATEST=$(curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4)
wget -qi – $PROM_LATEST
tar xvf prometheus*.tar.gz
cd */
mv prometheus promtool /usr/local/bin
mv prometheus.yml /etc/prometheus/prometheus.yml
mv consoles/ console_libraries/ /etc/prometheus/
for i in rules rules.d files_sd; do sudo chown -R prometheus:prometheus /etc/prometheus/${i}; done
for i in rules rules.d files_sd; do sudo chmod -R 775 /etc/prometheus/${i}; done
chown -R prometheus:prometheus /etc/prometheus/
sudo tee -a > /etc/systemd/system/prometheus.service << EOF
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP \$MAINPID
ExecStart=/usr/local/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries \
--web.listen-address=0.0.0.0:9090 \
--web.external-url=
SyslogIdentifier=prometheus
Restart=always
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl start prometheus.service
sudo systemctl enable prometheus.service
sudo systemctl status prometheus.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment