怎样安装Prometheus监控平台
Prometheus的组件
Prometheus生态系统由多个组件组成,它们中的一些是可选的。多数Prometheus组件是Go语言写的,这使得这些组件很容易编译和部署。
- Prometheus Server
主要负责数据采集和存储,提供PromQL查询语言的支持。
- 客户端SDK
官方提供的客户端类库有go、java、scala、python、ruby,其他还有很多第三方开发的类库,支持nodejs、php、erlang等。
- Push Gateway
支持临时性Job主动推送指标的中间网关。
- Exporter
Exporter是Prometheus的一类数据采集组件的总称。它负责从目标处搜集数据,并将其转化为Prometheus支持的格式。与传统的数据采集组件不同的是,它并不向中央服务器发送数据,而是等待中央服务器主动前来抓取。
Prometheus提供多种类型的Exporter用于采集各种不同服务的运行状态。目前支持的有数据库、硬件、消息中间件、存储系统、HTTP服务器、JMX等。
- alertmanager
警告管理器,用来进行报警。
Prometheus适用的场景
Prometheus在记录纯数字时间序列方面表现非常好。它既适用于面向服务器等硬件指标的监控,也适用于高动态的面向服务架构的监控。对于现在流行的微服务,Prometheus的多维度数据收集和数据筛选查询语言也是非常的强大。Prometheus是为服务的可靠性而设计的,当服务出现故障时,它可以使你快速定位和诊断问题。它的搭建过程对硬件和服务没有很强的依赖关系。
Prometheus不适用的场景
Prometheus它的价值在于可靠性,甚至在很恶劣的环境下,你都可以随时访问它和查看系统服务各种指标的统计信息。如果你对统计数据需要100%的精确,它并不适用,例如:它不适用于实时计费系统。
prometheus官网
https://prometheus.io
下载node_exporter
node_exporter收集远程机器的监控数据,提供给Prometheus定时来抓取。
一、安装node_exporter
安装所需要的包
yum install wget net-tools bash-comp* vim -y
1、下载node_exporter
[root@prometheus ~]# wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
2、解压并移动到/usr/local下面
[root@localhost ~]# tar xf node_exporter-1.3.1.linux-amd64.tar.gz
[root@localhost ~]# mv node_exporter-1.3.1.linux-amd64 /usr/local/node_exporter
3、启动node_exporter服务
[root@prometheus ~]# cd /usr/local/node_exporter/
[root@prometheus node_exporter]# nohup ./node_exporter &
查看服务

二、prometheus安装
1、下载prometheus
[root@localhost ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.37.0/prometheus-2.37.0.linux-amd64.tar.gz
2、解压并移动到/usr/local
[root@prometheus node_exporter]# tar xf prometheus-2.18.0.linux-amd64.tar.gz
[root@prometheus node_exporter]# mv prometheus-2.18.0.linux-amd64 /usr/local/prometheus
3、编辑配置文件
编辑prometheus.yml, 将node_exporter添加到Prometheus目标对象,因为这里node_exporter和Prometheus安装在同一台机器,使用localhost即可,node_exporter端口9100
[root@prometheus node_exporter]# cd /usr/local/prometheus/
[root@prometheus prometheus]# cp prometheus.yml prometheus.yml.bak
[root@prometheus prometheus]# vim prometheus.yml

4、启动prometheus(指定配置文件来启动)
[root@prometheus prometheus]# nohup ./prometheus --config.file=prometheus.yml &
5、查看服务

6、浏览器打开(IP+9090)
如果没有关闭防火墙请关闭防火墙,或者防火墙放开9090端口号
[root@prometheus prometheus]# firewall-cmd --permanent --add-port=9090/tcp
[root@prometheus prometheus]# firewall-cmd --reload

查看Targets

三、Grafana 安装
Grafana 是一个开箱即用的可视化工具,具有功能齐全的度量仪表盘和图形编辑器,有灵活丰富的图形化选项,可以混合多种风格,支持多个数据源特点。
1、下载并安装
下载地址
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.0.4-1.x86_64.rpm
[root@prometheus ~]# rpm -ivh grafana-6.2.5-1.x86_64.rpm
警告:grafana-6.2.5-1.x86_64.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID 24098cb6: NOKEY
错误:依赖检测失败:
fontconfig 被 grafana-6.2.5-1.x86_64 需要
urw-fonts 被 grafana-6.2.5-1.x86_64 需要
安装依赖包‘
[root@prometheus ~]# yum install fontconfig urw-fonts -y
#centos为例
wget https://dl.grafana.com/oss/release/grafana-6.7.3-1.x86_64.rpm
sudo yum install grafana-6.7.3-1.x86_64.rpm

2、启动服务
[root@prometheus ~]# service grafana-server start

3、访问服务(IP+3000端口号)
放开防火墙
[root@prometheus ~]# firewall-cmd --permanent --add-port=3000/tcp
[root@prometheus ~]# firewall-cmd --reload

输入用户名和密码进行登陆admin/admin,第一次登陆要进行修改密码

访问地址:IP:3000 账号密码:admin/admin 二进制文件:/usr/sbin/grafana-server 启动文件:/etc/init.d/grafana-server 启动环境变量:/etc/sysconfig/grafana-server 配置文件:/etc/grafana/grafana.ini systemd服务名称:grafana-server.service 默认配置的日志文件:var/log/grafana/grafana.log sqlite3数据库文件:/var/lib/grafana/grafana.db
四、grafana配置prometheus
1、选择数据源

2、添加数据源

3、选择prometheus

4、输入对应参数

5、下载模板

选择需要下载的模板

导入模板

选择下载好的模板

选择数据源prometheus,并输入名字

查看监控效果图

安装完!!!
文档参考自: https://www.yangxingzhen.com/6625.html
感谢大神分享!!!
如有侵权请速与我联系,邮箱:root@cnbugs.com。谢谢