ubuntu 22.04 配置 Prometheus 和 Grafana 服务器监控

news2025/7/11 17:02:58

由于内存白菜价, 家里的虚拟机越来越多了。

1个是难以管理hostname 和 ip, 只靠/etc/hosts 去记住其实并不方便

试过宝塔linux面板, 可惜是单机的,不适用于管理集群linux服务器, 而且里面一股金钱气息。
至于他们另1个产品堡塔云, 估计是集群管理, 但是安装失败, 而且看了价格感觉像智商税。

公司用过Appdynamic, 功能强大可惜更不是我能想的。
在这里插入图片描述

只能还是去寻找开源方案。好在外能的google提供了一套成熟的开源方案

Prometheus - 用于管理机 - 集群服务器数据收集
node_exporter - 用于被管理节点 - 提供节点本身的服务器数据给Prometheus
Grafana - 数据展示工具

下面就会写出详细的安装步骤



1. 服务器准备

Nohostnameipcpu 数memoryoscomment
1amdeuc-vm010.0.1.15512ubuntu 22.04 LTS server监控机
2amdeuc-vm110.0.1.15628ubuntu 22.04 LTS server被监控机
3amdeuc-vm210.0.1.15714ubuntu 22.04 LTS server被监控机
4amdeuc-vm310.0.1.15814ubuntu 22.04 LTS server被监控机



2. 在宿主机安装Prometheus

2.1 安装

个人觉得不用下载安装包这么复杂, 直接从ubuntu源安装

sudo apt-get install prometheus

检查prometheus 有没有启动

gateman@amdeuc-vm0:~$ systemctl status prometheus
● prometheus.service - Monitoring system and time series database
     Loaded: loaded (/lib/systemd/system/prometheus.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-11-24 15:58:52 UTC; 4h 3min ago
       Docs: https://prometheus.io/docs/introduction/overview/
             man:prometheus(1)
   Main PID: 23080 (prometheus)
      Tasks: 7 (limit: 23310)
     Memory: 44.6M
        CPU: 30.744s
     CGroup: /system.slice/prometheus.service
             └─23080 /usr/bin/prometheus



2.2 检查配置文件

gateman@amdeuc-vm0:/etc/prometheus$ cat prometheus.yml 
# Sample config for Prometheus.

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.
  # scrape_timeout is set to the global default (10s).

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
      monitor: 'example'

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets: ['localhost:9093']

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s
    scrape_timeout: 5s

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ['localhost:9090']

  - job_name: node
    # If prometheus-node-exporter is installed, grab stats about the local
    # machine by default.
    static_configs:
      - targets: ['localhost:9100']

可以见prometheus 的 控制端口是9090

在浏览器访问服务器ip和9090 端口, 如果 prometheus 页面能打开就没什么问题
在这里插入图片描述



3. 在被监控节点安装node exporter

也是直接从ubuntu源里安装

sudo apt-get install prometheus-node-exporter

检查node exporter 服务有没有启动

gateman@amdeuc-vm3:~$ systemctl status prometheus-node-exporter
● prometheus-node-exporter.service - Prometheus exporter for machine metrics
     Loaded: loaded (/lib/systemd/system/prometheus-node-exporter.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-11-25 11:49:24 UTC; 5min ago
       Docs: https://github.com/prometheus/node_exporter
   Main PID: 1567 (prometheus-node)
      Tasks: 4 (limit: 4460)
     Memory: 2.2M
        CPU: 7ms
     CGroup: /system.slice/prometheus-node-exporter.service
             └─1567 /usr/bin/prometheus-node-exporter

Nov 25 11:49:24 amdeuc-vm3 prometheus-node-exporter[1567]: ts=2022-11-25T11:49:24.830Z caller=node_exporter.go:115 level=info collector=thermal_zone
Nov 25 11:49:24 amdeuc-vm3 prometheus-node-exporter[1567]: ts=2022-11-25T11:49:24.830Z caller=node_exporter.go:115 level=info collector=time
Nov 25 11:49:24 amdeuc-vm3 prometheus-node-exporter[1567]: ts=2022-11-25T11:49:24.830Z caller=node_exporter.go:115 level=info collector=timex
Nov 25 11:49:24 amdeuc-vm3 prometheus-node-exporter[1567]: ts=2022-11-25T11:49:24.830Z caller=node_exporter.go:115 level=info collector=udp_queues
Nov 25 11:49:24 amdeuc-vm3 prometheus-node-exporter[1567]: ts=2022-11-25T11:49:24.830Z caller=node_exporter.go:115 level=info collector=uname
Nov 25 11:49:24 amdeuc-vm3 prometheus-node-exporter[1567]: ts=2022-11-25T11:49:24.830Z caller=node_exporter.go:115 level=info collector=vmstat
Nov 25 11:49:24 amdeuc-vm3 prometheus-node-exporter[1567]: ts=2022-11-25T11:49:24.830Z caller=node_exporter.go:115 level=info collector=xfs
Nov 25 11:49:24 amdeuc-vm3 prometheus-node-exporter[1567]: ts=2022-11-25T11:49:24.830Z caller=node_exporter.go:115 level=info collector=zfs
Nov 25 11:49:24 amdeuc-vm3 prometheus-node-exporter[1567]: ts=2022-11-25T11:49:24.830Z caller=node_exporter.go:199 level=info msg="Listening on" address=:9100
Nov 25 11:49:24 amdeuc-vm3 prometheus-node-exporter[1567]: ts=2022-11-25T11:49:24.830Z caller=tls_config.go:195 level=info msg="TLS is disabled." http2=false

可以简单监控端口是9100



4. 配置监控机的 prometheus.xml 加入被监控的节点

  - job_name: node
    # If prometheus-node-exporter is installed, grab stats about the local
    # machine by default.
    static_configs:
      - targets: ['localhost:9100', '10.0.1.156:9100', '10.0.1.157:9100', '10.0.1.158:9100']

然后重启服务

 sudo systemctl restart prometheus

再打开 prometheus 的监控列表, 发现 已经有4个节点被监控了, 包括监控机本身
在这里插入图片描述

5.安装Grafana

没想到grafana居然不在ubuntu的默认仓库…

sudo wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt install grafana

安装完后检查服务有没有启动

 systemctl status grafana-server

没有就手动起来

gateman@amdeuc-vm0:/etc/prometheus$ sudo systemctl start grafana-server
gateman@amdeuc-vm0:/etc/prometheus$ sudo systemctl enable grafana-server

grafana 的默认端口是3000
再浏览器打开ip:3000, 如果见到grafana页面就代表安装好了
在这里插入图片描述



6.配置grafana

默认账号和密码都是admin 先登录再说
登录后马上要求你改密码的



6.1 添加数据源

Configuration -> Data Sources ->add data source -> Prometheus
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述



6.2 添加Dashboard

接下来我们先去下载一个模板
https://grafana.com/grafana/dashboards/?search=8919

把Json文件下载下来就好
在这里插入图片描述

然后在grafana
New Dashboard -> Import Json
就得到1个比较完善的linux主机详情模板了

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/36750.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

李宏毅2017机器学习课程 回归

李宏毅2017机器学习课程 P3 回归 Regression 下文不区分w和ω&#xff08; 文章目录李宏毅2017机器学习课程 P3 回归 Regression回归定义举例:Pokemon精灵攻击力预测(Combat Power of a Pokemon)模型步骤Step1&#xff1a;模型假设-线性模型一元线性模型&#xff08;单个特征&…

搭建lnmp+nfs+调度器

→→→大虾好吃吗←←← 目录 搭建lnmp平台 nginx配置 mysql配置 php配置 验证 nfs调度器 安装服务 nfs配置 调度器配置 验证 →→→大虾好吃吗←←← 实验目标&#xff1a;搭建lnmp平台&#xff0c;安装wordpress论坛搭建nfs&#xff0c;客户端通过调度器访问nfs论坛。 实验拓…

pandas数据分析:十分钟快速入门重点函数速查

文章目录前言一、生成Series对象和DataFrame对象二、查看数据三、获取数据3.1 获取单列数据3.2 按照标签选择数据&#xff1a;loc函数3.2 按照位置选择数据&#xff1a;iloc函数3.3 布尔索引3.4 赋值四、缺失值五、运算六、merge&#xff1a;合并DataFrame6.1 concat函数6.2 me…

体系结构31_机群计算机

目前流行的高性能并行计算机系统结构通常可以分成五类&#xff1a;并行向量处理机&#xff08;PVP&#xff09;、对称多处理机&#xff08;SMP&#xff09;、大规模并行处理机&#xff08;MPP&#xff09;、分布共享存储&#xff08;DSM&#xff09;多处理机和机群&#xff08;…

现代密码学导论-13-归约证明

目录 3.3.2 Proofs by Reduction 最后来理一遍&#xff1a; 3.3.2 Proofs by Reduction 如果我们希望证明一个给定的构造&#xff08;例如&#xff0c;加密方案&#xff09;在计算上是安全的&#xff0c;那么——除非该方案在信息理论上是安全的——我们必须依赖于未经证明的…

影像匹配基本算法(摄影测量)

影像匹配实质上是在两幅(或多幅)影像之间识别同名点&#xff0c;它是计算机视觉及数字摄影测量的核心问题。由于早期的研究一般使用相关技术解决影像匹配问题&#xff0c;所以影像匹配常常被称为影像相关。 根据影像匹配过程中匹配基元选择的不同&#xff0c;影像匹配方法可分…

iptables应用大全

iptables四表五链&#xff1a; 1、“四表”是指 iptables 的功能 ——filter 表&#xff08;过滤规则表&#xff09;&#xff1a;控制数据包是否允许进出及转发 ——nat 表&#xff08;地址转换规则表&#xff09;&#xff1a;控制数据包中地址转换 ——mangle&#xff08;修改…

【C++笔试强训】第三十天

&#x1f387;C笔试强训 博客主页&#xff1a;一起去看日落吗分享博主的C刷题日常&#xff0c;大家一起学习博主的能力有限&#xff0c;出现错误希望大家不吝赐教分享给大家一句我很喜欢的话&#xff1a;夜色难免微凉&#xff0c;前方必有曙光 &#x1f31e;。 &#x1f4a6;&a…

计算机网络——应用层重点协议【HTTP协议】

目录 1、HTTP是什么 抓包工具Fidder的下载及使用 2、HTTP协议工作过程 3、HTTP协议格式 HTTP请求&#xff1a; HTTP响应&#xff1a; 协议格式总结&#xff1a; 4、HTTP请求 4.1、URL / URI 4.1.1、URL(I)基本格式 4.1.2、URL encode 4.2、认识“方法” 4.2.1、GET…

五、ROS2接口及其使用

接口&#xff0c;即interface&#xff0c;其实是一种规范。 举个例子&#xff0c;不同厂家生产出不同类型的激光雷达&#xff0c;每种雷达的驱动方式&#xff0c;扫描速率都不相同。 当机器人进行导航时&#xff0c;需要激光雷达的扫描数据&#xff0c;假如没有统一接口&#x…

Nginx (6):nginx防盗链配置

先说一下含义&#xff0c;就是想让nginx里的静态资源只供它反向代理连接的内部服务器去访问&#xff0c;其他人想访问&#xff0c;就不给。比如01虚拟机充当nginx服务器&#xff0c;它里面存了很多静态资源&#xff0c;04虚拟机proxy_pass到01虚拟机&#xff0c;想访问它的页面…

Linux--信号量共享内存

1.基础知识&#xff1a; &#xff08;1&#xff09;共享内存是最快的IPC形式。一旦这样的内存映射到共享它的进程的地址空间&#xff0c;这些进程间的数据传递不再涉及内核&#xff0c;即进程不再通过执行进入内核的系统调用来传递彼此的数据。 &#xff08;2&#xff09;共享…

MySQL浅析之架构概览

MySQL主要分为Server层&#xff0c;跟存储引擎层。 Server层负责“逻辑处理”&#xff0c;包括连接器、分析器、优化器、执行器以及所有内置函数。所有跨存储引擎的功能都在这一层实现&#xff0c;比如存储过程、触发器、视图等。 存储引擎层跟文件系统交互&#xff0c;负责数…

bug探索之路:List<Map>get取出元素却是String?

一、bug初现峥嵘 有一说一我定义的List<Map>对吧&#xff0c;我get(0)取出的元素也应该是Map类型没问题吧。不行&#xff0c;编译器告诉我&#xff0c;java.lang.String cannot be cast to java.util.Map。 这个意思就是说&#xff0c;你这个就是String类型&#xff0c;…

Spring Cloud Gateway夺命连环10问?

这篇文章介绍下微服务中的一个重要角色&#xff1a;网关&#xff0c;对于网关如何选择&#xff0c;由于阿里系暂时未出网关&#xff0c;当然是选择了Spring cloud Gateway&#xff0c;毕竟是亲儿子。 文章目录如下&#xff1a; ​ 编辑切换为居中 添加图片注释&#xff0c;不…

[附源码]java毕业设计智能超市导购系统

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; SSM mybatis Maven Vue 等等组成&#xff0c;B/S模式 M…

【科学文献计量】RC.networkBibCoupling()中的参数解释

RC.networkBibCoupling中的参数解释 1 数据2 RC.networkBibCoupling()中的参数解释2.1 测试weighted参数2.2 测试fullInfo参数2.3 测试addCR参数1 数据 使用web of science中的数据,借助metaknowledge库读入到python中,然后截取2020-2021年的数据构建网络 2 RC.networkBib…

CrystalNet ADO.Net VCL for Delphi

CrystalNet ADO.Net VCL for Delphi ADO。用于Delphi的Net DAC被描述为数据库的最快和最可靠的连接&#xff0c;以及使用ADO技术的虚拟和数据库的替代方案。NET在Delphi。它能够为用户和开发人员提供对信息源的数据访问&#xff0c;这些信息源不喜欢SQL Server、Oracle、Vista…

Flutter高仿微信-第42篇-创建群

Flutter高仿微信系列共59篇&#xff0c;从Flutter客户端、Kotlin客户端、Web服务器、数据库表结构、Xmpp即时通讯服务器、视频通话服务器、腾讯云服务器全面讲解。 详情请查看 效果图&#xff1a; 实现代码&#xff1a; /*** Author : wangning* Email : maoning20080809163.c…

ARM S5PV210的启动过程

一、内存 SRAM 静态内存 特点就是容量小、价格高&#xff0c;优点是不需要软件初始化直接上电就能用。DRAM 动态内存 特点就是容量大、价格低&#xff0c;缺点就是上电后不能直接使用&#xff0c;需要软件初始化后才可以使用。 单片机中&#xff1a;内存需求量小&#xff0c;而…