zoukankan      html  css  js  c++  java
  • CentOS7安装Prometheus(二进制)

    一、概述

    Prometheus是由SoundCloud开发的开源监控报警系统和时序列数据库(TSDB)。Prometheus使用Go语言开发,是Google BorgMon监控系统的开源版本。

    环境说明

    操作系统:centos 7.6
    ip地址:192.168.31.150

    下载包

    https://prometheus.io/download/
    目前最新版是:2.14.0
    下载链接:
    https://github.com/prometheus/prometheus/releases/download/v2.14.0/prometheus-2.14.0.linux-amd64.tar.gz

    二、安装

    useradd prometheus -s /sbin/nologin
    tar zxvf prometheus-2.14.0.linux-amd64.tar.gz -C /data
    mv /data/prometheus-2.14.0.linux-amd64 /data/prometheus
    chown prometheus:prometheus -R /data/prometheus

    封装service

    vi /etc/systemd/system/prometheus.service

    内容如下:

    [Unit]
    Description=Prometheus
    After=network.target
    [Service]
    ExecStart=/data/prometheus/prometheus --config.file=/data/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus/data
    User=prometheus
    [Install]
    WantedBy=multi-user.target

    注意:主要修改ExecStart和User

    设置开机自启动

    systemctl daemon-reload
    systemctl enable prometheus
    systemctl start prometheus

    查看端口

    # ss -tunlp|grep prometheus
    tcp    LISTEN     0      128      :::9090                 :::*                   users:(("prometheus",pid=969,fd=5))

    如果是centos 6.x系统,需要自己写一个启动脚本。

    vi /etc/init.d/prometheus

    内容如下:

    #!/bin/bash
    # auditd        Start jar package
    # chkconfig: 2345 14 87
    # description: This is admin project
    #define var
    PROJECT_SERVICE="prometheus"
    PORT="9090"
    . /etc/init.d/functions 
    export START="nohup /data/prometheus/prometheus --config.file=/data/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus/data &"
    #服务脚本
    start(){
        echo "${PROJECT_SERVICE} starting....."
        cd /data/${PROJECT_SERVICE} && eval $START
        if [ $? -eq 0 ];then
                action "$PROJECT_SERVICE is starting" /bin/true
        else
                action "$PROJECT_SERVICE is starting" /bin/false
        fi
    }
    stop(){
        kill -9 `lsof -t -i:${PORT}`
        if [ $? -eq 0 ];then
            action "$PROJECT_SERVICE is stoping" /bin/true
        else
            action "$PROJECT_SERVICE is stoping" /bin/false
        fi 
    }
    status(){
        if [ `ss -tunlp|grep ${PROJECT_SERVICE}|awk '{print $5}'|cut -d: -f4` = ${PORT} ];then
                echo "${PROJECT_SERVICE} is running....."
        else
                echo "${PROJECT_SERVICE} is stopping....."
        fi
    }
    case $1 in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    status)
        status
        ;;
    *)
       echo "$0 <start|stop|restart>"
    esac
    View Code

    添加权限,并启动

    chmod 755 /etc/init.d/prometheus
    /etc/init.d/prometheus start

    三、访问页面

    访问targets
    http://192.168.31.150:9090/targets

    到这里,安装就结束了。

  • 相关阅读:
    学习进度03
    构建之法阅读笔记03
    软件工程结队作业01
    用图像算法增强夜视效果
    python将指定目录下的所有文件夹用随机数重命名
    python脚本中调用其他脚本
    opencv+python实现图像锐化
    机器学习中减弱不同图像数据色调及颜色深浅差异
    python利用列表文件遍历
    python文件处理-检查文件名/路径是否正确
  • 原文地址:https://www.cnblogs.com/xiao987334176/p/11927979.html
Copyright © 2011-2022 走看看