一、prometheus安装前准备

prometheus官网:https://prometheus.io/

grafana官网:https://grafana.com/

资源下载:

# 1.资源下载
wget https://github.com/prometheus/prometheus/releases/download/v2.45.4/prometheus-2.45.4.linux-amd64.tar.gz wget https://github.com/prometheus/alertmanager/releases/download/v0.27.0/alertmanager-0.27.0.linux-amd64.tar.gz wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz wget https://dl.grafana.com/enterprise/release/grafana-enterprise-10.4.2.linux-amd64.tar.gz # 2.解压到对应目录
mkdir -p /opt/prometheus
root@os:/opt/prometheus# pwd
/opt/prometheus
root@os:/opt/prometheus# ls
alertmanager grafana node_exporter prometheus # 3.创建一个专门的prometheus用户
useradd -M -s /usr/sbin/nologin prometheus # 4.修改目录权限
chown prometheus:prometheus -R /opt/prometheus

二、配置文件修改

2.1 创建system服务

# 1.prometheus服务启动文件
cat > /etc/systemd/system/prometheus.service << "EOF"
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target [Service]
Type=simple
User=prometheus
Group=prometheus
Restart=on-failure
ExecStart=/opt/prometheus/prometheus/prometheus \
--config.file=/opt/prometheus/prometheus/prometheus.yml \
--storage.tsdb.path=/opt/prometheus/prometheus/data \
--storage.tsdb.retention.time=60d \
--web.enable-lifecycle [Install]
WantedBy=multi-user.target
EOF # 详情
--config.file=/opt/prometheus/prometheus/prometheus.yml #主配置文件
--storage.tsdb.path=/opt/prometheus/prometheus/data #数据库存储目录
--web.console.libraries=/opt/prometheus/prometheus/console_libraries #指定控制台库目录路径
--web.console.templates=/opt/prometheus/prometheus/consoles #指定控制台模版目录路径
--storage.tsdb.retention=60d #指明数据保留天数,默认15天
--web.enable-lifecycle #热加载
# 2.创建altermanager启动服务
cat >/etc/systemd/system/alertmanager.service << "EOF" [Unit]
Description=Alert Manager
Wants=network-online.target
After=network-online.target [Service]
Type=simple
User=prometheus
Group=prometheus
ExecStart=/opt/prometheus/alertmanager/alertmanager \
--config.file=/opt/prometheus/alertmanager/alertmanager.yml \
--storage.path=/opt/prometheus/alertmanager/data Restart=always [Install]
WantedBy=multi-user.target EOF
# 3.创建grafana启动服务
cat >/etc/systemd/system/grafana-server.service<<"EOF"
[Unit]
Description=Grafana server
Documentation=http://docs.grafana.org
[Service]
Type=simple
User=prometheus
Group=prometheus
Restart=on-failure
ExecStart=/opt/prometheus/grafana/bin/grafana-server \
--config=/opt/prometheus/grafana/conf/defaults.ini \
--homepath=/opt/prometheus/grafana
[Install]
WantedBy=multi-user.target
EOF
# 4.创建node_exporter启动服务
cat > /etc/systemd/system/node_exporter.service <<"EOF"
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
User=prometheus
Group=prometheus
ExecStart=/opt/prometheus/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

2.2 修改配置文件

# altermanager启动前修改prometheus配置
vim /opt/prometheus/prometheus/prometheus.yml alerting:
alertmanagers:
- static_configs:
- targets:
#根据实际填写alertmanager的地址
- localhost:9093 rule_files:
#根据实际名修改文件名
- "alert.yml" # 搜刮配置
scrape_configs:
- job_name: 'alertmanager'
scrape_interval: 15s
static_configs:
- targets: ['localhost:9093'] # 触发器配置文件alert.yml
cat > /opt/prometheus/prometheus/alert.yml <<"EOF"
groups:
- name: Prometheus alert
rules:
# 对任何实例超过30秒无法联系的情况发出警报
- alert: 服务告警
expr: up == 0
for: 30s
labels:
severity: critical
annotations:
summary: "服务异常,实例:{{ $labels.instance }}"
description: "{{ $labels.job }} 服务已关闭"
EOF
# node_exporter服务
cat >> /opt/prometheus/prometheus/prometheus.yml <<"EOF" # 再scrape_configs这行下面添加如下配置:
#node-exporter配置
- job_name: 'node-exporter'
scrape_interval: 15s
static_configs:
- targets: ['localhost:9100']
labels:
instance: Prometheus服务器
EOF

2.3 启动服务

# 启动服务
systemctl daemon-reload
systemctl start prometheus.service
systemctl enable prometheus.service

访问测试地址:
http://192.168.10.14:9090/
监控指标:http://192.168.10.14:9090/metrics

systemctl start alertmanager.service
systemctl enable alertmanager.service
访问测试地址:http://192.168.10.14:9093/

systemctl start grafana-server.service
systemctl enable grafana-server.service
web访问地址:http://192.168.10.14:3000/

systemctl start node_exporter.service
systemctl enable node_exporter.service
web访问地址:http://192.168.10.14:9100/metrics # 查看命令
systemctl status 服务名

# prometheus配置文件如果有修改,请用重载或重启服务命令
重载:curl -X POST http://localhost:9090/-/reload

三、使用grafana展示prometheus

3.1 登录grafana

http://192.168.10.14:3000/login

默认用户名密码:admin/admin

第一次登陆,需要修改密码,填入新的密码后,再submit

3.2 创建prometheus数据源

在 Grafana 中创建 Prometheus 数据源:

  1. 单击边栏中的“齿轮”,打开“配置”菜单。
  1. 单击“数据源”。
  1. 单击“添加数据源”。
  1. 选择“Prometheus”作为类型。
  1. 设置适当的 Prometheus 服务器 URL(例如,http://localhost:9090
  1. 单击“保存并测试”以保存新的数据源。

url填入:http://localhost:9090 注:localhost表示本机,然后保存save&test

3.3 创建仪表盘:从grafana导入仪表盘

https://grafana.com/grafana/dashboards/

打开grafana的dashboards官网,在搜索栏输入node exporter回车,点击下载量大的dashboards如下图:

拷贝id

打开grafana web控制台--点击dashbord图标--在点import导入--粘贴之前复制的id--在点load加载

name填写“服务器监控”(根据实际修改),选择“prometheus”--在点import导入

导入dashboard完成后,查看:

1.prometheus源码安装的更多相关文章

  1. mono-3.4.0 源码安装时出现的问题 [do-install] Error 2 [install-pcl-targets] Error 1 解决方法

    Mono 3.4修复了很多bug,继续加强稳定性和性能(其实Mono 3.2.8 已经很稳定,性能也很好了),但是从http://download.mono-project.com/sources/m ...

  2. 搭建LNAMP环境(七)- PHP7源码安装Memcached和Memcache拓展

    上一篇:搭建LNAMP环境(六)- PHP7源码安装MongoDB和MongoDB拓展 一.安装Memcached 1.yum安装libevent事件触发管理器 yum -y install libe ...

  3. 搭建LNAMP环境(二)- 源码安装Nginx1.10

    上一篇:搭建LNAMP环境(一)- 源码安装MySQL5.6 1.yum安装编译nginx需要的包 yum -y install pcre pcre-devel zlib zlib-devel ope ...

  4. 搭建LNAMP环境(一)- 源码安装MySQL5.6

    1.yum安装编译mysql需要的包 yum -y install gcc-c++ make cmake bison-devel ncurses-devel perl 2.为mysql创建一个新的用户 ...

  5. Greenplum 源码安装教程 —— 以 CentOS 平台为例

    Greenplum 源码安装教程 作者:Arthur_Qin 禾众 Greenplum 主体以及orca ( 新一代优化器 ) 的代码以可以从 Github 上下载.如果不打算查看代码,想下载编译好的 ...

  6. salt源码安装软件和yum安装软件

    上面简单列出了源码安装的sls文件书写思路. 涉及到一些固定的思路:如, 1,拷贝 解压安装时候需要依赖tar.gz存在 如果已安装则无需再次安装. 2,启动脚本 加入chk时候需要文件存在,如果已添 ...

  7. 搭建LNAMP环境(六)- PHP7源码安装MongoDB和MongoDB拓展

    上一篇:搭建LNAMP环境(五)- PHP7源码安装Redis和Redis拓展 一.安装MongoDB 1.创建mongodb用户组和用户 groupadd mongodb useradd -r -g ...

  8. 搭建LNAMP环境(三)- 源码安装Apache2.4

    上一篇:搭建LNAMP环境(二)- 源码安装Nginx1.10 1.yum安装编译apache需要的包(如果已经安装,可跳过此步骤) yum -y install pcre pcre-devel zl ...

  9. Linux MySQL源码安装缺少ncurses-devel包

    在Red Hat Enterprise Linux Server release 5.7 上用源码安装MySQL-5.6.23时,遇到了" remove CMakeCache.txt and ...

  10. centos 6x系统下源码安装mysql操作记录

    在运维工作中经常部署各种运维环境,涉及mysql数据库的安装也是时常需要的.mysql数据库安装可以选择yum在线安装,但是这种安装的mysql一般是系统自带的,版本方面可能跟需求不太匹配.可以通过源 ...

随机推荐

  1. .NET开源、免费、强大的交互式绘图库

    前言 今天大姚给大家分享一款.NET开源(采用MIT许可证).免费.强大的交互式绘图库,该库能够轻松地实现大型数据集的交互式显示.使用几行代码即可快速创建折线图.柱状图.饼图.散点图等不同类型的图表: ...

  2. MySQL 汉字字段 拼音排序

    原数据 排序后 SELECT c1 FROM test ORDER BY CONVERT ( c1 USING gbk )

  3. 一个可以让你有更多时间摸鱼的WPF控件(一)

    前言 我们平时在开发软件的过程中,有这样一类比较常见的功能,它没什么技术含量,开发起来也没有什么成就感,但是你又不得不花大量的时间来处理它,它就是对数据的增删改查.当我们每增加一个需求就需要对应若干个 ...

  4. 【Java】请写出你最常见到的 5 个 runtime exception

    请写出你最常见到的 5 个 runtime exception. ​ 参考:https://blog.csdn.net/qq_20417499/article/details/80222820 Cla ...

  5. Python爬虫爬取爱奇艺、腾讯视频电影相关信息(改进版)---团队第一阶段冲刺

    爱奇艺 1 import time 2 import traceback 3 import requests 4 from lxml import etree 5 import re 6 from b ...

  6. C++ 简单实现shared_ptr

    共享指针 管理指针的存储,提供有限的垃圾回收工具,并可能与其他对象共享该管理. shared_ptr类型的对象都能够获得指针的所有权并共享该所有权:一旦它们获得所有权,当最后一个所有者释放该所有权时, ...

  7. 网页实现串口TCP数据通讯的两种方案

    概述 串口和TCP数据通讯客户端的形式比较多,但是网页中用的比较少. 其实最大的是网页无法访问本地资源造成的,可能是出于安全方面考虑吧. 解决方案也不是没有,这里介绍几种供大家参考. ​ 方案一:专用 ...

  8. #Kruskal,可撤销并查集#CF891C Envy

    题目 给出一个 \(n\) 个点 \(m\) 条边的无向图,每条边有边权,共 \(Q\) 次询问, 每次给出 \(k_i\) 条边,问这些边能否同时在一棵最小生成树上. 分析 考虑最小生成树选择的边权 ...

  9. 面向OpenHarmony终端的密码安全关键技术

      本文转载自 OpenHarmony TSC 官方微信公众号<峰会回顾第17期 | 面向OpenHarmony终端的密码安全关键技术> 演讲嘉宾 | 何道敬 回顾整理 | 廖   涛 排 ...

  10. 重磅官宣,OpenHarmony技术峰会来了

      技术构筑万物智联 创新使能行业发展 2月25日 第一届开放原子开源基金会OpenHarmony技术峰会即将启幕 众多行业大咖齐聚深圳 开启一场"技术硬核"探索盛宴 亮点拉满,我 ...