GIT下载地址:
https://github.com/prometheus/prometheus/releases/download/v2.16.0/prometheus-2.16.0.linux-arm64.tar.gz
CSDN下载地址:
https://download.csdn.net/download/xtlhxl/12281245
创建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=` 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界面
GIT下载
https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz
3个节点都装
安装思路与prometheus
一样
prometheus
用户和组(没有安装prometheus
的节点)owner
/etc/systemd/system
目录下创建node_exporter.service
node_exporter.service
内容
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/opt/prometheus/node_exporter-0.17.0.linux-amd64/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动服务
[root@master prometheus]# systemctl daemon-reload
[root@master prometheus]# systemctl start node_exporter.service
[root@master prometheus]# systemctl enable node_exporter.service
http://10.180.249.57:9100/metrics
http://10.180.249.58:9100/metrics
http://10.180.249.59:9100/metrics
prometheus
访问如果要查询node_exporter
,需要对prometheus.yml
配置文件做修改
scrape_configs:
# The job name is added as a label `job=` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['10.180.249.57:9090']
- job_name: 'manager.rancher'
static_configs:
- targets: ['10.180.249.57:9100']
labels:
instance: 'sys1'
- job_name: 'master.rancher'
static_configs:
- targets: ['10.180.249.58:9100']
labels:
instance: 'sys2'
- job_name: 'worker.rancher'
static_configs:
- targets: ['10.180.249.59:9100']
labels:
instance: 'sys3'
然后重新启动prometheus
[root@manager prometheus-2.16.0.linux-amd64]# systemctl restart prometheus