首页 > 其他分享 >搭建服务端性能监控系统 Prometheus 详细指南

搭建服务端性能监控系统 Prometheus 详细指南

时间:2024-06-19 18:33:35浏览次数:13  
标签:sudo prometheus apt Prometheus docker yml 服务端 搭建

前言

在现代软件开发中,性能监控是确保系统稳定性和性能优化的重要环节。Prometheus 是一个开源的系统监控和报警工具,广泛用于容器化环境和微服务架构。本指南将详细介绍如何在服务器上搭建 Prometheus 性能监控系统。

安装 Prometheus

  1. 环境准备

确保你的服务器上已经安装了以下软件:

  • 操作系统:Linux (本文以 Ubuntu 为例)
  • Docker(可选,但推荐用于简化部署)
  • Git (用于获取 Prometheus 配置示例)
  1. 安装 Docker

如果尚未安装 Docker,可以通过以下命令安装:

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce
  1. 启动 Prometheus 容器

使用 Docker 拉取并启动 Prometheus 容器:

docker run -d \
  --name=prometheus \
  -p 9090:9090 \
  -v /path/to/prometheus.yml:/etc/prometheus/prometheus.yml \
  prom/prometheus

在上述命令中,/path/to/prometheus.yml 是你本地 Prometheus 配置文件的路径。

配置 Prometheus

  1. 下载默认配置文件

可以从 Prometheus 官方 GitHub 仓库获取默认配置文件:

git clone https://github.com/prometheus/prometheus.git
cd prometheus
cp documentation/examples/prometheus.yml /path/to/your/prometheus.yml
  1. 修改配置文件

打开 prometheus.yml 文件,修改以下内容以适应你的监控需求:

global:
  scrape_interval: 15s # 全局抓取间隔

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

可以根据需要添加更多的抓取目标(targets)。

安装 Node Exporter

Node Exporter 是 Prometheus 官方提供的一个用来收集系统硬件和操作系统相关指标的数据导出器。

  1. 下载和运行 Node Exporter
docker run -d \
  --name=node_exporter \
  -p 9100:9100 \
  prom/node-exporter
  1. 配置 Prometheus 抓取 Node Exporter 数据

prometheus.yml 中添加以下内容:

scrape_configs:
  - job_name: 'node_exporter'
    static_configs:
      - targets: ['localhost:9100']

启动 Prometheus

完成配置文件的修改后,重新启动 Prometheus 容器:

docker restart prometheus

访问 http://<your_server_ip>:9090,你将看到 Prometheus 的 Web 界面。

总结

本文主要介绍了搭建Prometheus 性能监控系统,后续我们将继续介绍使用Grafana 来做到数据的实时展示。

标签:sudo,prometheus,apt,Prometheus,docker,yml,服务端,搭建
From: https://www.cnblogs.com/hogwarts/p/18257022

相关文章

  • 【云服务器介绍】选择指南 腾讯云 阿里云全配置对比 搭建web 个人开发 app 游戏服务器
    ​省流目录:适用于博客建站(2-4G)、个人开发/小型游戏[传奇/我的世界/饥荒](4-8G)、数据分析/大型游戏[幻兽帕鲁/雾锁王国]服务器(16-64G)1.京东云-618专属活动 官方采购季专属活动地址:京东云-618采购季服务器活动专区https://3.cn/20-J4jjX京东云又双叒降价了!活动页大改,增加两......
  • linux中搭建mysql服务
    下载mysql安装包wgethttps://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz解压压缩包tar-xvfmysql-5.7.27-linux-glibc2.12-x86_64.tar.gz#移动文件夹mvmysql-5.7.27-linux-glibc2.12-x86_64/usr/local/mysqlmysql用......
  • docker(ubuntu18.04) + 宿主机(ubuntu20.04) + ROS + 乐视三合一体感摄像头LeTMC-520
    参考链接:https://blog.csdn.net/weixin_45225720/article/details/1144642441.准备docker环境dockerpullhyeonjaegil/vins-monodockerrun-it--privileged--networkhost--gpusall\-v/tmp/.X11-unix:/tmp/.X11-unix\-eDISPLAY-eNVIDIA_VISIBLE_DEVIC......
  • 从0到1使用vite搭建react项目保姆级教程(持续更新中)
    一、vite创建react项目要使用Vite创建一个React项目,你需要按照以下步骤操作:1、确保你已经安装了Node.js(建议使用最新的稳定版本)。2、使用npm命令安装ViteCLI工具,再来创建项目npmcreatevite@latestmy-vite-app 3、运行上述命令后,按照提示选择“create-react-app”......
  • 开发Prometheus的redis bigkey exporter,完善k8s下redis容器的性能监控
      好久没来博客园写技术总结了,回顾这些年的职业路径,从自动化测试到python后端到golang后端直到现在的devops,确实积累了很多心得,可惜都没时间来写写这些心得(主要是懒)。自从转为devops后确实有比较多的时间了(主要是加班少:)),看来以后还是要多写写技术总结:)。   废话不......
  • hbase-2.2.7分布式搭建
    hbase-2.2.7分布式搭建文档1、上传解压配置环境变量#1、解压tar-xvfhbase-2.2.7-bin.tar.gz.gz#2、配置环境变量vim/etc/profile#3、在最后增加配置exportHBASE_HOME=/usr/local/soft/hbase-2.2.7exportPATH=$PATH:$HBASE_HOME/bin#4、使环境变量剩下source......
  • 苍穹外卖环境搭建
    一、前端环境搭建①整体结构 ②前端工程基于nginx运行启动nginx:双击nginx.exe即可启动nginx服务,访问端口号为80进入浏览器地址输入locallhost回车二、后端环境搭建 后端初始工程基于maven进行项目构建,并且进行分模块开发(1)idea打开初始工程,了解项......
  • 在 windows 上搭建一台 Linux
    前言看这篇文章之前,首先得要给大家先介绍一下什么是虚拟机。虚拟机是一种软件,它可以在一台物理服务器上,也就是我们平时所使用的电脑,虚拟出多台逻辑服务器,这个逻辑服务器怎么理解呢?逻辑服务器是指在物理服务器基础上,通过虚拟化技术或软件配置来划分和管理的虚拟服务器。它不......
  • 【Playwright+Python】系列教程(一)环境搭建及脚本录制
    一、前言看到这个文章,有的同学会说:六哥,你为啥不早早就写完python系列的文章。因为有徒弟需要吧,如果你也想学自学,那这篇文章,可以说是我们结缘一起学习的开始吧!如果对你有用,建议收藏和转发!二、Playwright是什么?微软开源自动化测试工具Playwright,支持主流浏览器,包括:Chrome、Fir......
  • nacos-gateway搭建
    引入依赖<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId>&l......