7

CentOS 7安装Prometheus监控系统完整版

 3 years ago
source link: http://dockone.io/article/2434457
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

普罗米修斯概述

Prometheus(由Go语言开发)是一套开源的监控&报警&时间序列数据库的组合。适合监控Docker容器。因为Kubernetes(俗称K8s)的流行带动了Prometheus的发展。

时间序列数据

什么是序列数据

时间序列数据(TimeSeries Data): 按照时间顺序记录系统、设备状态变化 的数据被称为时序数据。

应用的场景很多,如:
  • 无人驾驶车辆运行中要记录的经度,纬度,速度,方向,旁边物体的距离等等。每时每刻都要将数据记录下来做分析。
  • 某一个地区的各车辆的行驶轨迹数据
  • 传统证券行业实时交易数据
  • 实时运维监控数据等

时间序列数据特点

  • 性能好,关系型数据库对于大规模数据的处理性能糟糕。NoSQL可以比较好的处理大规模数据,但依然比不上时间序列数据库。
  • 存储成本低,高效的压缩算法,节省存储空间,有效降低IO
Prometheus有着非常高效的时间序列数据存储方法,每个采样数据仅仅占 用3.5byte左右空间,上百万条时间序列,30秒间隔,保留60天,大概花了 200多G(来自官方数据)。

Prometheus的主要特征

  • 多维度数据模型。
  • 灵活的查询语言。
  • 不依赖分布式存储,单个服务器节点是自主的。
  • 通过基于HTTP的pull方式采集时序数据。
  • 可以通过中间网关进行时序列数据推送。
  • 通过服务发现或者静态配置来发现目标服务对象。
  • 支持多种多样的图表和界面展示,比如Grafana等。

普罗米修斯原理架构图

实验环境准备

教程使用的软件:

下载链接:https://pan.baidu.com/s/1Y-BN3ZWaUCnlVO4woZYhOg,提取码:h6wn

1、静态IP(要求能上外网)

2、主机名
各自配置好主机名 
# hostnamectl set-hostname --static server.cluster.com 
三台都互相绑定IP与主机名 
# vim /etc/hosts            
192.168.116.129  master
192.168.116.130  node1
192.168.116.131  node2
echo "192.168.116.129 master
192.168.116.130 node1
192.168.116.131 node2">>/etc/hosts

3、时间同步(时间同步一定要确认一下)
yum install -y  ntpdate && ntpdate time.windows.com

4、关闭防火墙,SELinux
# systemctl stop firewalld 
# systemctl disable firewalld 
# iptables -F

安装prometheus

https://prometheus.io/download/下载相应版本,安装到服务器上。

官网提供的是二进制版,解压就能用,不需要编译。

上传prometheus-2.5.0.linux-amd64.tar.gz。
tar -zxvf prometheus-2.5.0.linux-amd64.tar.gz -C /usr/local/
mv /usr/local/prometheus-2.5.0.linux-amd64/  /usr/local/prometheus


直接使用默认配置文件启动。
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &

确认端口(9090)。
ss -anltp | grep 9090

Prometheus界面

通过浏览器访问http://服务器IP:9090就可以访问到Prometheus的主界面。

默认只监控了本机一台,点Status --》点Targets --》可以看到只监控了本 机。

主机数据展示

通过http://服务器IP:9090/metrics可以查看到监控的数据。

在Web主界面可以通过关键字查询监控项。

监控远程Linux主机

1、在远程Linux主机(被监控端agent1)上安装node_exporter组件。

下载地址:https://prometheus.io/download/

上传node_exporter-0.16.0.linux-amd64.tar.gz。
tar -zxvf node_exporter-0.16.0.linux-amd64.tar.gz -C /usr/local/
mv /usr/local/node_exporter-0.16.0.linux-amd64/ /usr/local/node_exporter

里面就一个启动命令node_exporter,可以直接使用此命令启动。
nohup /usr/local/node_exporter/node_exporter & 


确认端口(9100)。

扩展:nohup命令:如果把启动node_exporter的终端给关闭,那么进程也会随之关闭。nohup命令会帮你解决这个问题。

2、通过浏览器访问http://被监控端IP:9100/metrics就可以查看到 node_exporter在被监控端收集的监控信息。

3、回到Prometheus服务器的配置文件里添加被监控机器的配置段。

在主配置文件最后加上下面三行。
vim /usr/local/prometheus/prometheus.yml 
- job_name: 'node1'
static_configs:
- targets: ['192.168.116.130:9100'] 
- job_name: 'agent1'                   # 取一个job名称来代表被监控的机器   
static_configs:   
- targets: ['10.1.1.14:9100']        # 这里改成被监控机器的IP,后面端口接9100

改完配置文件后,重启服务。
pkill prometheus 

确认端口没有进程占用。
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &

确认端口被占用,说明重启成功。

4、回到Web管理界面 --》点Status --》点Targets --》可以看到多了一台监 控目标。


原文链接:https://blog.csdn.net/heian_99 ... 52955,作者:南宫乘风

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK