CentOS7部署Prometheus

  • Prometheus
    Prometheus(普罗米修斯)首先联想到的是异形,一部很不错的电影。在这里指的是一套开源的监控、
    报警、时序数据库的组合。是由SoundCloud公司开发。
    Prometheus基本原理是通过HTTP协议周期性抓取(Pull方式)被监控组件的状态,好处是任意组件只要提供HTTP接口就可以接入监控系统,不需要任何SDK或者其他的集成过程。这样做非常适合虚拟化环境,比如VM或者Docker。输出被监控组件信息的Http接口叫exporter。
    常用的组件大部分都有exporter可以直接使用,比如Nginx、MySQL、Linux OS系统信息等。
    Prometheus架构:
    CentOS7部署Prometheus
  • 安装Prometheus
    Prometheus基于Go编写,编译后的软件包,不依赖于任何的第三方依赖。只需下载对应平台的二进制包,解压到对应目录启动Prometheus Server即可。
    1. 下载二进制包
      通过prometheus官网,我们下载最新版本的prometheus,目前官网最新版本prometheus-2.18.1。
      wget https://github.com/prometheus/prometheus/releases/download/v2.18.1/prometheus-2.18.1.linux-amd64
      tar xzvf prometheus-2.18.1.linux-amd64.tar.gz
      mv prometheus-2.18.1.linux-amd64 /usr/local/
      ln -s /usr/local/prometheus-2.18.1.linux-amd64/ /usr/local/prometheus
    2. 配置
      默认的Prometheus配置文件为promethes.yml
      CentOS7部署Prometheus
      scrape_interval:     15s   # 设置抓取间隔,默认为1分钟
      evaluation_interval: 15s   #估算规则的默认周期,每15秒计算一次规则。默认1分钟
    3. 创建Prometheus用户及数据存储目录
      为安全起见,使用普通用户来启动prometheus服务。作为一个时序型的数据库产品,prometheus的数据默认会存放在应用所在目录下,这里需要修改为 /data/prometheus下。
      #创建用户
      useradd  -s /sbin/nologin -M prometheus 
      mkdir  /data/prometheus -p
      #修改目录属主
      chown -R prometheus:prometheus /usr/local/prometheus/
      chown -R prometheus:prometheus /data/prometheus/
    4. 使用Systemd服务启动prometheus
      创建prometheus.service文件
      vim /etc/systemd/system/prometheus.service
      [Unit]
      Description=Prometheus
      Documentation=https://prometheus.io/
      After=network.target
      [Service]
      Type=simple
      User=prometheus
      ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus
      Restart=on-failure
      [Install]
      WantedBy=multi-user.target

      在service文件里面,定义了启动的命令,定义了数据存储在/data/prometheus路径下,否则默认会在prometheus二进制的data目录下。
      启动prometheus服务

      systemctl start prometheus
      systemctl enable prometheus
    5. 打开prometheus浏览首页
      prometheus启动后默认会监听9090端口,如果本地有防火墙,如iptables,需将9090端口放开。
      打开本地localhost:9090。
      CentOS7部署Prometheus
  • 發表評論
    所有評論
    還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
    相關文章