prometheus+grafana+node_exporter服务器性能监控搭建

作为一个测试工程师,什么都要懂一点、
在公司做性能测试,目前除了shell脚本没办法进行监控服务器的cpu和内存,代码不好的我的觉得太麻烦了,所以想着搭建一个监控平台试试、

进入主题~~~

本文是在阿里云服务器进行prometheus+grafana+node_exporter搭建的、
我只是搭建在一个服务器上面,有条件的可以搭建到两到三个服务器、
注意的是node_exporter必须搭建在被监控的服务器上面、

准备条件
1、要先知道阿里云服务器的外网地址;不要在Linux上用ifconfig查看,那只是个内网地址;
2、要在阿里云安全组上面配置需要用到的接口;这个是一定是需要配置的;需要配置的接口大概有9090、3000、9100,这都是那三个的默认接口;
方法:https://developer.aliyun.com/article/767328
3、关闭防火墙或者放行配置的接口;
方法:https://editor.csdn.net/md?articleId=117395151
4、创建目录,方便管理;我是在/data下创建node、prometheus、grafana目录;

开始搭建

prometheus官网地址:https://prometheus.io/download/

  • node_exporter
    可以先官网下载,然后放到Linux上;也可以在Linux上使用wget下载;
    我这里使用的是wget下载,首先先去官网拿到对应版本的地址;
    如下图:
    在这里插入图片描述
#进入node目录,下载node_exporter
wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz
#解压
tar -zxvf node_exporter-1.1.2.linux-amd64.tar.gz
#进入启动目录
cd node_exporter-1.1.2.linux-amd64
#启动,使用隐形启动
nohup ./node_exporter>node.logs 2>&1 &

验证启动成功:输入服务器ip+9100;http://127.0.0.1:9100
在这里插入图片描述

  • prometheus
    首先先去官网拿到对应版本的地址;
    如下图:
    在这里插入图片描述
#进入prometheus目录下载
wget https://github.com/prometheus/prometheus/releases/download/v2.27.1/prometheus-2.27.1.linux-amd64.tar.gz
#解压
tar -zxvf prometheus-2.27.1.linux-amd64.tar.gz
#进入启动目录
cd  prometheus-2.27.1.linux-amd64
#进行文件配置
vim prometheus.yml

#配置以下内容
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']
#追加以下内容,安装node_exporter的服务器
  - job_name: 'node_exporter-1'
    static_configs:
    - targets: ['localhost:9100'] #如何你是其他服务器的,请改成其他服务器ip

 
#启动,使用隐形启动
nohup ./prometheus>prometheus.log 2>&1 &

每个job_name标签标示一个监控的job
targets 标签标示受监控的应用的 ip和端口号
注意:这个配置文件要特别注意格式缩进,严格按照他原来的格式来修改,不然会导致prometheus运行不了。
验证启动成功:浏览器访问 服务器ip+9090
在这里插入图片描述

  • grafana
    grafana官网:https://grafana.com/grafana/download
    在这里插入图片描述
    根据官网的指导下载就好了
#进入grafana目录下载
wget https://dl.grafana.com/oss/release/grafana-7.5.7-1.x86_64.rpm

sudo yum install grafana-7.5.7-1.x86_64.rpm
#启动
systemctl start grafana-server

验证启动成功:服务器ip+3000
在这里插入图片描述
注意:如果启动失败,一般是因为端口被占用了;可以使用lsof -i : 端口 查看那个进程被占用;然后使用kill -9 进程号 杀掉进程重新启动就好了

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值