prometheus回顾(1)--在liunx上以二进制的方式安装prometheus监控


前言

什么是prometheus

Prometheus 是一个开源的系统监控和报警工具,最早由 SoundCloud 开发,现已成为独立的开源项目并且是 Cloud Native Computing Foundation 的孵化项目。

环境

虚拟机

Ip主机名cpu内存硬盘
192.168.10.14prometheus-server2c2G100G
192.168.10.15prometheus-agent2c2G100G

版本 centos7.9
初始化已完成(防火墙,沙盒,主机名)

一、Prometheus安装

prometheus-server主机操作
1.Prometheus包获取

wget https://github.com/prometheus/prometheus/releases/download/v2.37.8/prometheus-2.37.8.linux-amd64.tar.gz

2.Prometheus安装

tar xf prometheus-2.37.8.linux-amd64.tar.gz
mv prometheus-2.37.8.linux-amd64 /usr/local/prometheus

3.Prometheus启动

cd /usr/local/prometheus/
ls

可以看到包含以下文件与目录
在这里插入图片描述

编辑yml文件

vim Prometheus.yml

翻到最后
把targets后的localhost改为本机ip即192.168.10.14
修改前
在这里插入图片描述
修改后
在这里插入图片描述

这里我们使用 nohup 命令启动 Prometheus 并在后台运行
注意:在/usr/local/prometheus中执行

nohup ./prometheus --config.file=prometheus.yml &

查找与Prometheus相关的进程

ps aux | grep prometheus

在这里插入图片描述

也可以把Prometheus托管给systemd,注册成系统服务,方便管理,如下所示

先停止进程

pkill prometheus

注册为系统服务

cat > /usr/lib/systemd/system/prometheus.service << EOF
[Service]
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
 
[Install]
WantedBy=multi-user.target
 
[Unit]
Description=prometheus
After=network.target
EOF

重载/开机自启/查看状态/启动

systemctl daemon-reload
systemctl enable prometheus
systemctl start prometheus
systemctl status prometheus

running了就行
在这里插入图片描述
查看一下进程

ps -ef | grep prometheus

在这里插入图片描述

二、Prometheus UI界面访问

可以通过运行Prometheus server节点IP+9090端口对Prometheus进行访问。
这里是

192.168.10.14:9090

正常会看到以下页面
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
可以看到日志内容
在这里插入图片描述

在这里插入图片描述
搜索一下刚刚看到的日志
go_gc_duration_seconds
在这里插入图片描述
可以看到搜索出来了
这里使用的语法是PromQL (Prometheus Query Language)
一种用于查询 Prometheus 监控数据的专用语言
感兴趣的可以去了解一下,这里不过多描述
在这里插入图片描述
点击Graph可以看到图形化界面
在这里插入图片描述
在这里插入图片描述

五、使用Prometheus监控Prometheus server及其它主机

1.对Prometheus server主机监控

下载node_exporter

cd ~
wget https://github.com/prometheus/node_exporter/releases/download/v1.6.0/node_exporter-1.6.0.linux-amd64.tar.gz

安装node_exporter

tar xf node_exporter-1.6.0.linux-amd64.tar.gz
mv node_exporter-1.6.0.linux-amd64 /usr/local/node_exporter
cd /usr/local/node_exporter/
 ls

可以看到有如下文件与目录
在这里插入图片描述

启动node_exporter
注册为systemd管理的系统服务

cat > /usr/lib/systemd/system/node_exporter.service << EOF
[Service]
ExecStart=/usr/local/node_exporter/node_exporter
 
[Install]
WantedBy=multi-user.target
 
[Unit]
Description=node_exporter
After=network.target
EOF

重载/开机自启/查看状态/启动

systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter
systemctl status node_exporter

在这里插入图片描述

修改Prometheus Server配置文件添加node节点

cd /usr/local/prometheus/
vim prometheus.yml

尾部添加

  - job_name: "prometheus-server"
    static_configs:
      - targets: ["192.168.10.14:9100"]

重启prometheus

systemctl restart prometheus

web页面
已经监控到了prometheus-server主机了
在这里插入图片描述

2.其它主机监控

prometheus-agent主机操作

tar xf node_exporter-1.6.0.linux-amd64.tar.gz
mv node_exporter-1.6.0.linux-amd64 /usr/local/node_exporter
cd /usr/local/node_exporter/
ls

在这里插入图片描述

启动node_exporter
注册为系统服务

cat > /usr/lib/systemd/system/node_exporter.service << EOF
[Service]
ExecStart=/usr/local/node_exporter/node_exporter
 
[Install]
WantedBy=multi-user.target
 
[Unit]
Description=node_exporter
After=network.target
EOF

重载/开机自启/查看状态/启动

systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter
systemctl status node_exporter

在这里插入图片描述

修改Prometheus Server配置文件添加node节点
回到prometheus-server操作

cd /usr/local/prometheus/
vim prometheus.yml

末端添加

  - job_name: "prometheus-agent"
    static_configs:
      - targets: ["192.168.10.15:9100"]

重启prometheus

systemctl restart prometheus

查看web界面
在这里插入图片描述
完成
后面会有Grafana的讲解

  • 33
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用二进制安装Prometheus 和 Grafana 来监控 Kubernetes,您需要按照以下步骤进行设置: 1. 首先,您需要在 Kubernetes 集群中运行 Prometheus。您可以在每个节点上运行一个 Prometheus 实例,也可以使用 Prometheus Operator 在整个集群中运行多个实例。您可以从 Prometheus 官方网站下载二进制文件。 2. 配置 Prometheus,指定要监控的 Kubernetes 组件和指标。您可以创建一个 Prometheus 配置文件,定义要监控的目标和抓取规则。例如,您可以监控 Kubernetes API 服务器、节点指标、容器指标等等。 3. 启动 Prometheus 实例,并确保它可以连接到 Kubernetes 集群和要监控的组件。您可以使用命令行参数或环境变量来指定 Prometheus 的配置文件和目标。 4. 确保 Prometheus 正确抓取和存储指标数据。您可以访问 Prometheus 的 Web UI 或使用 PromQL 查询语言来检查指标数据。 5. 安装和配置 Grafana,以便可视化 Prometheus 中的指标数据。您可以从 Grafana 官方网站下载二进制文件,并根据需要进行自定义配置。 6. 在 Grafana 中创建仪表盘,并添加 Prometheus 数据源。您可以使用 Grafana 的界面来创建和编辑仪表盘,并使用 PromQL 查询语言来检索和呈现数据。 7. 在仪表盘中添加面板,并选择要显示的指标和图表类型。您可以根据需要创建各种类型的面板,例如图表、表格、仪表盘等。 通过以上步骤,您应该能够使用 Prometheus 和 Grafana 来监控 Kubernetes 集群,并可视化指标数据。请注意,这只是一个简单的概述,具体的配置和设置可能会根据您的需求和环境而有所不同。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值