Debian 10 installs prometeus 2.37.6 and configures rc.local to start automatically

1. Download the installation package

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. Installation

Unzip the installation package to the /usr/local/ directory

tar -zxvf prometheus-2.37.6.linux-amd64.tar.gz -C /usr/local/

Modify the installation directory name to prometeus

cd /usr/local/
mv prometheus-2.37.6.linux-amd64/ prometheus

Start the prometeus service

cd prometheus
nohup ./prometheus --storage.tsdb.path="data/" --storage.tsdb.retention=30d --config.file=prometheus.yml > ./prometheus.log 2>&1 &

Parameter interpretation

--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.

insert image description here
Automatically generate data directory and prometheus.log file
insert image description here
insert image description here

3. Visit Prometheus

insert image description here

4. Add auto-start at boot

4.1. Configure rc-local.service

In debian 10, add a custom command in /etc/rc.local to realize the automatic execution of the command when booting up: booting up automatically.

Debian 10 has the rc-local service installed by default, but it is not started, so there is no /etc/rc.local file by default.

The default rc-local service is not started.
systemctl status rc-local shows Active: inactive (dead) is not started.
insert image description here
The default rc-local.service file
insert image description here
starts the rc-local service
and fails to start because the condition verification fails, which means that there is no /etc/rc.local file on the system.
insert image description here

Then first create the /etc/rc.local file and give it executable permissions

touch /etc/rc.local
chmod +x /etc/rc.local 

insert image description here

Start the rc-local service again and report an error

systemctl start rc-local.service

insert image description here
/etc/rc.local format error

Edit the /etc/rc.local file and add a line: #!/bin/bash

vi /etc/rc.local

Start the rc-local service again

systemctl start rc-local.service

insert image description here

4.2. Add a custom startup command

Edit the /etc/rc.local file

vi /etc/rc.local

Add a line:

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 &

Restart the server to see if Prometheus is running

insert image description here
insert image description here

4.3. View rc-local.service

systemctl status rc-local.service

You can see that all self-starting services configured through /etc/rc.local are displayed in CGroup
insert image description here

Guess you like

Origin blog.csdn.net/OceanWaves1993/article/details/130113380