prometheus官网下载链接:https://prometheus.io/download/
1、将下载好的prometheus安装包上传至centos系统任意目录,解压安装包,并赋权
tar zxvf prometheus-2.49.1.linux-amd64.tar.gz \解压
mv prometheus-2.49.1.linux-amd64 /usr/local/prometheus \移动解压成功的promethues目录的相关文件
mkdir /usr/local/prometheus/data \创建prometheus数据保存目录
useradd -s /sbin/nologin prometheus \添加prometheus用户
chown -R prometheus:prometheus /usr/local/prometheus/ -R \promethues赋权
2、创建prometheus系统启动文件
vi /etc/systemd/system/prometheus.service \创建prometheus启动文件
\\在prometheus.service 添加以下内容
[Unit]
Description=Prometheus
After=network.target
[Service]
User=prometheus
Group=prometheus
WorkingDirectory=/usr/local/prometheus
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.retention.time=90d
[Install]
WantedBy=multi-user.target
3、 载入prometheus启动文件,启动prometheus并检查启动状态
systemctl daemon-reload \载入启动文件
systemctl enable prometheus \设置开机启动
systemctl start prometheus \启动prometheus
systemctl status prometheus \检查状态
active则表示prometheus启动成功了netstat -tulnep 用该命令查看prometheus 的9090端口使用情况,如端口正常启动,也可说明prometheus启动成功,然后就可以用 http://本机ip:9090 访问prometheus的web界面了
5、将下载好的blackbox安装上传centos7系统,并解压安装
tar -zxvf blackbox_exporter-0.24.0.linux-amd64.tar.gz \解压
mv blackbox_exporter-0.24.0.linux-amd64 /usr/local/blackbox \移动解压后的blackbox配置文件到指定目录
6、创建blackbox系统启动文件
vi /etc/systemd/system/blackbox.service
在blackbox.service输入以下内容:
[Unit]
Description=Prometheus Blackbox Exporter
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/blackbox/blackbox_exporter \
--config.file=/usr/local/blackbox/blackbox.yml \
--web.listen-address=:9115
Restart=on-failure
[Install]
WantedBy=multi-user.target
7、加载系统启动文件,启动blackbox并检查状态
systemctl daemon-reload
systemctl start blackbox.service
systemctl enable blackbox.service
systemctl status blackbox.service
8、因为官方的blackbox只能监控ipv4地址,如果想监控ipv6,需要对blackbox.yml文件进行修改
\\在blackbox.yml最底部的icmp模块,修改成以下内容即可实现同时监控ipv4和ipv6
vi /usr/local/blackbox/blackbox.yml
\\在icmp模块修改成以下内容
icmp:
prober: icmp
icmp:
preferred_ip_protocol: "ipv4"
icmp6:
prober: icmp
icmp:
preferred_ip_protocol: "ipv6"
icmp_ttl5:
prober: icmp
timeout: 5s
icmp:
ttl: 5
9、重启blackbox服务,systemctl restart blackbox
10、blackbox已经安装完成,现在可以修改prometheus配置文件用以监控你需要监控的ip地址网络情况了
cd /usr/local/prometheus
vi prometheus.yml
\\以下是prometheus.yml的内容修改
scrape_interval: 1s \\将数据抓取修改成1S,用以控制blackbox每1s执行一次
- job_name: icmp-ping \\添加一个新的工作
metrics_path: /probe
params:
module: [icmp,icmp6] \\应用的blackbox模块是icmp和icmp6
static_configs:
- targets:
- "114.114.114.114" \\添加需要被监控ip地址
- "fec0::1"
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: localhost:9115 \\Prometheus将使用 localhost:9115 作为网络探测的目标地址,也就是使用blackbox作为探测源
11、重启prometheus服务,登录进web界面查看是否添加成功,在status中的targets查看,状态up表示正常。