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

二、安装

tar zxvf prometheus-2.14.0.linux-amd64.tar.gz -C /data
mv /data/prometheus-2.14.0.linux-amd64 /data/prometheus

启动脚本

vi /etc/init.d/prometheus-server

内容如下:

#!/bin/bash
# auditd        Startup script
# chkconfig: 2345 14 87
# description: This is Startup script
# 服务器名
export SERVICE=prometheus
# 服务端口
export PORT=9090
# 基础目录
export BASE_DIR=/data/prometheus
. /etc/init.d/functions 
# 服务相关命令
start(){
    echo "${SERVICE} starting....."
    cd $BASE_DIR;nohup ${BASE_DIR}/prometheus --config.file=${BASE_DIR}/prometheus.yml --storage.tsdb.path=${BASE_DIR}/data &
    if [ $? -eq 0 ];then
        action "$SERVICE is starting" /bin/true
    else
        action "$SERVICE is starting" /bin/false
    fi
}
stop(){
    killall -9 $SERVICE
    if [ $? -eq 0 ];then
        action "$SERVICE is stoping" /bin/true
    else
        action "$SERVICE is stoping" /bin/false
    fi 
}
status(){
    if [ `ss -tunlp|grep ${PORT}|awk '{print $5}'|cut -d: -f2` = ${PORT} ];then
            echo "${SERVICE} is running....."
    else
            echo "${SERVICE} is stopping....."
    fi
}
case $1 in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    stop
    start
    ;;
status)
    status
    ;;
*)
   echo "$0 <start|stop|restart>"
esac

设置开机自启动

chmod +x /etc/init.d/prometheus-server
chkconfig --add prometheus-server
chkconfig --level 2345 prometheus-server on
/etc/init.d/prometheus-server start

三、访问页面

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

到这里,安装就结束了。

猜你喜欢

转载自www.cnblogs.com/xiao987334176/p/11927979.html