Prometheus 安装、部署、出图+grafana


文章目录

  • Prometheus 安装、部署、出图+grafana
  • 前言
  • 一、Prometheus安装与部署
  • 1.1、go环境部署
  • 1.2、安装普罗米修斯prometheus
  • 二、安装常用监控exporter
  • 2.1、安装并启动
  • 三、Grafana
  • 3.1、准备
  • 3.2、安装
  • 3.3、对接prometheus
  • 3.4、重新对接一个新面板json


前言

prometheus配置redis密码 prometheus部署_prometheus配置redis密码


Prometheus 服务器

Prometheus Server 是 Prometheus组件中的核心部分,负责实现对监控数据的获取,存储以及查询。

NodeExporter 业务数据源

业务数据源通过 Pull/Push 两种方式推送数据到 Prometheus Server。

AlertManager 报警管理器

Prometheus 通过配置报警规则,如果符合报警规则,那么就将报警推送到 AlertManager,由其进行报警处理。

可视化监控界面

Prometheus 收集到数据之后,由 WebUI 界面进行可视化图标展示。目前我们可以通过自定义的 API 客户端进行调用数据展示,也可以直接使用 Grafana 解决方案来展示

简单地说,Prometheus 的实现架构也并不复杂。其实就是收集数据、处理数据、可视化展示,再进行数据分析进行报警处理。 但其珍贵之处在于提供了一整套可行的解决方案,并且形成了一整个生态,能够极大地降低我们的研发成本。

prometheus配置redis密码 prometheus部署_linux_02

一、Prometheus安装与部署

1.1、go环境部署

首先安装运行环境go
有网络环境直接运行下面命令行
yum -y install go
无网络离线安装
下载go的安装包
Golang官网下载地址:https://golang.org/dl/
按照包版本:go1.18.2.linux-amd64.tar.gz
将安装包解压放到到usr/local中,并解压

[root@shigj ~]# vim /etc/profile
export PATH=$PATH:/usr/local/go/bin
[root@shigj ~]# source /etc/profile
[root@shigj ~]# go version
go version go1.18 linux/amd64

1.2、安装普罗米修斯prometheus

开始安装prometheus,首先先去官网下载对应系统的版本
https://prometheus.io/download/ 解压并重命名

[root@shigj local]# tar -zxvf prometheus-2.35.0.linux-amd64.tar.gz
[root@shigj local]# mv prometheus-2.35.0.linux-amd64 prometheus

切换到目录下

[root@shigj local]# cd prometheus/
[root@shigj prometheus]# ls
console_libraries  consoles  LICENSE  NOTICE  prometheus  prometheus.yml  promtool

接着要配置一下监控的配置文件:prometheus.yml
localhost修改为IP地址
启动 prometheus服务

[root@shigj prometheus]# /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &
[1] 25131

prometheus配置redis密码 prometheus部署_linux_03


表示成功

添加服务并设置开机启动

[root@shigj prometheus]# pwd
/usr/local/prometheus
[root@shigj prometheus]# touch /usr/lib/systemd/system/prometheus.service
[root@shigj prometheus]# vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target
[root@shigj prometheus]# systemctl daemon-reload
[root@shigj prometheus]# systemctl enable prometheus.service
Created symlink /etc/systemd/system/multi-user.target.wants/prometheus.service → /usr/lib/systemd/system/prometheus.service.
[root@shigj prometheus]# pkill prometheus
[root@shigj prometheus]# systemctl start prometheus.service
[root@shigj prometheus]# systemctl status prometheus.service
● prometheus.service - Prometheus
   Loaded: loaded (/usr/lib/systemd/system/prometheus.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-05-18 11:58:26 CST; 8s ago
     Docs: https://prometheus.io/
 Main PID: 28846 (prometheus)
    Tasks: 7 (limit: 47729)
   Memory: 19.2M
   CGroup: /system.slice/prometheus.service
           └─28846 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml

浏览器打开IP:9090端口即可打开普罗米修斯自带的监控页面

prometheus配置redis密码 prometheus部署_linux_04

prometheus配置redis密码 prometheus部署_prometheus配置redis密码_05

二、安装常用监控exporter

2.1、安装并启动

下载安装包并解压缩
https://prometheus.io/download/

[root@shigj ~]# du -sh node_exporter-1.3.1.linux-amd64.tar.gz 
6.7M	node_exporter-0.17.0.linux-amd64.tar.gz
[root@shigj ~]# mv node_exporter-1.3.1.linux-amd64.tar.gz /usr/local/
[root@shigj ~]# cd /usr/local/
[root@shigj local]# tar -zxvf node_exporter-1.3.1.linux-amd64.tar.gz 
node_exporter-1.3.1.linux-amd64/
node_exporter-1.3.1.linux-amd64/NOTICE
node_exporter-1.3.1.linux-amd64/node_exporter
node_exporter-1.3.1.linux-amd64/LICENSE

启动 node_exporter 服务

[root@shigj node_exporter]# ./node_exporter &

添加服务并设置开机启动

[root@shigj node_exporter]# touch /usr/lib/systemd/system/node_exporter.service
[root@shigj node_exporter]# vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=prometheus server daemon
[Service]
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
[root@shigj node_exporter]# systemctl daemon-reload
[root@shigj node_exporter]# systemctl enable node_exporter.service
[root@shigj node_exporter]# systemctl start node_exporter.service
[root@shigj node_exporter]# systemctl status node_exporter.service

node 监控的端口是9100

然后需要配置prometheus 的yml文件

prometheus配置redis密码 prometheus部署_运维_06


重启主机prometheus

[root@shigj prometheus]# systemctl stop prometheus.service
[root@shigj prometheus]# systemctl start prometheus.service

三、Grafana

3.1、准备

下载地址
https://grafana.com/grafana/download (prometheus)默认的页面可能没有那么直观,我们可以安装grafana使监控看起来更直观
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.5.2-1.x86_64.rpm
国外网址科学上网或许下载快一些

3.2、安装

[root@shigj local]# yum localinstall grafana-enterprise-8.5.2-1.x86_64.rpm

[root@shigj local]# /sbin/chkconfig --add grafana-server
[root@shigj local]# service grafana-server start
Starting grafana-server (via systemctl):                   [  OK  ]

启动后访问地址:ip:3000(记得开放3000端口)
初始用户名和密码都是admin
如果出现密码忘记怎么办??
重置密码下面命令行即可重置成功,密码为admin123

[root@openvpn bin]# ./grafana-cli admin reset-admin-password admin123
WARN[04-16|22:59:59] falling back to legacy setting of 'min_interval_seconds'; please use the configuration option in the `unified_alerting` section if Grafana 8 alerts are enabled. logger=settings
WARN[04-16|22:59:59] falling back to legacy setting of 'min_interval_seconds'; please use the configuration option in the `unified_alerting` section if Grafana 8 alerts are enabled. logger=settings
INFO[04-16|22:59:59] Config loaded from                       logger=settings file=/jiankong/grafana/conf/defaults.ini
INFO[04-16|22:59:59] Path Home                                logger=settings path=/jiankong/grafana
INFO[04-16|22:59:59] Path Data                                logger=settings path=/jiankong/grafana/data
INFO[04-16|22:59:59] Path Logs                                logger=settings path=/jiankong/grafana/data/log
INFO[04-16|22:59:59] Path Plugins                             logger=settings path=/jiankong/grafana/data/plugins
INFO[04-16|22:59:59] Path Provisioning                        logger=settings path=/jiankong/grafana/conf/provisioning
INFO[04-16|22:59:59] App mode production                      logger=settings
INFO[04-16|22:59:59] Connecting to DB                         logger=sqlstore dbtype=sqlite3
INFO[04-16|22:59:59] Starting DB migrations                   logger=migrator
INFO[04-16|22:59:59] migrations completed                     logger=migrator performed=0 skipped=346 duration=482.6µs

Admin password changed successfully ✔

prometheus配置redis密码 prometheus部署_运维_07

3.3、对接prometheus

添加Prometheus数据源

Configuration -> Data Sources ->add data source -> Prometheus

prometheus配置redis密码 prometheus部署_数据_08


prometheus配置redis密码 prometheus部署_数据_09


prometheus配置redis密码 prometheus部署_prometheus配置redis密码_10


返回保存

prometheus配置redis密码 prometheus部署_linux_11


prometheus配置redis密码 prometheus部署_linux_12


prometheus配置redis密码 prometheus部署_linux_13


prometheus配置redis密码 prometheus部署_数据_14

3.4、重新对接一个新面板json

已经准备好的配置文件

使用notepad打开json文件,将文件内容导入进去,如下图

模版下载地址

https://grafana.com/grafana/dashboards

prometheus配置redis密码 prometheus部署_linux_15


prometheus配置redis密码 prometheus部署_prometheus配置redis密码_16


prometheus配置redis密码 prometheus部署_运维_17


我这里已经导入完成才有这样的提示

prometheus配置redis密码 prometheus部署_linux_18


prometheus配置redis密码 prometheus部署_dashboard_19


prometheus配置redis密码 prometheus部署_运维_20