环境
下载安装包
GIT下载地址:PrometheusV2.16.0下载使用GitHub 文件加速-CSDN博客
安装
创建prometheus用户及组,并指定家目录
[root@manager ~]# groupadd prometheus
[root@manager ~]# useradd -g prometheus prometheus -d /opt/prometheus/
将家目录做为prometheus
的安装目录,将下载的安装包上传于此,然后解压
[root@manager prometheus]# ll
total 58212
-rw-r--r-- 1 root root 59608515 May 26 16:58 prometheus-2.16.0.linux-amd64.tar.gz
[root@manager prometheus]# tar -zxvf prometheus-2.16.0.linux-amd64.tar.gz
prometheus-2.16.0.linux-amd64/
prometheus-2.16.0.linux-amd64/LICENSE
prometheus-2.16.0.linux-amd64/promtool
prometheus-2.16.0.linux-amd64/NOTICE
prometheus-2.16.0.linux-amd64/consoles/
prometheus-2.16.0.linux-amd64/consoles/node.html
prometheus-2.16.0.linux-amd64/consoles/index.html.example
prometheus-2.16.0.linux-amd64/consoles/prometheus-overview.html
prometheus-2.16.0.linux-amd64/consoles/node-disk.html
prometheus-2.16.0.linux-amd64/consoles/node-overview.html
prometheus-2.16.0.linux-amd64/consoles/node-cpu.html
prometheus-2.16.0.linux-amd64/consoles/prometheus.html
prometheus-2.16.0.linux-amd64/console_libraries/
prometheus-2.16.0.linux-amd64/console_libraries/menu.lib
prometheus-2.16.0.linux-amd64/console_libraries/prom.lib
prometheus-2.16.0.linux-amd64/prometheus
prometheus-2.16.0.linux-amd64/prometheus.yml
prometheus-2.16.0.linux-amd64/tsdb
[root@manager prometheus]# ll
查看目录内文件
[root@manager prometheus-2.16.0.linux-amd64]# ll
total 140984
drwxr-xr-x 2 3434 3434 38 Feb 14 09:52 console_libraries
drwxr-xr-x 2 3434 3434 173 Feb 14 09:52 consoles
-rw-r--r-- 1 3434 3434 11357 Feb 14 09:52 LICENSE
-rw-r--r-- 1 3434 3434 3184 Feb 14 09:52 NOTICE
-rwxr-xr-x 1 3434 3434 82329106 Feb 14 07:52 prometheus
-rw-r--r-- 1 3434 3434 926 Feb 14 09:52 prometheus.yml
-rwxr-xr-x 1 3434 3434 48417809 Feb 14 07:54 promtool
-rwxr-xr-x 1 3434 3434 13595766 Feb 14 07:54 tsdb
设置环境变量
[root@manager prometheus-2.16.0.linux-amd64]# vim /etc/profile
export PROMETHEUS_HOME=/opt/prometheus
export PATH=$PROMETHEUS_HOME/prometheus-2.16.0.linux-amd64:$PATH
[root@manager prometheus-2.16.0.linux-amd64]# source /etc/profile
创建prometheus.service
文件
进入/etc/systemd/system
目录,创建prometheus.service
文件,并编辑如下内容
# vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/opt/prometheus/prometheus-2.16.0.linux-amd64/prometheus --config.file=/opt/prometheus/prometheus-2.16.0.linux-amd64/prometheus.yml --storage.tsdb.path=/opt/prometheus/prometheus-2.16.0.linux-amd64/data
Restart=on-failure
[Install]
WantedBy=multi-user.target
进入/opt/prometheus/prometheus-2.16.0.linux-amd64
目录,创建一个数据存在目录,并修改所属用户及组
[root@manager prometheus-2.16.0.linux-amd64]# mkdir data
[root@manager prometheus-2.16.0.linux-amd64]# chown prometheus:prometheus data/
修改配置文件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']
启动
[root@manager prometheus-2.16.0.linux-amd64]# systemctl daemon-reload
[root@manager prometheus-2.16.0.linux-amd64]# systemctl start prometheus.service
[root@manager prometheus-2.16.0.linux-amd64]# systemctl enable prometheus.service
浏览器访问
浏览器访问http://IP:9090/
可打开自带的UI界面