centos操作系统上以service形式运行blackbox_exporter监控网页端口


前言

记录一下centos操作系统上以简单的service形式运行blackbox_exporter监控网页端口的记录


一、blackbox_exporter是什么

Blackbox Exporter是Prometheus官方提供的黑盒监控解决方案之一。它允许用户通过HTTP、HTTPS、DNS、TCP、ICMP和gRPC等方式对网络端点进行探测,以检查服务的可用性、响应时间和性能等关键指标。

二、使用步骤

1.获取二进制文件

官网地址:
https://github.com/prometheus/blackbox_exporter/releases
https://prometheus.io/download/#memcached_exporter

我这里选择的是blackbox_exporter-0.25.0.linux-amd64.tar.gz版本
在这里插入图片描述

在这里插入图片描述

2.准备部署脚本

#!/bin/bash

set -e
tar -xvf ./blackbox_exporter-0.25.0.linux-amd64.tar.gz
if [ -d ./blackbox_exporter-0.25.0.linux-amd64/ ];then
  sudo cp ./blackbox_exporter-0.25.0.linux-amd64/blackbox_exporter /usr/local/bin/ && cp ./blackbox_exporter-0.25.0.linux-amd64/blackbox.yml /usr/local/bin/
else
  echo "请检查 blackbox_exporter 所在文件目录"
  exit 1
fi

sudo touch /usr/lib/systemd/system/blackbox_exporter.service
sudo chmod o+w /usr/lib/systemd/system/blackbox_exporter.service
sudo chmod o+x /usr/local/bin/blackbox_exporter

cat << EOF > /usr/lib/systemd/system/blackbox_exporter.service 
[Service]
User=$USER
Group=$USER
ExecStart=/usr/local/bin/blackbox_exporter --config.file=/usr/local/bin/blackbox.yml

[Install]
WantedBy=multi-user.target

[Unit]
Description=blackbox_exporter
After=network.target 
EOF

sudo systemctl daemon-reload
sudo systemctl start blackbox_exporter
sudo systemctl enable blackbox_exporter
sudo systemctl status blackbox_exporter
echo 'end success'

3.执行命令,进行部署

chmod +x blackbox-expoter-0.25.0.sh
./blackbox-expoter-0.25.0.sh

4.prometheus中增加需要监控页面的job信息

配置之后重启prometheus

  - job_name: '150.2_web_port_status'
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
    - targets: ['192.168.150.2:8097']
      labels:
        instance: '192.168.150.2'
        tags: 'seafile平台端口'
    - targets: ['192.168.150.2:8098']
      labels:
        instance: '192.168.150.2'
        tags: 'onlyoffice平台端口'
    - targets: ['192.168.150.2:8088']
      labels:
        instance: '192.168.150.2'
        tags: '禅道平台端口'
    - targets: ['harbor.XXX.XXX.XX:10002']
      labels:
        instance: '192.168.150.2'
        tags: 'harbor平台端口'
    - targets: ['192.168.150.2:10001']
      labels:
        instance: '192.168.150.2'
        tags: 'gitlab平台端口'
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: 192.168.150.XX:9115

三、查看部署结果

Blackbox Exporter页面

在这里插入图片描述

prometheus界面

在这里插入图片描述

四、配置到grafana中

使用13659的dashboard
地址:https://grafana.com/grafana/dashboards/13659-blackbox-exporter-http-prober/

在这里插入图片描述

总结

简单记录一下,高阶功能有具体需求的时候再使用了。

CentOS7系统上配置Prometheus和VMware_exporter进行VMware环境监控并设置邮件警报时,您将需要遵循以下步骤,以确保系统安全性、环境准备、监控服务配置以及警报系统的正确设置。 参考资源链接:[使用prometheus+vmware_exporter实现监控与邮件警报](https://wenku.csdn.net/doc/6kh9s31tce) 首先,确保您的CentOS7系统是最新的。运行`yum -y update`来更新系统及其包。接下来,为了保证通信安全,配置防火墙以允许9090端口Prometheus监听端口)和3000端口(VMware_exporter监听端口)的TCP流量。使用以下命令: ``` firewall-cmd --zone=public --add-port=9090/tcp --permanent firewall-cmd --zone=public --add-port=3000/tcp --permanent firewall-cmd --reload ``` 接着,安装Go语言环境,这对于Prometheusexporter运行至关重要。下载Go的Linux-amd64版本的压缩包,并解压到`/usr/local`目录下: ``` wget [下载链接] tar -C /usr/local -xzf [压缩包名称].linux-amd64.tar.gz ``` 然后,更新环境变量以包含Go的路径: ``` echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bash_profile source ~/.bash_profile go version ``` 确认Go已正确安装后,安装Python3及其开发库,这可能涉及到使用Python脚本的场景: ``` yum -y install python3 python3-devel python3 --version ``` 配置完成后,下载Prometheus二进制包和VMware_exporter的压缩包,并在各自目录下解压。确保Prometheus可以访问VMware_exporter提供的端点。 Prometheus的配置文件`prometheus.yml`需要正确设置,指定VMware_exporter作为目标。例如: ``` scrape_configs: - job_name: 'vmware' static_configs: - targets: ['localhost:3000'] ``` 此外,配置Prometheus的alertmanager.yml文件,设置SMTP服务器信息、通知接收邮箱,并定制警报模板。 完成配置后,通过运行Prometheus和VMware_exporter的二进制文件启动服务。这可以通过在各自目录下运行以下命令来实现: ``` ./prometheus ./vmware_exporter ``` 确保通过运行`ps aux | grep [进程名]`检查两个进程是否正常运行。 到此为止,您应该已经成功在CentOS7上配置了Prometheus和VMware_exporter,并设置了邮件警报。对于希望深入了解监控和警报系统配置的用户,可以参考《使用prometheus+vmware_exporter实现监控与邮件警报》一书。它不仅包含了上述内容,还提供了更深入的场景分析、故障排查和最佳实践,帮助您构建稳定高效的监控系统。 参考资源链接:[使用prometheus+vmware_exporter实现监控与邮件警报](https://wenku.csdn.net/doc/6kh9s31tce)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值