环境:
软件: prometheus-2.5.0 , node_exporter-1.0.1
客户端IP: 192.168.31.30,192.168.31.[40..42]
prometheus端IP: 192.168.31.250
一、部署Prometheus 服务端
1.1 二进制部署promethues
官网下载对于的包:https://prometheus.io/download/
[root@prometheus ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.5.0/prometheus-2.5.0.linux-amd64.tar.gz
[root@prometheus ~]# tar -xf prometheus-2.5.0.linux-amd64.tar.gz
[root@prometheus ~]# cd prometheus-2.5.0.linux-amd64/
[root@prometheus prometheus-2.5.0.linux-amd64]# cp prometheus promtool /usr/local/bin
[root@prometheus prometheus-2.5.0.linux-amd64]# prometheus –version //查看下prometheus 版本
[root@prometheus prometheus-2.5.0.linux-amd64]# mkdir /etc/prometheus //创建prometheus 配置文件目录
[root@prometheus prometheus-2.5.0.linux-amd64]# cp prometheus.yml /etc/prometheus/
1.2 为了方便管理,创建prometheus.service 文件,使用systemd 去管理
[root@prometheus ~]# vim /etc/systemd/system/prometheus.service
[Unit]Description=Prometheus Monitoring SystemDocumentation=Prometheus Monitoring System[Service]ExecStart=/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --web.listen-address=:9090[Install]WantedBy=multi-user.target
[root@prometheus ~]# systemctl daemon-reload
[root@prometheus ~]# systemctl enable prometheus.service
[root@prometheus ~]# systemctl start prometheus.service
[root@prometheus ~]# ps -ef | grep prometheus
root 19302 1 0 11:38 ? 00:00:04 /usr/local/bin/prometheus –config.file=/etc/prometheus/prometheus.yml –web.listen-address=:9090
root 20532 16875 0 11:55 pts/1 00:00:00 grep –color=auto prometheus
1.3 打开浏览器访问 prometheus webUI界面
http://192.168.31.250:9090
二、监控节点部署Node exporter
2.1 二进制部署promethues
官网下载 软件包 node_exporter ,https://prometheus.io/download/
选择对应的版本进行下载
[root@prometheus ~]# wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
[root@prometheus ~]# tar -xf node_exporter-1.0.1.linux-amd64.tar.gz
[root@prometheus ~]# cd node_exporter-1.0.1.linux-amd64/
[root@prometheus ~]# cp node_exporter /usr/local/bin
#验证是否安装成功
[root@prometheus ~]# node_exporter –version
node_exporter, version 1.0.1 (branch: HEAD, revision: 3715be6ae899f2a9b9dbfd9c39f3e09a7bd4559f)
build user: root@1f76dbbcfa55
build date: 20200616-12:44:12
go version: go1.14.4
#拷贝node_exporter 可执行文件到其他需要监控的节点上
[root@prometheus ~]# scp /usr/local/bin/node_exporter root@192.168.31.40:/usr/local/bin
[root@prometheus ~]# scp /usr/local/bin/node_exporter root@192.168.31.41:/usr/local/bin
[root@prometheus ~]# scp /usr/local/bin/node_exporter root@192.168.31.42:/usr/local/bin
[root@prometheus ~]# scp /usr/local/bin/node_exporter root@192.168.31.30:/usr/local/bin
2.2 配置 文本文件收集器
#每个客户端的文本收集器内容都不一致
[root@master-1 ~]# mkdir -p /var/lib/node_exporter/textfile_collector
[root@master-1 ~]# echo ‘metadata{role=”docker_server”,datacenter=”NJ”} 1’ > /var/lib/node_exporter/textfile_collector/metadata.prom
[root@node-1 ~]# mkdir -p /var/lib/node_exporter/textfile_collector
[root@node-1 ~]# echo ‘metadata{role=”docker_server”,datacenter=”NJ”} 1’ > /var/lib/node_exporter/textfile_collector/metadata.prom
[root@node-2 ~]# mkdir -p /var/lib/node_exporter/textfile_collector
[root@node-2 ~]# echo ‘metadata{role=”docker_server”,datacenter=”NJ”} 1’ > /var/lib/node_exporter/textfile_collector/metadata.prom
[root@node-3 ~]# mkdir -p /var/lib/node_exporter/textfile_collector
[root@node-3 ~]# echo ‘metadata{role=”docker_server”,datacenter=”NJ”} 1’ > /var/lib/node_exporter/textfile_collector/metadata.prom
2.3 运行节点导出器
#在每个客户端的分别启动
[root@master-1 ~]# nohup node_exporter –collector.textfile.directory /var/lib/node_exporter/textfile_collector –collector.systemd –collector.systemd.unit-whitelist=”(docker|sshd|rsyslog).service” > node_exporter.out 2>&1 &
==============================
#启动文件配置说明
–collector.textfile.directory /var/lib/node_exporter/textfile_collector #指定文本文件收集器的文件目录,只需要指定目录 –collector.textfile.directory
–collector.systemd –collector.systemd.unit-whitelist=”(docker|sshd|rsyslog).service” #启用 system 收集器(默认是关闭的),使用正则表达式 收集信息
其他配置,没有列出来的
–web.listen-address=“0.0.0.0:9600″ #node_exporter 导出器 的监听地址端口, 默认是 0.0.0.0:9100
–web.telemetrypath=”/node_metrics” #节点metrics 访问路径,默认是 http://XX.XX.XX.XX:9100/metrics
打开浏览器 http://XX.XX.XX.XX:9100/metrics 可以看到 node_exporter 收集到的数据
2.4 在 prometheus 服务器配置 scrap(连接每台node_exporter地址)
#添加一组job_name ,名称为 node
# 写入节点导出器的监听地址 ; targets: [‘192.168.31.30:9100′,’192.168.31.40:9100′,’192.168.31.41:9100′,’192.168.31.42:9100’]
[root@prometheus ~]# vim /path/to/prometheus.yml
global:scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. # 多久 收集 一次数据evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # 多久评估一次 规则# Alertmanager configurationalerting:alertmanagers:- static_configs:- targets:# - alertmanager:9093rule_files:# - "first_rules.yml"# - "second_rules.yml"scrape_configs:- job_name: 'prometheus'static_configs:- targets: ['192.168.31.250:9090']- job_name: 'node'static_configs:- targets: ['192.168.31.30:9100','192.168.31.40:9100','192.168.31.41:9100','192.168.31.42:9100']
#改完后记得重新加载下 prometheus 的配置文件
[root@prometheus ~]# ps -ef | grep prometheus | grep -v “grep” | awk ‘{print $2}’ | xargs kill -HUP
2.5 登陆 prometheus 控制台上 查看Targets
查看刚刚定义的node_exporter 的主机 时候都添加到 prometheus 目标里了