prometheus二进制安装

2023-12-24 14:29:32

1、在需要安装prometheus的目录下执行wget命令下载软件到本地,如我的路径是/opt/module/prometheus

wget https://github.com/prometheus/prometheus/releases/download/v2.34.0/prometheus-2.34.0.linux-amd64.tar.gz

正在解析主机 objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.108.133, 185.199.111.133, 185.199.109.133, ...
正在连接 objects.githubusercontent.com (objects.githubusercontent.com)|185.199.108.133|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:76299772 (73M) [application/octet-stream]
正在保存至: “prometheus-2.34.0.linux-amd64.tar.gz”

100%[========================================================================================>] 76,299,772  15.7MB/s 用时 5.3s   

2023-12-24 11:51:25 (13.9 MB/s) - 已保存 “prometheus-2.34.0.linux-amd64.tar.gz” [76299772/76299772])

表示下载已完成
查看

[root@ambari-hadoop1 prometheus]# ll
总用量 74512
-rw-r--r-- 1 root root   76299772 315 2022 prometheus-2.34.0.linux-amd64.tar.gz

解压

[root@ambari-hadoop1 prometheus]# tar -zxvf prometheus-2.34.0.linux-amd64.tar.gz 
prometheus-2.34.0.linux-amd64/
prometheus-2.34.0.linux-amd64/consoles/
prometheus-2.34.0.linux-amd64/consoles/index.html.example
prometheus-2.34.0.linux-amd64/consoles/node-cpu.html
prometheus-2.34.0.linux-amd64/consoles/node-disk.html
prometheus-2.34.0.linux-amd64/consoles/node-overview.html
prometheus-2.34.0.linux-amd64/consoles/node.html
prometheus-2.34.0.linux-amd64/consoles/prometheus-overview.html
prometheus-2.34.0.linux-amd64/consoles/prometheus.html
prometheus-2.34.0.linux-amd64/console_libraries/
prometheus-2.34.0.linux-amd64/console_libraries/menu.lib
prometheus-2.34.0.linux-amd64/console_libraries/prom.lib
prometheus-2.34.0.linux-amd64/prometheus.yml
prometheus-2.34.0.linux-amd64/LICENSE
prometheus-2.34.0.linux-amd64/NOTICE
prometheus-2.34.0.linux-amd64/prometheus
prometheus-2.34.0.linux-amd64/promtool

解压后查看

[root@ambari-hadoop1 prometheus]# ll
总用量 74512
drwxr-xr-x 4 3434 3434      132 315 2022 prometheus-2.34.0.linux-amd64
-rw-r--r-- 1 root root 76299772 315 2022 prometheus-2.34.0.linux-amd64.tar.gz

删除压缩文件

[root@ambari-hadoop1 prometheus]# rm -rf prometheus-2.34.0.linux-amd64.tar.gz 

2、创建开机启动项

vim /usr/lib/systemd/system/prometheus.service

配置内容如下

[Unit]
Description=prometheus
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
User=root
Group=root
ExecStart=/opt/module/prometheus/prometheus-2.34.0.linux-amd64/prometheus --config.file=/opt/module/prometheus/prometheus-2.34.0.linux-amd64/prometheus.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target

设置自动启动:

$ systemctl enable prometheus

报错

[root@ambari-hadoop1 system]# systemctl enable prometheus
Failed to execute operation: File exists

原因:之前安装过prometheus,没有卸载干净
接下来卸载之前安装的prometheus文件
先查找

[root@ambari-hadoop1 system]# find / -name prometheus.service
/etc/systemd/system/multi-user.target.wants/prometheus.service
/usr/lib/systemd/system/prometheus.service

删除第一个文件,第二个文件是刚刚自己创建的prometheus.service

[root@ambari-hadoop1 system]#  rm -rf /etc/systemd/system/multi-user.target.wants/prometheus.service

再次查看

[root@ambari-hadoop1 system]# find / -name prometheus.service
/usr/lib/systemd/system/prometheus.service

设置开机启动

[root@ambari-hadoop1 system]# systemctl enable prometheus
Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /usr/lib/systemd/system/prometheus.service.

启动服务并查看启动状态:

# 重新加载某个服务的配置文件
$ systemctl daemon-reload
# 启动prometheus
$ systemctl start prometheus
# 查看prometheus状态
$ systemctl status prometheus

[root@ambari-hadoop1 system]# systemctl status prometheus
● prometheus.service - prometheus
   Loaded: loaded (/usr/lib/systemd/system/prometheus.service; enabled; vendor preset: disabled)
   Active: active (running) since 日 2023-12-24 12:08:55 CST; 5s ago
     Docs: https://prometheus.io/
 Main PID: 3960 (prometheus)
    Tasks: 9
   Memory: 19.4M
   CGroup: /system.slice/prometheus.service
           └─3960 /opt/module/prometheus/prometheus-2.34.0.linux-amd64/prometheus --config.file=/opt/module/prometheus/promethe...

1224 12:08:55 ambari-hadoop1 prometheus[3960]: ts=2023-12-24T04:08:55.726Z caller=head.go:493 level=info component=tsd... any"
12月 24 12:08:55 ambari-hadoop1 prometheus[3960]: ts=2023-12-24T04:08:55.726Z caller=head.go:536 level=info component=tsd…=5.31μs
12月 24 12:08:55 ambari-hadoop1 prometheus[3960]: ts=2023-12-24T04:08:55.726Z caller=head.go:542 level=info component=tsd...hile"
1224 12:08:55 ambari-hadoop1 prometheus[3960]: ts=2023-12-24T04:08:55.727Z caller=head.go:613 level=info component=tsd...ent=0
1224 12:08:55 ambari-hadoop1 prometheus[3960]: ts=2023-12-24T04:08:55.727Z caller=head.go:619 level=info component=tsd…0.235μs
1224 12:08:55 ambari-hadoop1 prometheus[3960]: ts=2023-12-24T04:08:55.727Z caller=main.go:958 level=info fs_type=XFS_S...MAGIC
1224 12:08:55 ambari-hadoop1 prometheus[3960]: ts=2023-12-24T04:08:55.727Z caller=main.go:961 level=info msg="TSDB started"
1224 12:08:55 ambari-hadoop1 prometheus[3960]: ts=2023-12-24T04:08:55.727Z caller=main.go:1142 level=info msg="Loading...s.yml
12月 24 12:08:55 ambari-hadoop1 prometheus[3960]: ts=2023-12-24T04:08:55.728Z caller=main.go:1179 level=info msg="Completed lo…μs
1224 12:08:55 ambari-hadoop1 prometheus[3960]: ts=2023-12-24T04:08:55.728Z caller=main.go:910 level=info msg="Server i...sts."
Hint: Some lines were ellipsized, use -l to show in full.

3、访问prometheus页面查看 http协议+prometheus安装主机的ip地址+端口号

http://192.168.0.21:9090

在这里插入图片描述
在页面Status------>targets查看节点信息
在这里插入图片描述4、在本机上安装Node-exporter客户端采集数据
NodeExporter 是 Prometheus 官方提供的一个可以采集到主机信息的应用程序,它能采集到机器的 CPU、内存、磁盘等信息。作为基础的组件,一般在所有的节点都都会安装。
从prometheus官网找https://prometheus.io/download/ 获取最新的 Node Exporter 版本的二进制包:

https://prometheus.io/download/

在这里插入图片描述
下载node_exporter-1.7.0.linux-amd64.tar.gz

[root@ambari-hadoop1 node-exporter]# ll
总用量 10176
-rw-r--r-- 1 root root 10419253 1224 13:22 node_exporter-1.7.0.linux-amd64.tar.gz
[root@ambari-hadoop1 node-exporter]# pwd
/opt/module/prometheus/node-exporter

解压

[root@ambari-hadoop1 node-exporter]# pwd
/opt/module/prometheus/node-exporter
[root@ambari-hadoop1 node-exporter]# tar -zxvf node_exporter-1.7.0.linux-amd64.tar.gz 
node_exporter-1.7.0.linux-amd64/
node_exporter-1.7.0.linux-amd64/LICENSE
node_exporter-1.7.0.linux-amd64/node_exporter
node_exporter-1.7.0.linux-amd64/NOTICE
[root@ambari-hadoop1 node-exporter]# ll
总用量 10176
drwxr-xr-x 2 1001 1002       56 1113 08:03 node_exporter-1.7.0.linux-amd64
-rw-r--r-- 1 root root 10419253 1224 13:22 node_exporter-1.7.0.linux-amd64.tar.gz

在解压后的目录下后台运行

[root@ambari-hadoop1 node_exporter-1.7.0.linux-amd64]# pwd
/opt/module/prometheus/node-exporter/node_exporter-1.7.0.linux-amd64

运行node Exporter ,指定为8080端口运行


# 前台运行
$ ./node_exporter --web.listen-address 192.168.0.21:8080
# 后台运行
$ nohup ./node_exporter --web.listen-address 192.168.0.21:8080 >> nohup.out 2>&1 &
[root@ambari-hadoop1 node_exporter-1.7.0.linux-amd64]# pwd
/opt/module/prometheus/node-exporter/node_exporter-1.7.0.linux-amd64
[root@ambari-hadoop1 node_exporter-1.7.0.linux-amd64]# nohup ./node_exporter --web.listen-address 192.168.0.21:8080 >> nohup.out 2>&1 &
[1] 9032

查看node-exporter运行成功后的页面

http://192.168.0.21:8080

在这里插入图片描述
在这里插入图片描述
配置prometheus的监控数据源

现在我们运行了 Prometheus 服务器,也运行了业务数据源 NodeExporter。但此时 Prometheus 还获取不到任何数据,我们还需要配置下 prometheus.yml 文件,让其去拉取 Node Exporter 的数据

prometheus.yml并在 scrape_configs 节点下添加以下内容:

[root@ambari-hadoop1 prometheus-2.34.0.linux-amd64]# pwd
/opt/module/prometheus/prometheus-2.34.0.linux-amd64
[root@ambari-hadoop1 prometheus-2.34.0.linux-amd64]# ll
总用量 197372
drwxr-xr-x 2 3434 3434        38 315 2022 console_libraries
drwxr-xr-x 2 3434 3434       173 315 2022 consoles
drwxr-xr-x 2 root root         6 1224 12:01 data
-rw-r--r-- 1 3434 3434     11357 315 2022 LICENSE
-rw-r--r-- 1 3434 3434      3773 315 2022 NOTICE
-rwxr-xr-x 1 3434 3434 105137495 315 2022 prometheus
-rw-r--r-- 1 3434 3434       934 315 2022 prometheus.yml
-rwxr-xr-x 1 3434 3434  96946761 315 2022 promtool
[root@ambari-hadoop1 prometheus-2.34.0.linux-amd64]# 

修改路径下的prometheus.yml文件
下方为原先有的文件

[root@ambari-hadoop1 prometheus-2.34.0.linux-amd64]# vim prometheus.yml 

# 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"]

需要增加的配置文件


  - job_name: 'node-exporter'
    static_configs:
      - targets: ['localhost:8080']

修改后的配置文件

# 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"]

  - job_name: 'node-exporter'
    static_configs:
      - targets: ['localhost:8080']

注意:每次修改配置完成,用promtool检测配置文件是否正确

$ ./promtool check config ./prometheus.yml

[root@ambari-hadoop1 prometheus-2.34.0.linux-amd64]# ./promtool check config ./prometheus.yml
Checking ./prometheus.yml
 SUCCESS: ./prometheus.yml is valid prometheus config file syntax

重启prometheus

$  systemctl restart prometheus

在这里插入图片描述

重启后发现增加了node-exporter的信息,状态为up

文章来源:https://blog.csdn.net/weixin_44870066/article/details/135176047
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。