Prometheus学习笔记(2)Prometheus部署
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部署的更多相关文章
- ActionBarSherlock学习笔记 第一篇——部署
ActionBarSherlock学习笔记 第一篇--部署 ActionBarSherlock是JakeWharton编写的一个开源框架,使用这个框架,可以实现在所有的Android ...
- 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 ...
- Prometheus监控学习笔记之Prometheus的Relabel,SD以及Federation功能
0x00 k8s 的监控设计 k8s 默认以及推荐的监控体系是它自己的一套东西:Heapster + cAdvisor + Influxdb + Grafana,具体可以看 这里 . 包括 k8s 自 ...
- Prometheus监控学习笔记之prometheus的federation机制
0x00 概述 有时候对于一个公司,k8s集群或是所谓的caas只是整个技术体系的一部分,往往这个时候监控系统不仅仅要k8s集群以及k8s中部署的应用,而且要监控传统部署的项目.也就是说整个监控系统不 ...
- Prometheus监控学习笔记之Prometheus存储
0x00 概述 Prometheus之于kubernetes(监控领域),如kubernetes之于容器编排.随着heapster不再开发和维护以及influxdb 集群方案不再开源,heapster ...
- Prometheus监控学习笔记之Prometheus普罗米修斯监控入门
0x00 概述 视频讲解通过链接网易云课堂·IT技术快速入门学院进入,更多关于Prometheus的文章. Prometheus是最近几年开始流行的一个新兴监控告警工具,特别是kubernetes的流 ...
- Prometheus监控学习笔记之Prometheus监控简介
0x00 Prometheus容器监控解决方案 Prometheus(普罗米修斯)是一个开源系统监控和警报工具,最初是在SoundCloud建立的.它是一个独立的开放源码项目,并且独立于任何公司.不同 ...
- Prometheus学习笔记(6)Alertmanager告警
目录 一.Alertmanager简介 二.Alertmanager部署 三.Alertmanager配置 四.自定义告警规则和发送 五.自定义告警模板 一.Alertmanager简介 Promet ...
- Prometheus监控学习笔记之Prometheus从1.x升级到2.x
详细参考这篇文章 https://cloud.tencent.com/developer/article/1171434 prometheus 2.0于2017-11-08发布,主要是存储引擎进行了优 ...
随机推荐
- [RN] 阿里 ant-design 菜单比较丰富 https://github.com/ant-design/ant-design-mobile
阿里 ant-design 菜单比较丰富 https://github.com/ant-design/ant-design-mobile 天和风雨顺 地和五谷丰 人和事业旺 家和万事兴
- ajax有哪些方法可以实现跨域?他们都有哪些局限性?
1.服务器端代理:在服务器端设置一个代理,由服务器端向跨域下的网站发出请求,再将请求结果返回给前端. 属于后端的技术,实现起来最麻烦. 2.jsonP,只支持get方式调用. 3.XHR2(cors) ...
- 前端,DJ
Vue模块 1.Vue都有哪些指令,简单说说? """ Vue里面常见指令有文本指令:v-text.v-html,属性指令:v-bind,方法指令:v-on,条件指令:v ...
- Unix/Linux系统下的nobody用户是什么?
1.Windows系统在安装后会自动建立一些用户帐户,在Linux系统中同样有一些用户帐户是在系统安装后就有的,就像Windows系统中的内置帐户一样. 2.它们是用来完成特定任务的,比如nobody ...
- 每日一问:简述 View 的绘制流程
Android 开发中经常需要用一些自定义 View 去满足产品和设计的脑洞,所以 View 的绘制流程至关重要.网上目前有非常多这方面的资料,但最好的方式还是直接跟着源码进行解读,每日一问系列一直追 ...
- USDT
如果刚刚接触比特币,你可能会看到USDT并把它误认为美元. 实际上就是这样,这正是USDT开发团队的意思. Tether(USDT)是基于在Bitcoin Blockchain上发布的Omni Lay ...
- 非mvn项目转为mvn项目并构建mvn私服
非mvn项目转为mvn项目并构建mvn私服 一.背景 公司里的系统是老系统,没有使用mvn,但是现在准备使用持续集成(CI),就要用到mvn,所以现在需要将老项目转为mvn项目,并且非mvn项目也是不 ...
- .NET配置引用程序集的路径(分离exe和dll)
按照引用程序集路径的不同,程序集DLL分为两类: 1)全局DLL(在GAC中注册,GAC——全局程序集缓存),有关GAC的详细资料可以参考一下链接: http://dddspace.com/2011/ ...
- 规范化使用MySQL
如何更规范化使用MySQL 如何更规范化使用MySQL 背景:一个平台或系统随着时间的推移和用户量的增多,数据库操作往往会变慢:而在Java应用开发中数据库更是尤为重要,绝大多数情况下数据库的性能决定 ...
- C#调用摄像头(AForge)实现扫描条码解析(Zxing)功能
网上找了很多代码,都比较零散,以下代码纯自己手写,经过测试.下面有链接,下载后可以直接使用. 介绍: 自动识别:点击Start按钮会调用PC摄像头,代码内置Timer,会每100毫秒识别一下当前摄像头 ...