安装prometheus
服务器
ip | 系统 | 配置 | 目录 | 部署版本 |
---|---|---|---|---|
172.24.32.200 | centos7.7 | 2c4g | /data/prometheus | 2.18 |
1、部署prometheus
创建目录,下载文件
mkdir -p /data/prometheus && cd /data/prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.18.1/prometheus-2.18.1.linux-amd64.tar.gz
wget https://github.com/prometheus/alertmanager/releases/download/v0.20.0/alertmanager-0.20.0.linux-amd64.tar.gz
tar zxf prometheus-2.18.1.linux-amd64.tar.gz&&mv prometheus-2.18.1.linux-amd64 prometheus
创建数据目录
mkdir -p /data/prometheus/prometheus/data
mkdir -p /data/prometheus/prometheus/rules
创建用户并授权
useradd prometheus
chown -R prometheus:prometheus /data/prometheus
添加启动项
cat>>/usr/lib/systemd/system/prometheus.service<<EOF
[Unit]
Description=Prometheus
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/data/prometheus/prometheus/prometheus --config.file=/data/prometheus/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus/prometheus/data
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
启动并设置为开机自启动
systemctl start prometheus
systemctl enable prometheus
2、部署alertmanager
cd /data/prometheus
mv alertmanager-0.20.0.linux-amd64 alertmanager
mkdir -p /data/prometheus/alertmanager/template
chown -R prometheus:prometheus /data/prometheus
添加启动项
cat>>/usr/lib/systemd/system/alertmanager.service<<EOF
[Unit]
Description=alertmanager
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/data/prometheus/alertmanager/alertmanager --config.file=/data/prometheus/alertmanager/alertmanager.yml
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
启动并开机自启动
systemctl start alertmanager
systemctl enable alertmanager
3、部署node_export
mkdir -p /data/prometheus && cd /data/prometheus
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.0-rc.1/node_exporter-1.0.0-rc.1.linux-amd64.tar.gz
tar zxf node_exporter-1.0.0-rc.1.linux-amd64.tar.gz
mv node_exporter-1.0.0-rc.1.linux-amd64 node_exporter
chown -R prometheus:prometheus /data/prometheus
添加启动项
cat>>/usr/lib/systemd/system/node_exporter.service<<EOF
[Unit]
Description=node_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/data/prometheus/node_exporter/node_exporter
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
启动并开机自启动
systemctl start node_exporter
systemctl enable node_exporter
验证下监控参数
curl 127.0.0.1:9100/metrics
vim /data/prometheus/prometheus/prometheus.yml
- job_name: 'node'
static_configs:
- targets: ['172.24.32.200:9100']
热加载
查看targets查看监控
http://172.24.32.200:9090/targets
思考:采用file_sd_configs的方式加载配置