<返回更多

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

2020-06-15    
加入收藏
CentOS7下简单搭建Prometheus+Grafana监控系统

 

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

1、Features

Prometheus's main features are:

2、Components

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

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:

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

 

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

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

 


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

 

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

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

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

 

上传安装包到CentOS7服务器上

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

 

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 *

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

 

prometheus配置文件语法校验方法

./promtool check config prometheus.yml

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

 

先采用默认配置启动Prometheus Server

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

 

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

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

 

设置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

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

 

启动参数说明:

--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

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

 

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

排错

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

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

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

 

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

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

 

创建系统服务

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

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

 

启动node_exporter并设置为开启自启动

systemctl enable node_exporter.service

systemctl start node_exporter.service

systemctl status node_exporter.service

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

 

启动成功,测试API访问

http://192.168.31.80:9100/metrics

能正常返回数据说明node_exporter正常

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

 

并将其加入prometheus.yml配置文件中

- job_name: 'CentOS7_VMServer'

static_configs:

- targets: ['192.168.31.80:9100']

然后重启服务

systemctl restart prometheus.service

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

 

这是再登录prometheus 的Web界面可以看到新增的这个Target

http://192.168.31.80:9090/targets

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

 

4、安装Grafana图形化工具包

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

 

缺少组件包的情况,使用

yum localinstall grafana-6.7.3-1.x86_64.rpm

systemctl enable grafana-server.service

systemctl start grafana-server.service

systemctl status grafana-server.service

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

 

5、配置数据源并添加Dashboard

1)、登录grafana,默认端口3000,初始账号/密码:admin/admin

http://192.168.31.80:3000/

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

 


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

 

2)添加数据源

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

 

示例:Name CentOS7_VM_Prometheus

URL :http://192.168.31.80:9090

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

 

3)添加一个DashBoard,Import 例如8919 ID这个

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

 


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

 


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

 


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

 

效果如下(点击图片查看清晰大图)

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

 

总结:

Prometheus vs Zabbix

声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>