Prometheus設置systemctl管理


  Prometheus可以設置成后台啟動 參考:https://www.cnblogs.com/minseo/p/13370596.html

  但是其他應用程序大多使用systemctl管理啟動,為統一設置Prometheus為systemctl啟動

  環境查看

 

 

  下載prometheus

  下載地址:https://github.com/prometheus/prometheus/releases

 

 

  解壓

#解壓
tar -xf prometheus-2.20.0.linux-amd64.tar.gz 
#設置軟連接
ln -s /usr/local/prometheus-2.20.0.linux-amd64 /usr/local/prometheus
#拷貝配置文件至/etc
cd promrtheus
cp prometheus.yml /etc/

   prometheus默認配置文件

# cat /etc/prometheus.yml 
# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']

   設置systemctl管理

# cat /usr/lib/systemd/system/prometheus.service 
[Unit]
Description=Prometheus Node Exporter
After=network.target

[Service]
ExecStart=/usr/local/prometheus/prometheus --config.file=/etc/prometheus.yml --web.read-timeout=5m  --web.max-connections=10 --storage.tsdb.retention=15d --storage.tsdb.path=/prometheus/data --query.max-concurrency=20 --query.timeout=2m
User=root
[Install]
WantedBy=multi-user.target

   啟動參數解釋

–config.file=/etc/prometheus.yml 指定配置文件
 
–web.read-timeout=5m 請求鏈接的最大等待時間,防止太多的空閑鏈接占用資源
 
–web.max-connections=512 針對prometheus,獲取數據源的時候,建立的網絡鏈接數,做一個最大數字的限制,防止鏈接數過多造成資源過大的消耗
 
–storage.tsdb.retention=15d 重要參數,prometheus 開始采集監控數據后,會存在內存和硬盤中;對於保存期限的設置。時間過長,硬盤和內存都吃不消;時間太短,要查歷史數據就沒了。企業15天最為合適。
 
–storage.tsdb.path="/prometheus/data" 存儲數據路徑,不要隨便定義
 
–query.max-concurrency=20 用戶查詢最大並發數
 
–query.timeout=2m 慢查詢強制終止

   注意:配置文件不能加雙引號,否則啟動報錯找不到文件或目錄

       本次啟動用戶是root生產中最好新建一個用戶用於啟動,需要設置配置文件及數據文件權限

      數據目錄在生產中最好單獨配置數據硬盤,使用LVM硬盤格式配置

  啟動

#啟動
systemctl start prometheus
#設置開機自啟動
systemctl enable prometheus

   查看是否啟動

lsof -i:9090
ps -ef|grep prometheus

 

 

   web頁面查看

 

   設置systemctl管理完成


免責聲明!

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



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