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发布,主要是存储引擎进行了优 ...
随机推荐
- 联想笔记本上Ubuntu无线网卡问题
可能有两个问题: 1.无无线网卡驱动 2.无线网卡驱动不能自动加载 问题1:无线网卡驱动 百度出网卡驱动iwlwifi-9000,如iwlwifi-9000-pu-b0-jf-b0-34.618819 ...
- ORA-01589错误的解决办法
出现下图错误 使用下面解决办法,首先输入下面第一个箭头的语句,然后会弹出一个等待光标,接下来就是找到最新的那个REMOD0X.LOG文件地址,也就是第二个箭头所示. 再输入下面图片第一个箭头的语句.
- sparksql基础知识二
目标 掌握sparksql操作jdbc数据源 掌握sparksql保存数据操作 掌握sparksql整合hive 要点 1. jdbc数据源 spark sql可以通过 JDBC 从关系型数据库中读取 ...
- [算法模板]SOS DP
[算法模板]SOS DP 正文 SOS-DP(\(\text{Sum over Subsets}\))是用来解决这样的问题的: 其实就是子集和DP.上面每个\(F[mask]\)里面包含了\(mask ...
- Visual Studio报错/plugin.vs.js,行:1074,错误:缺少标识符、字符串或数字
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\PrivateAssemblies/plugin. ...
- 【VS开发】【C/C++开发】关于boost库的C++11导致的undefined符号问题
undefined reference to boost::program_options::options_description::m_default_line_length 问题最终解决依靠的是 ...
- xshell 快速复制粘贴的方法
xshell快速复制粘贴的方法<img src="http://newmiracle.cn/wp-content/uploads/2017/01/QQ截图20170113163139- ...
- 在flask中使用sqlalchemy插入数据返回新增的id
user = User(‘name’=‘张三’)db.session.add(user)db.session.flush()#输出新插入数据的主键print(user.id)#此时数据才插入到数据库中 ...
- Scala Collection Method
接收一元函数 map 转换元素,主要应用于不可变集合 (1 to 10).map(i => i * i) (1 to 10).flatMap(i => (1 to i).map(j =&g ...
- TCMalloc - 细节
1,释放速度控制 在将一个Span删除掉的时候,会优先将它加入到normal队列中,这之后会尝试从normal队列中释放一部分同样大小的内存给系统. 释放内存给系统的时候,tcmalloc使用了一个延 ...