安装Prometheus grafana安装

52 阅读2分钟

解压安装包;tar -zxvf prometheus-2.29.1.linux-amd64.tar.gz

image.png 修改配置文件 prometheus.yml
cat prometheus.yml

image.png 配置说明:

1、global 配置块:控制 Prometheus 服务器的全局配置

➢ scrape_interval:配置拉取数据的时间间隔,默认为 1 分钟。

➢ evaluation_interval:规则验证(生成 alert)的时间间隔,默认为 1 分钟。

2、rule_files 配置块:规则配置文件

3、scrape_configs 配置块:配置采集目标相关, prometheus 监视的目标。Prometheus

自身的运行信息可以通过 HTTP 访问,所以 Prometheus 可以监控自己的运行数据。

➢ job_name:监控作业的名称

➢ static_configs:表示静态目标配置,就是固定从某个 target 拉取数据

➢ targets : 指 定 监 控 的 目 标 , 其 实 就 是 从 哪 儿 拉 取 数 据 。 Prometheus 会 从

http://hadoop202:9090/metrics 上拉取数据。

Prometheus 是可以在运行时自动加载配置的。启动时需要添加:--web.enable-lifecycle

启 动 Prometheus Server 、Pushgateway 和 Alertmanager

Prometheus Server 目录下执行启动命令

nohup ./prometheus --config.file=prometheus.yml > ./prometheus.log 2>&1 &

Pushgateway 目录下执行启动命令

nohup ./pushgateway --web.listen-address :9091 > ./pushgateway.log 2>&1 &

设置prometheus为开机自启

配置开机自启文件

[root@centos1 system]# cat prometheus.service

[Unit]

Description=prometheus

After=network.target

[Service]

Type=simple

User=root

ExecStart=/opt/prometheus/prometheus-2.29.1.linux-amd64/prometheus --config.file=/opt/prometheus/prometheus-2.29.1.linux-amd64/prometheus.yml

Restart=on-failure

[Install]

WantedBy=multi-user.target

启动普罗米修斯并检查

[root@centos1 system]# systemctl daemon-reload

[root@centos1 system]# systemctl start prometheus.service

[root@centos1 system]# systemctl status prometheus.service

● prometheus.service - prometheus

Loaded: loaded (/usr/lib/systemd/system/prometheus.service; enabled; vendor preset: disabled)

Active: active (running) since 三 2023-07-26 14:59:21 CST; 9s ago

Main PID: 23099 (prometheus)

CGroup: /system.slice/prometheus.service

└─23099 /opt/prometheus/prometheus-2.29.1.linux-amd64/prometheus --config.file=/opt/prometheus/prometheus-2...

设置node_exporter为开机自启

cat /usr/lib/systemd/system/node_exporter.service

image.png systemctl enable node_exporter.service

systemctl start node_exporter.service

安装Grafana

减压:tar -zxvf grafana-enterprise-8.1.2.linux-amd64.tar.gz -C /opt/module/ 5.2 启动 Grafan

启动: nohup ./bin/grafana-server web > ./grafana.log 2>&1 &

打开web:192.168.26.128:3000,默认用户名和密码:admin

添加数据源

image.png 创建仪表盘

image.png 导入文件创建仪表盘

image.png