Prometheus设置systemctl管理

  Prometheus可以设置成后台启动 参考:https://www.cnblogs.com/minseo/p/13370596.html

  但是其他应用程序大多使用systemctl管理启动,为统一设置Prometheus为systemctl启动

  环境查看

 

 

  下载prometheus

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

 

 

  解压

1
2
3
4
5
6
7
#解压
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默认配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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管理

1
2
3
4
5
6
7
8
9
10
# 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

   启动参数解释

1
2
3
4
5
6
7
8
9
10
11
12
13
–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硬盘格式配置

  启动

1
2
3
4
#启动
systemctl start prometheus
#设置开机自启动
systemctl enable prometheus

   查看是否启动

1
2
lsof -i:9090
ps -ef|grep prometheus

 

 

   web页面查看

 

   设置systemctl管理完成

posted @   minseo  阅读(4186)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
历史上的今天:
2017-07-29 Linux监控远程端口是否开启脚本
点击右上角即可分享
微信分享提示