美文网首页Security
Prometheus-2·配置及部署

Prometheus-2·配置及部署

作者: 技术老男孩 | 来源:发表于2022-12-13 08:11 被阅读0次

一、部署Prometheus流程:

- 部署监控服务器

  1. 安装Prometheus软件
  2. 修改prometheus.yml添加自己为监控节点
  3. 启动prometheus服务
  4. 查看prometheus控制台

- 被控端部署

  1. 安装node_exporter软件
  2. 启动node_exporter服务
  3. 在Prometheus服务器上修改prometheus.yml添加监控节点
  4. 查看prometheus控制台

二、环境准备:

实验拓扑.png

Prometheus版本:prometheus-2.17.2.linux-386

Node_exporter版本:node_exporter-1.0.0-rc.0.linux-amd64

三、实施:(部署监控服务器)

第一步:安装Prometheus软件

  • 解压本地软件包(prometheus是经过编译后的go语言程序,相当于绿色软件,解压即用)
[root@prometheus ~]# tar xf prometheus_soft.tar.gz 
[root@prometheus ~]# cd prometheus_soft/
[root@prometheus prometheus_soft]# tar xf prometheus-2.17.2.linux-386.tar.gz 
# 专业(将软包移动到local目录下)
[root@prometheus prometheus_soft]# mv prometheus-2.17.2.linux-386 /usr/local/prometheus

第二步:修改prometheus.yml添加自己为监控节点

  • 修改配置文件prometheus.yml大概在29行左右(将自己作为监控项)
[root@prometheus ~]# vim /usr/local/prometheus/prometheus.yml
29 - targets: ['192.168.88.10:9090']
  • 注意:prometheus主机的时间需要与真机时间一致,如果不一致,必须修改时间
# 查看时区
[root@prometheus ~]# timedatectl   
# 修改时区
[root@prometheus ~]# timedatectl set-timezone Asia/Shanghai    
# 修改时间
[root@prometheus ~]# date -s "20220105 14:18:00"
  • 检查语法是否出现问题
# 检查语法
[root@prometheus ~]# /usr/local/prometheus/promtool check config /usr/local/prometheus/prometheus.yml 
Checking /usr/local/prometheus/prometheus.yml
  SUCCESS: 0 rule files found

第三步:启动prometheus服务

  • 创建服务文件(方便启动)
# 创建服务文件prometheus.service
[root@prometheus ~]# vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus Monitoring System
After=network.target

[Service]
ExecStart=/usr/local/prometheus/prometheus \
  --config.file=/usr/local/prometheus/prometheus.yml \
  --storage.tsdb.path=/usr/local/prometheus/data/

[Install]
WantedBy=multi-user.target
  • 启动prometheus服务
# 重新加载配置
[root@prometheus ~]# systemctl daemon-reload 
# 启动服务并设置开机自启
[root@prometheus ~]# systemctl enable prometheus.service --now
  • 查看prometheus的9090端口是否开启
# 查看9090端口
[root@prometheus ~]# ss -tlnp | grep :9090
LISTEN     0      128         :::9090

第四步:查看prometheus控制台

  • 查看监控页面,访问http://192.168.88.10:9090
    prometheus监控页面1.png
  • 被监控的对象称为targets


    targets.png
  • status显示up就说明prometheus已经在监控自己了


    status.png
  • 查看监控图像


    查看监控图像.png
  • 添加需要查看的监控项


    添加需要查看的监控项1.png
    添加需要查看的监控项2.png
  • 查看监控项的图形信息


    查看监控项的图形信息1.png
    查看监控项的图形信息2.png

四、实施:(被控端部署)

第一步:安装node_exporter软件

  • node-exporter用于监控硬件和系统的常用指标
  • 安装node_exporter
# 解压软件包
[root@node1 ~]# tar xf node_exporter-1.0.0-rc.0.linux-amd64.tar.gz 
# 依旧是专业(将软件包移动到local目录下)
[root@node1 ~]# mv node_exporter-1.0.0-rc.0.linux-amd64 /usr/local/node_exporter

第二步:启动node_exporter服务

  • 创建服务文件(方便启动)
# 创建node_exporter.service
[root@node1 ~]# vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/node_exporter/node_exporter

[Install]
WantedBy=multi-user.target
  • 启动node_exporter服务
# 重新加载配置
[root@node1 ~]# systemctl daemon-reload
# 启动node_exporter服务并设置开机自启
[root@node1 ~]# systemctl enable node_exporter.service --now
  • 查看node_exporter的9100端口是否开启
# 查看9100端口
[root@node1 ~]# ss -tlnp | grep :9100
LISTEN     0      128         :::9100

第三步:在Prometheus服务器上添加监控节点

# 在配置文件中追加以下内容。特别注意缩进
[root@prometheus ~]# vim /usr/local/prometheus/prometheus.yml
 - job_name: 'node1'
    static_configs:
    - targets: ['192.168.88.11:9100']
  • 重启服务
# 重启prometheus服务
[root@prometheus ~]# systemctl restart prometheus.service 

第四步:查看prometheus控制台

  • 查看targets是否新增监控设备


    targets.png
  • 查看node1节点的1分钟平均负载


    node1.png
    node1-Graph.png

相关文章

网友评论

    本文标题:Prometheus-2·配置及部署

    本文链接:https://www.haomeiwen.com/subject/uzasfdtx.html