Install & Setup Prometheus On Amazon Linux, CentOS & RHEL
- Add system user and group for Prometheus
sudo groupadd --system prometheus sudo useradd -s /sbin/nologin --system -g prometheus prometheus
- Create data directory for Prometheus
sudo mkdir /var/lib/prometheus
- Create configuration directories for Prometheus
for i in rules rules.d files_sd; do sudo mkdir -p /etc/prometheus/${i}; done
- Download 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 -
- Extract the file and move it to directory in your $PATH
tar xvf prometheus-*.tar.gz cd prometheus-*/ sudo cp prometheus promtool /usr/local/bin/
- Also copy consoles and console_libraries to /etc/prometheus directory:
sudo cp -r prometheus.yml consoles/ console_libraries/ /etc/prometheus/
- Create systemd Service unit
sudo vi /etc/systemd/system/prometheus.service
Add below content and save
[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 SyslogIdentifier=prometheus Restart=always [Install] WantedBy=multi-user.target
- Set correct directory permissions.
sudo chown -R prometheus:prometheus /etc/prometheus sudo chmod -R 777 /etc/prometheus/ sudo chmod -R 777 /var/lib/prometheus/ sudo chown -R prometheus:prometheus /var/lib/prometheus/
- Start Prometheus service.
sudo systemctl daemon-reload sudo systemctl start prometheus
- Enable the service to start at system boot:
sudo systemctl enable prometheus
- Check status using systemctl status prometheus command:
systemctl status prometheus.service