install-prometheus-debian-12/install-prometheus.sh

88 lines
1.8 KiB
Bash
Raw Normal View History

2024-03-21 14:22:43 +02:00
#!/usr/bin/env bash
set -x
2024-06-18 16:30:15 +03:00
DOWNLOAD_URL="https://github.com/prometheus/prometheus/releases/download/v2.52.0/prometheus-2.52.0.linux-amd64.tar.gz"
2024-03-21 14:22:43 +02:00
groupadd --system prometheus
useradd -s /sbin/nologin --system -g prometheus prometheus
mkdir /var/lib/prometheus
for i in rules rules.d files_sd
do
mkdir -p /etc/prometheus/${i}
done
mkdir -p /tmp/prometheus
cd /tmp/prometheus
#curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi -
wget "${DOWNLOAD_URL}" -O "prometheus.tar.gz"
tar xvf prometheus.tar.gz
cd prometheus*/
mv prometheus promtool /usr/local/bin/
prometheus --version
mv prometheus.yml /etc/prometheus/prometheus.yml
mv consoles/ console_libraries/ /etc/prometheus/
cd ${HOME}
cat >/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
for i in rules rules.d files_sd
do
chown -R prometheus:prometheus /etc/prometheus/${i}
done
for i in rules rules.d files_sd
do
chmod -R 775 /etc/prometheus/${i}
done
chown -R prometheus:prometheus /var/lib/prometheus/
systemctl daemon-reload
systemctl start prometheus
systemctl enable prometheus
systemctl status prometheus --no-pager
set +x