Prometheus的安装配置启动

1、Prometheus二进制安装

Prometheus下载链接:https://prometheus.io/download/

Prometheus本身的存储是通过时间序列化存储的,所以对时间是很有要求的,系统时间需要通过ntp进行同步,避免因为时间造成数据无法显示。

# 时间同步
[root@prometheus ~]# ntpdate ntp1.aliyun.com
[root@prometheus ~]# crontab -e
*/5 * * * * ntpdate ntp1.aliyun.com &> /dev/null # 下载
[root@prometheus ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.14.0/prometheus-2.14.0.linux-amd64.tar.gz # 解压
[root@prometheus ~]# tar -zxf prometheus-2.14.0.linux-amd64.tar.gz -C /usr/local
[root@prometheus ~]# mv /usr/local/prometheus-2.14.0.linux-amd64 /usr/local/prometheus-2.14.0
[root@prometheus ~]# ln -sv /usr/local/prometheus-2.14.0 /usr/local/prometheus # 配置自我监控
[root@prometheus ~]# cd /usr/local/prometheus
[root@prometheus ~]# vim prometheus.yaml
global:
scrape_interval: 15s # 全局配置,默认15s收集一次数据. # 配置外部标签
external_labels:
monitor: 'codelab-monitor' # 监控配置
scrape_configs:
# 监控任务名称,KV形式.
- job_name: 'prometheus' # 覆盖前面的全局配置,以5s收集一次数据.
scrape_interval: 5s # 目标监控主机和收集数据的端口
static_configs:
- targets: ['localhost:9090'] # 启动
[root@prometheus prometheus]# ./prometheus &
[root@prometheus prometheus]# netstat -tulnp |grep 9090
[root@prometheus prometheus]# netstat -tulnp |grep 9090
tcp6 0 0 :::9090 :::* LISTEN 21407/./prometheus

上面可以看到监听了9090端口,即可通过localhost:9090/metrics来获取指标数据,也可以通过浏览器直接访问localhost:9090通过web界面来查看数据。

Prometheus的安装还是比较简单的,但是由于Prometheus没有使用systemd来进行管理,用./的方式启动并不方便,这里虽然使用&、nohup的挂起方式也不尽完美,那么这里再来2种守护进程方式运行prometheus。如下:

  • (1)安装screen工具,将prometheus放入后台运行
[root@prometheus prometheus]# yum install screen -y
[root@prometheus prometheus]# screen
[root@prometheus prometheus]# ./prometheus
#按Ctrl+a+d后进入后台运行模式
[root@prometheus prometheus]# screen -ls
There is a screen on:
28915.pts-0.prometheus (Detached)
1 Socket in /var/run/screen/S-root. [root@prometheus prometheus]# ps -ef |grep prometheus
root 28927 28916 6 15:07 pts/2 00:00:01 ./prometheus
  • (2)使用systemd进行管理
[root@prometheus ~]# vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus
Documentation=https://prometheus.io/docs/introduction/overview
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target [Service]
Type=simple
PIDFile==/var/run/prometheus.pid
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.read-timeout=5m --web.max-connections=512 --storage.tsdb.retention=15d --storage.tsdb.path="data/" --query.max-concurrency=20 --query.timeout=2m
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID [Install]
WantedBy=multi-user.target [root@prometheus ~]# systemctl daemon-reload
[root@prometheus ~]# systemctl start prometheus
[root@prometheus ~]# ps -ef |grep prometheus
root 29688 1 1 16:31 ? 00:00:00 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.read-timeout=5m --web.max-connections=512 --storage.tsdb.retention=15d --storage.tsdb.path="data/" --query.max-concurrency=20 --query.timeout=2m
[root@prometheus ~]# netstat -tulnp |grep 9090
tcp6 0 0 :::9090 :::* LISTEN 29707/prometheus

这里需要了解的几个启动优化的参数:

  • --config.file:指定prometheus的配置文件路径

  • --web.read-timeout:请求链接的最大等待时间,为了防止过多查询链接请求或太多的空闲链接占用资源

  • --web.max-connections:最大连接数设置

  • --storage.tsdb.retention:prometheus采集数据后会保存在内存和硬盘当中,设定保留数据的时长,避免高消耗

  • --storage.tsdb.path:指定采集监控数据保存的磁盘路径

  • --query.max-concurrency --query.timeout:这两个参数是用于在用户执行查询时,防止太多用户同时查询,也防止用户执行过大的查询而不退出,导致资源过载。

2、Prometheus容器化安装

直接使用官方的镜像启动,并映射prometheus.yml配置文件到本地进行管理

[root@prometheus ~]# docker run -p 9090:9090 -v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

还有另外一种方式是通过自定义镜像方式启动Prometheus

[root@prometheus ~]# vim dockerfile
FROM prom/prometheus
ADD prometheus.yml /etc/prometheus/ [root@prometheus ~]# docker build -t my-prometheus .
[root@prometheus ~]# docker run -p 9090:9090 my-prometheus

Prometheus学习笔记(2)Prometheus部署的更多相关文章

  1. ActionBarSherlock学习笔记 第一篇——部署

    ActionBarSherlock学习笔记 第一篇--部署          ActionBarSherlock是JakeWharton编写的一个开源框架,使用这个框架,可以实现在所有的Android ...

  2. OGG学习笔记04-OGG复制部署快速参考

    OGG学习笔记04-OGG复制部署快速参考 源端:Oracle 10.2.0.5 RAC + ASM 节点1 Public IP地址:192.168.1.27 目标端:Oracle 10.2.0.5 ...

  3. Prometheus监控学习笔记之Prometheus的Relabel,SD以及Federation功能

    0x00 k8s 的监控设计 k8s 默认以及推荐的监控体系是它自己的一套东西:Heapster + cAdvisor + Influxdb + Grafana,具体可以看 这里 . 包括 k8s 自 ...

  4. Prometheus监控学习笔记之prometheus的federation机制

    0x00 概述 有时候对于一个公司,k8s集群或是所谓的caas只是整个技术体系的一部分,往往这个时候监控系统不仅仅要k8s集群以及k8s中部署的应用,而且要监控传统部署的项目.也就是说整个监控系统不 ...

  5. Prometheus监控学习笔记之Prometheus存储

    0x00 概述 Prometheus之于kubernetes(监控领域),如kubernetes之于容器编排.随着heapster不再开发和维护以及influxdb 集群方案不再开源,heapster ...

  6. Prometheus监控学习笔记之Prometheus普罗米修斯监控入门

    0x00 概述 视频讲解通过链接网易云课堂·IT技术快速入门学院进入,更多关于Prometheus的文章. Prometheus是最近几年开始流行的一个新兴监控告警工具,特别是kubernetes的流 ...

  7. Prometheus监控学习笔记之Prometheus监控简介

    0x00 Prometheus容器监控解决方案 Prometheus(普罗米修斯)是一个开源系统监控和警报工具,最初是在SoundCloud建立的.它是一个独立的开放源码项目,并且独立于任何公司.不同 ...

  8. Prometheus学习笔记(6)Alertmanager告警

    目录 一.Alertmanager简介 二.Alertmanager部署 三.Alertmanager配置 四.自定义告警规则和发送 五.自定义告警模板 一.Alertmanager简介 Promet ...

  9. Prometheus监控学习笔记之Prometheus从1.x升级到2.x

    详细参考这篇文章 https://cloud.tencent.com/developer/article/1171434 prometheus 2.0于2017-11-08发布,主要是存储引擎进行了优 ...

随机推荐

  1. Python实现电子词典(图形界面)

    Python实现电子词典(图形界面) 终端电子词典:https://www.cnblogs.com/noonjuan/p/11341375.html 文件一览: .├── client.py├── d ...

  2. 小端存储转大端存储 & 大端存储转小端存储

    1.socket编程常用的相关函数:htons.htonl.ntohs.ntohl h:host   n:network      s:string    l:long 2.基本数据类型,2字节,4字 ...

  3. C++ 重写虚函数的代码使用注意点+全部知识点+全部例子实现

    h-------------------------- #ifndef VIRTUALFUNCTION_H #define VIRTUALFUNCTION_H /* * 派生类中覆盖虚函数的使用知识点 ...

  4. 数据结构与算法系列——排序(4)_Shell希尔排序

    1. 工作原理(定义) 希尔排序,也称递减增量排序算法,是插入排序的一种更高效的改进版本.但希尔排序是非稳定排序算法. 希尔排序的基本思想是:先将整个待排序的记录序列分割成为若干子序列分别进行直接插入 ...

  5. CDN惹的祸:记一次使用OSS设置跨域资源共享(CORS)不生效的问题

    原文: https://www.lastupdate.net/4669.html 昨天H5组的开发反馈了一个问题,说浏览器收不到跨域的配置,提示:Failed to load https://nnmj ...

  6. [技术博客]微信小程序审核的注意事项及企业版小程序的申请流程

    关于小程序审核及企业版小程序申请的一些问题 微信小程序是一个非常方便的平台.由于微信小程序可以通过微信直接进入,不需要下载,且可使用微信账号直接登录,因此具有巨大的流量优势.但是,也正是因为微信流量巨 ...

  7. React组件介绍与使用(父传子、子传父、兄弟传)

    1.创建组件的方法     1.1.函数式无状态组件 1.1.1.语法 1 function myComponent(props) { 2 return 3 <div>Hello {pro ...

  8. cmder是一个增强型命令行工具,不仅可以使用windows下的所有命令,更爽的是可以使用linux的命令,shell命令。

    cmder使用简介 Cmder is a software package created out of pure frustration over the absence of nice conso ...

  9. Atlassian JIRA 插件开发之一 环境搭建

    参考 https://developer.atlassian.com/server/framework/atlassian-sdk/  download the SDK 说明 Download the ...

  10. web-debug-server

    web-debug-server 项目来自:https://github.com/itzg/web-debug-server 这位大哥的镜像做的很有意思:一个很小的web debug服务器,访问它可以 ...