This manual explains the basic installation of Prometheus, including how to configure Node Exporter and AlertManager in an easy-to-understand way.
โ 1. Install Prometheus
๐ง Prepare Users and Directories
sudo su -
yum update -y
# Create the prometheus user (login disabled)
useradd --no-create-home --shell /bin/false prometheus
# Create directories
mkdir /opt/prometheus
mkdir /var/lib/prometheus
# Change ownership to the prometheus user
chown prometheus. /opt/prometheus
chown prometheus. /var/lib/prometheus
๐ฆ Download and Extract the Prometheus Binary
cd /opt/prometheus
# Download the Prometheus binary
curl -LO https://github.com/prometheus/prometheus/releases/download/v2.19.2/prometheus-2.19.2.linux-amd64.tar.gz
# Verify the hash
dwnl=68382959f73354b30479f9cc3e779cf80fd2e93010331652700dcc71f6b05586
diff <(sha256sum prometheus-2.19.2.linux-amd64.tar.gz | awk '{print $1}') <(echo $dwnl)
# Extract the archive
tar -zxvf prometheus-2.19.2.linux-amd64.tar.gz
cd prometheus-2.19.2.linux-amd64
# Copy binaries
cp -v prometheus /usr/local/bin/
cp -v promtool /usr/local/bin/
chown prometheus. /usr/local/bin/prometheus
chown prometheus. /usr/local/bin/promtool
โ 2. Install Node Exporter
curl -LO https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
chown ec2-user. node_exporter-1.0.1.linux-amd64.tar.gz
tar -zxvf node_exporter-1.0.1.linux-amd64.tar.gz
โ 3. Create the Prometheus systemd Service
cat << _EOF_ > /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus Service
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=1
User=prometheus
Group=prometheus
ExecStart=/usr/local/bin/prometheus \
--web.enable-lifecycle \
--config.file=/opt/prometheus/prometheus-2.19.2.linux-amd64/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus \
--web.console.templates=/opt/prometheus/prometheus-2.19.2.linux-amd64/consoles \
--web.console.libraries=/opt/prometheus/prometheus-2.19.2.linux-amd64/console_libraries \
--storage.tsdb.retention=8d
[Install]
WantedBy=multi-user.target
_EOF_
# Start and enable the service
systemctl daemon-reload
systemctl start prometheus
systemctl enable prometheus
๐ If you want to reload Prometheus via API:
curl -X POST http://<PROMETHEUS_IP>:9090/-/reload
โ 4. Create the Node Exporter Service
cat << _EOF_ > /usr/lib/systemd/system/node-exporter.service
[Unit]
Description=Node Exporter Service
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=1
User=prometheus
Group=prometheus
ExecStart=/home/ec2-user/node_exporter-1.0.1.linux-amd64/node_exporter
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
[Install]
WantedBy=multi-user.target
_EOF_
systemctl daemon-reload
systemctl start node-exporter
systemctl enable node-exporter
โ 5. Access Prometheus
Open the following URL in your browser to check the metrics:
http://<PROMETHEUS_IP>:9090/metrics
โ 6. Example prometheus.yml Configuration File
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets: ['localhost:9093']
rule_files:
- rules.yml
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
โ 7. Install and Configure AlertManager
curl -LO https://github.com/prometheus/alertmanager/releases/download/v0.21.0/alertmanager-0.21.0.linux-amd64.tar.gz
dwnl=9ccd863937436fd6bfe650e22521a7f2e6a727540988eef515dde208f9aef232
diff <(sha256sum alertmanager-0.21.0.linux-amd64.tar.gz | awk '{print $1}') <(echo $dwnl)
tar -zxvf alertmanager-0.21.0.linux-amd64.tar.gz
cp -v alertmanager-0.21.0.linux-amd64/alertmanager /usr/local/bin/
cp -v alertmanager-0.21.0.linux-amd64/amtool /usr/local/bin/
Create the AlertManager systemd Service
cat << _EOF_ > /usr/lib/systemd/system/alert-manager.service
[Unit]
Description=AlertManager Service for Prometheus
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=1
User=prometheus
Group=prometheus
ExecStart=/usr/local/bin/alertmanager --config.file=/home/ec2-user/alertmanager-0.21.0.linux-amd64/alertmanager.yml
[Install]
WantedBy=multi-user.target
_EOF_
systemctl daemon-reload
systemctl start alert-manager
systemctl enable alert-manager
โ 8. Example Rule File (rules.yml)
groups:
- name: example
rules:
- alert: InstanceDown
expr: up == 0
for: 1m
๐ Reference Links
- Prometheus Official Website: https://prometheus.io
- GitHub: https://github.com/prometheus
- GitLab Integration: https://docs.gitlab.com/ee/administration/monitoring/prometheus/
- AlertManager Templates: https://www.freedesktop.org/software/systemd/man/systemd.service.html
If you would like further improvements to this manual, Kubernetes integration, or Slack notification setup examples, feel free to ask!
Sharing knowledge is my passion.
If you'd like to support me, a coffee is always welcome โ
Top comments (0)