debian 10 安装prometheus 2.37.6 配置rc.local自启动
- 1、下载安装包
 - 2、安装
 - 3、访问普罗米修斯
 - 4、加入开机自启动
 - 4.1、配置rc-local.service
 - 4.2、添加自定义启动命令
 - 4.3、查看rc-local.service
 
1、下载安装包
https://prometheus.io/download/
 wget -c https://github.com/prometheus/prometheus/releases/download/v2.37.6/prometheus-2.37.6.linux-amd64.tar.gz
2、安装
解压安装包至 /usr/local/目录
tar -zxvf prometheus-2.37.6.linux-amd64.tar.gz -C /usr/local/
 
修改安装目录名称为prometeus
cd /usr/local/
mv prometheus-2.37.6.linux-amd64/ prometheus
 
启动prometeus服务
cd prometheus
 
nohup ./prometheus --storage.tsdb.path="data/" --storage.tsdb.retention=30d --config.file=prometheus.yml > ./prometheus.log 2>&1 &
 
参数释义
--storage.tsdb.path="data/"  
                                 Base path for metrics storage. Use with server mode only.
--storage.tsdb.retention=STORAGE.TSDB.RETENTION  
                                 [DEPRECATED] How long to retain samples in storage. This flag has been deprecated, use "storage.tsdb.retention.time" instead. Use with server
                                 mode only.
--config.file="prometheus.yml"  
                                 Prometheus configuration file path.
 

 自动生成data目录和prometheus.log文件
 
 
3、访问普罗米修斯

4、加入开机自启动
4.1、配置rc-local.service
debian 10 中在 /etc/rc.local 添加自定义的命令即可实现开机自动执行命令:开机自启动。
debian 10 默认安装了rc-local 服务,但是没有启动,所以默认也没有 /etc/rc.local 文件。
默认 rc-local 服务没有启动
 systemctl status rc-local 显示Active: inactive (dead)就是没有启动。
 
 默认的rc-local.service文件
 
 启动rc-local 服务
 启动失败 因为condition验证失败,就是说系统上没有/etc/rc.local文件。
 
那么先建立 /etc/rc.local 文件,并赋予可执行权限
touch /etc/rc.local
chmod +x /etc/rc.local 
 

再次启动rc-local服务 报错
systemctl start rc-local.service
 

 /etc/rc.local格式错误
编辑/etc/rc.local文件,加入一行:#!/bin/bash
vi /etc/rc.local
 
再次启动rc-local服务
systemctl start rc-local.service
 

4.2、添加自定义启动命令
编辑/etc/rc.local文件
vi /etc/rc.local
 
加入一行:
nohup /usr/local/prometheus/prometheus --storage.tsdb.path="/usr/local/prometheus/data/" --storage.tsdb.retention=30d --config.file=/usr/local/prometheus/prometheus.yml > /usr/local/prometheus/prometheus.log 2>&1 &
 
重启服务器看普罗米修斯是否在运行

 
4.3、查看rc-local.service
systemctl status rc-local.service
 
可以看到CGroup里显示出所有通过/etc/rc.local配置的自启动服务
 



















