普罗米修斯安装部署(Prometheus+grafana+node_exporter)

本文详细介绍了如何在Linux系统上安装Prometheus、Grafana和node_exporter,包括配置Prometheus的scrape和alerting规则,设置Grafana数据源和中文界面,以及部署node_exporter监控节点指标。还涉及了服务的开机启动、端口验证和重启操作。
摘要由CSDN通过智能技术生成

Prometheus安装

安装go、wget

yum -y install go
yum -y install wget

下载Prometheus

cd  /usr/local

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

tar -zxvf  prometheus-2.45.4.linux-amd64.tar.gz

mv   prometheus-2.45.4.linux-amd64   prometheus

cd    prometheus
vi 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:
        - 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: ["192.168.40.176:9090"]
  - job_name: "主机地址"
    static_configs:
      - targets: ["192.168.xx.177:9100","192.168.xx.178:9100","192.168.xx.179:9100","192.168.xx.180:9100","192.168.xx.181:9100","192.168.xx.182:9100"]

运行Prometheus

/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml

关闭Prometheus

pkill prometheus

添加服务并设置开机启动

vi  /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target
systemctl daemon-reload

systemctl enable prometheus.service

pkill prometheus

systemctl start prometheus.service

systemctl status prometheus.service

验证:浏览器打开IP:9090端口

在这里插入图片描述

Grafana安装

下载-安装-启动-自动启动-查看端口

wget https://mirrors.aliyun.com/grafana/yum/rpm/Package/grafana-enterprise-10.1.0-1.x86_64.rpm

rpm -ivh grafana-enterprise-10.1.0-1.x86_64.rpm

systemctl start grafana-server

systemctl enable grafana-server

netstat -natp | grep :3000

验证

访问ip:3000 账户:admin 密码:admin
在这里插入图片描述

更换中文

vi /usr/share/grafana/conf/defaults.ini

将default_language = en-US改为 zh-Hans

添加Prometheus数据源

在这里插入图片描述
在这里插入图片描述

按要求输入被监控端地址

更换仪表盘

仪表盘下载地址https://grafana.com/grafana/dashboards

文件为.json结尾

在这里插入图片描述

上传加载即可

在这里插入图片描述

node_exporter安装(被监控端)

下载-解压-更名-开放端口-重新加载-生成目录-生成日志文件

cd /opt
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
tar -zxvf node_exporter-1.7.0.linux-amd64.tar.gz
mv node_exporter-1.7.0.linux-amd64  node_exporter
sudo firewall-cmd --add-port=9100/tcp --permanent
sudo firewall-cmd --reload
mkdir -p /applog/node_exporter/
touch /applog/node_exporter/node_exporter.log
cd node_exporter

编辑脚本-脚本文件-授权

[root@kvm1 node_exporter]# vi node_exporter.sh
#!/bin/bash
/opt/node_exporter/node_exporter &>> /applog/node_exporter/node_exporter.log
chmod +x node_exporter.sh

添加系统文件重置-自启动-启动-状态

vi /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
# 启动脚本
ExecStart=/opt/node_exporter/node_exporter.sh

[Install]
WantedBy=multi-user.target

重置-自启动-启动-状态

systemctl daemon-reload

systemctl enable node_exporter

systemctl start node_exporter

systemctl status node_exporter

重启Prometheus,查看仪表盘,被控端会逐渐上线

systemctl restart prometheus
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

歌颂平凡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值