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

 

到這里,安裝就結束了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM