linux安装prometheus

安装prometheus的步骤

  1. 安装go 语言环境
  2. 在监控服务器上安装prometheus
  3. 在被监控环境上安装export
  4. 安装grafana

前期准备工作

根据我们自己的业务需求创建安装prometheus的用户和组
我创建www用户和test用户的组
创建www用户

useradd  wwww   创建www用户

创建www用户的组test

groupadd test

创建www用户并加入已经创建的test组

useradd -g www test

步骤1:安装go 语言环境

由于Prometheus 是用golang开发的,所以首先安装一个go环境,Go语言是跨平台,支持Windows、Linux、Mac OS X等系统,还提供有源码,可编译安装

linux:https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz

下载后,上传到要部署的服务器(部署服务器和外网隔离,所以转了一道)。解压缩然后修改配置文件

rz  prometheus-2.24.1.linux-amd64.tar.gz  上传到服务器
tar -xvf prometheus-2.24.1.linux-amd64.tar.gz  -C /usr/local/   将prometheus解压到/usr/local文件夹下
vim /etc/profile  然后编译linux的系统环境变量 将promethues加入到系统的环境变量中

在文件的最后添加

export PATH=$PATH:/usr/local/go/bin

在这里插入图片描述

然后运行

source /etc/profile 让配置文件生效

在运行完配置文件后运行 ll yum 等命令 有时候会报错: command is not found
这个时候就是环境变量文件配置出错了我们要手动声明环境变量

export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

然后再修改/etc/profile文件来进行参数的
参考: https://www.cnblogs.com/flyingeagle/articles/9236582.html
Linux修改/etc/profile配置错误command is not found自救方法

go安装好后验证go是否安装成功

go version

在这里插入图片描述

出现上面的go的版本信息,既是安装成功

步骤2:在监控服务器上安装prometheus

开始安装prometheus,首先先去官网下载对应系统的版本:https://prometheus.io/download/,
下载对应的linux版本
在这里插入图片描述

然后进行文件的上传到linux服务器上
下载后上传到部署的服务器,在服务上执行如下命令解压(root用户,解压到 /usr/local):

tar -xvf prometheus-2.24.1.linux-amd64.tar.gz -C /usr/local/

为了以后进入目录方便,做了一个软连接:

 ln -sv /usr/local/prometheus-2.24.1.linux-amd64/ /usr/local/Prometheus

然后进入/usr/local中既可以看到对应的软链接
在这里插入图片描述
接下来我们进入/usrlocal/Prometheus 软链接中进行服务的启动和配置

cd /usr/local/Prometheus

启动prometheus

nohup ./prometheus &

在这里插入图片描述

prometheus的默认访问端口是9090我们prometheus服务
在这里插入图片描述

这个时候我们的promethues还只是什么服务器和服务都没有监控呢 我们要监控其他的服务器要搭配node_export来使用

步骤3:在系统层用作系统监控exporter

安装exporter ,这台linux环境是redhat ip:10.138.108.8,因此用的监控export是node_exporter-0.16.0.linux-amd64.tar.gz ,首先在官网下载这个文件,然后上传到被监控的主机(作为部署服务的主机上也需要安装 export),因此下载并部署后,执行如下命令:
下载node_export
https://github.com/prometheus/node_exporter/releases

tar -xvf node_exporter-1.0.1.linux-amd64.tar.gz -C /usr/local/

然后进入到/usr/local/node_exporter-1.0.1.linux-amd64中启动node_export服务

nohup ./node_export & 默认端口9100启动
nohup ./node_exporter  --web.listen-address=":9101" &  指定端口为9101启动

这个时候就是已经对10.138.108.8这台机器进行了机器的监控我们可以去prometheus中进行此服务器监控的配置就可以获取到监控信息

4 prometheus配置信息

我们进入安装prometheus的服务器中进行配置文件的修改

进入到prometheus安装目录

vim prometheus.yml

加入以下配置

  - job_name: 'linux' 
    static_configs:
    - targets: ['10.138.108.8:9101']

在这里插入图片描述
yml的配置信息修改的时候一定要上下对齐,不可以使用tab键盘,并且yml的所经和上下对齐一定要严格配置,否则启动会报错
修改完配置信息我们再启动prometheus然后让配置生效

通过如下URL可以打开prometheus的自带监控界面: IP:9090,点击targets 跳转到监控目标,这里展现了多个监控对象。红框的表示部署的prometheus

在这里插入图片描述

在这里插入图片描述

步骤5:安装grafana 优化展示界面

上面的监控界面是如此的丑我们可以安装grafana 来优化展示界面信息
下面grafana :https://grafana.com/grafana/download

解压安装包

tar -xvf grafana-7.3.7.linux-amd64.tar.gz 

然后进入到解压的grafana中进行服务的运行

cd grafana-7.3.7/bin/
./grafana-server  start 运行grafana软件

grafana的默认启动端口是3000
启动后,打开如下URL,端口采用默认的3000,http://10.138.108.9:3000/
在这里插入图片描述

输入默认的admin/admin

配置grafana和prometheus
添加Prometheus数据源
Configuration -> Data Sources ->add data source -> Prometheus

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

在这里插入图片描述

在这里插入图片描述

新增Dashboard
Create -> import
然后导入展示模板
在这里插入图片描述
模板我们可以直接搜索8919
在这里插入图片描述
从 https://grafana.com/grafana/dashboards 搜索 相应 dashboards的id如8919,然后load。
选择 Prometheus数据源,最后import。
如果搜索不到我们下载对应模板然后再import即可

查看Dashboard
Dashboards ->Manage

在这里插入图片描述
这个时候就完成了grafana和prometheus的结合展示

参考:https://www.cnblogs.com/yqq-blog/p/13712663.html
参考: https://www.cnblogs.com/flyingeagle/articles/9236582.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Lovely_red_scarf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值