CentOS7下简单搭建Prometheus+Grafana监控系统(上)

简介: CentOS7下简单搭建Prometheus+Grafana监控系统

640.jpg


Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud.


1、Features


Prometheus's main features are:

a multi-dimensional data model with time series data identified by metric name and key/value pairs

PromQL, a flexible query language to leverage this dimensionality

no reliance on distributed storage; single server nodes are autonomous

time series collection happens via a pull model over HTTP

pushing time series is supported via an intermediary gateway

targets are discovered via service discovery or static configuration

multiple modes of graphing and dashboarding support


2、Components


The Prometheus ecosystem consists of multiple components, many of which are optional:

the main Prometheus server which scrapes and stores time series data

client libraries for instrumenting application code

a push gateway for supporting short-lived jobs

special-purpose exporters for services like HAProxy, StatsD, Graphite, etc.

an alertmanager to handle alerts

various support tools

Most Prometheus components are written in Go, making them easy to build and deploy as static binaries.


3、Architecture


This diagram illustrates the architecture of Prometheus and some of its ecosystem components:

640.png


Prometheus scrapes metrics from instrumented jobs, either directly or via an intermediary push gateway for short-lived jobs. It stores all scraped samples locally and runs rules over this data to either aggregate and record new time series from existing data or generate alerts. Grafana or other API consumers can be used to visualize the collected data.


下面介绍CentOS7下简单搭建Prometheus+Grafana监控系统


1、先官网下载安装包

https://prometheus.io/download/
1)prometheus-2.17.2.linux-amd64.tar.gz
2)node_exporter-0.18.1.linux-amd64.tar.gz

640.png

grafana官网下载:https://grafana.com/grafana/download

3)https://dl.grafana.com/oss/release/grafana-6.7.3-1.x86_64.rpm


640.png


上传安装包到CentOS7服务器上

640.png


2、安装并配置prometheus服务端

groupadd prometheus
useradd -g prometheus -m -d /opt/prometheus/ -s /sbin/nologin prometheus
tar -zxf /data/prometheus-2.17.2.linux-amd64.tar.gz -C /opt
cd /opt/
mv prometheus-2.17.2.linux-amd64/* prometheus
cd prometheus
chown -R prometheus *

640.png

prometheus配置文件语法校验方法


./promtool check config prometheus.yml

640.png

先采用默认配置启动Prometheus Server

640.png


登录Prometheus Server的Web界面http://192.168.31.80:9090可以看到只有一个Targets:http://127.0.0.1:9090/metrics


640.png

设置Prometheus为系统服务,并配置为开机自启动

touch /usr/lib/systemd/system/prometheus.service
chown prometheus:prometheus /usr/lib/systemd/system/prometheus.service
vi /usr/lib/systemd/system/prometheus.service

并加入如下配置

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/opt/prometheus/data --storage.tsdb.retention=60d
Restart=on-failure
[Install]
WantedBy=multi-user.target

640.png

启动参数说明:


--config.file -- 指明prometheus的配置文件路径

--web.enable-lifecycle -- 指明prometheus配置更改后可以进行热加载

--storage.tsdb.path -- 指明监控数据存储路径

--storage.tsdb.retention --指明数据保留时间


启动服务,并设置为开机自启动

systemctl daemon-reload
systemctl enable prometheus.service
systemctl start prometheus.service 
systemctl status prometheus.service

640.png

可以看到已经报错了,服务未正常启动


排错


/opt/prometheus下data目录属主不对导致


解决办法:chown -R prometheus:prometheus *


640.png


3、安装node_exporter


比如就在该服务器上安装node_exporter

cd /data
tar -zxf node_exporter-0.18.1.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv node_exporter-0.18.1.linux-amd64 node_exporter
cd node_exporter/
ll -trh

640.png

创建系统服务

touch /usr/lib/systemd/system/node_exporter.service 
chown prometheus:prometheus /usr/lib/systemd/system/node_exporter.service 
chown -R prometheus:prometheus /usr/local/node_exporter* 
vi /usr/lib/systemd/system/node_exporter.service

加入如下行

[Unit]
Description=node_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target

640.png

相关文章
|
4月前
|
存储 Ubuntu Linux
VMware-安装CentOS系统教程及安装包
虚拟机相当于是一个独立于你电脑的环境,在这个环境上面,你可以安装Linux、Windows、Ubuntu等各个类型各个版本的系统,在这个系统里面你不用担心有病读等,不用担心文件误删导致系统崩溃。 虚拟机也和正常的电脑系统是一样的,也可以开关机,不用的时候,你关机就可以了,也不会占用你的系统资源,使用起来还是比较方便 这里也有已经做好的CentOS 7系统,下载下来解压后直接用VMware打开就可以使用
856 69
|
2月前
|
监控 关系型数据库 MySQL
在CentOS系统中,如何统计哪个进程打开了文件描述符?
利用上述方法,你可以有效地监控和统计CentOS系统中的进程打开的文件描述符数量,以帮助排查错误或优化系统配置。通过组合使用各种工具和命令,可以获得对系统状态和行为的深入了解,进而做出相应的调整和
149 5
|
4月前
|
Ubuntu Linux 索引
Centos 7、Debian及Ubuntu系统中安装和验证tree命令的指南。
通过上述步骤,我们可以在CentOS 7、Debian和Ubuntu系统中安装并验证 `tree`命令。在命令行界面中执行安装命令,然后通过版本检查确认安装成功。这保证了在多个平台上 `tree`命令的一致性和可用性,使得用户无论在哪种Linux发行版上都能使用此工具浏览目录结构。
415 78
|
5月前
|
缓存 NoSQL Linux
在CentOS 7系统中彻底移除MongoDB数据库的步骤
以上步骤完成后,MongoDB应该会从您的CentOS 7系统中被彻底移除。在执行上述操作前,请确保已经备份好所有重要数据以防丢失。这些步骤操作需要一些基本的Linux系统管理知识,若您对某一步骤不是非常清楚,请先进行必要的学习或咨询专业人士。在执行系统级操作时,推荐在实施前创建系统快照或备份,以便在出现问题时能够恢复到原先的状态。
468 79
|
4月前
|
缓存 监控 Linux
CentOS系统如何查看当前内存容量。
以上方法都不需要特殊软件或者复杂配置即可执行,在CentOS或其他Linux发行版中都适合运行,并且它们各自透露出不同角度对待问题解答方式:从简单快速到深入详尽;从用户态到核心态;从操作层数到硬件层数;满足不同用户需求与偏好。
355 8
|
6月前
|
机器人 Linux
CentOS 7系统中安装特定版本CMake 3.21.2的方法。
到这里,过程已经全部完成。如果你跟随上面的步骤来,那么你现在已经拥有了一个全新的CMake版本在你的CentOS 7系统上了。这个过程就像是你通过一系列仪式,唤醒了一个沉睡已久的古老机器人,它现在完全按照你的意愿来帮你构建和编译软件了。
535 18
|
4月前
|
存储 Linux 数据安全/隐私保护
确定CentOS系统分区表类型(MBR或GPT)
以上方法均能够帮助用户准确地识别出CentOS下连接硬件所应用得具体磁盘标准,并根据实际需求做进一步处理与管理工作。
516 0
|
4月前
|
Ubuntu Linux 云计算
CentOS与Ubuntu:Linux系统的双璧
选择Ubuntu还是CentOS,取决于用户的具体需求,如是否需要图形化界面、对稳定性的要求、软件包管理的偏好以及对商业支持的需求等。两者都是优秀的Linux发行版,只是在设计理念和目标用户群体上有所不同。#深度好文计划#
|
6月前
|
安全 Linux 网络安全
在CentOS 7系统上创建SSL/TLS证书以启用HTTPS
请记住,这只是单枚勋章,在野外,CA签发的证书才是堂堂正正的金盾牌。如果您打算让这个小兵走得更远,考虑一下像Let's Encrypt这样的免费CA服务,它会给您的小兵颁发一个大家都认可的荣誉勋章。而且,千万不要忘了定期更新您的装备哦,毕竟,没有哪件盔甲是永远坚不可摧的。
365 4
|
6月前
|
Cloud Native 安全 Linux
龙蜥操作系统:CentOS 谢幕之后,国产云原生系统的崛起之路
龙蜥操作系统(Anolis OS)是 CentOS 停止维护后,由阿里云等企业联合发起的开源项目。它以双内核架构和全栈优化为核心,提供无缝替代 CentOS 的方案,兼容主流生态并针对云计算场景深度优化。其技术亮点包括 RHCK 和 ANCK 双内核、性能优化、全栈安全及国密算法支持。龙蜥适用于云原生基础设施、企业级应用部署及开发环境,社区已吸引 200 多家单位参与。未来规划涵盖 AI 框架优化、RISC-V 架构适配及桌面环境构建,正重新定义云时代的操作系统边界。
1490 0

热门文章

最新文章