5 分钟搭建 Prometheus + Grafana 监控

一.安装 Prometheus

复制代码
cd /usr/local/
wget https://github.com/prometheus/prometheus/releases/download/v2.38.0/prometheus-2.38.0.linux-amd64.tar.gz
tar xvf prometheus-2.38.0.linux-amd64.tar.gz
ln -s prometheus-2.38.0.linux-amd64 prometheus

二.安装 node_exporter

在被监控机器上下载 node_exporter

复制代码
wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
tar xvf node_exporter-1.3.1.linux-amd64.tar.gz
ln -s node_exporter-1.3.1.linux-amd64 node_exporter

启动 node_exporter

复制代码
nohup ./node_exporter  --web.listen-address=":9100"&
netstat -ntlup | grep 9100

三.安装 mysqld_exporter

在被监控机器上下载 mysqld_exporter

复制代码
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.14.0/mysqld_exporter-0.14.0.linux-amd64.tar.gz
tar xvf mysqld_exporter-0.14.0.linux-amd64.tar.gz
ln -s mysqld_exporter-0.14.0.linux-amd64 mysqld_exporter

创建监控⽤户

复制代码
create user 'monitor'@'127.0.0.1' identified with mysql_native_password by '123456';
grant select,replication client, process on *.* to 'monitor'@'127.0.0.1';

添加客户端账号

复制代码
vim /usr/local/mysqld_exporter/.my.cnf

 [client]
 host=127.0.0.1
 port=3306
 user=monitor
 password=123456

重启 mysqld_exporter

复制代码
nohup /usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf &

netstat -ntlup | grep 9104

四.修改 prometheus 配置⽂件

添加被监控主机

复制代码
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"]


  - job_name: 'node2'
    static_configs:
      - targets: ['192.168.80.11:9100']

  - job_name: 'node-mysql'
    static_configs:
      - targets: ['192.168.80.11:9104']

重启 prometheus

复制代码
pkill prometheus
/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &

检查 Targets

五.安装 Grafana

下载 Grafana

复制代码
wget https://dl.grafana.com/oss/release/grafana-9.1.5.linux-amd64.tar.gz
tar -zxvf grafana-9.1.5.linux-amd64.tar.gz
ln -s grafana-9.1.5 grafana

启动 grafana

复制代码
cd grafana
./bin/grafana-server &

登录 grafana

初始账号密码:admin/admin

六.导入主机

Add data source

这个 1860 对应的模板地址是 https://grafana.com/grafana/dashboards/1860-node-exporter-full/![](https://i-blog.csdnimg.cn/direct/d7f36b4db3034f82ab5223da316fc402.png)

查看效果

七.导入mysql

导⼊⽅式同上,只不过对应的 ID 是 7362。

https://grafana.com/grafana/dashboards/7362-mysql-overview/

完成。

相关推荐
奈斯ing11 小时前
【prometheus+Grafana篇】Prometheus与Grafana:深入了解监控架构与数据可视化分析平台
信息可视化·grafana·prometheus
东风微鸣2 天前
关于全球化大规模混合云 Kubernetes Prometheus 监控体系标准化及 GitOps 自动化改进方案
kubernetes·自动化·prometheus
迷茫运维路2 天前
K8S+Prometheus+Consul+alertWebhook实现全链路服务自动发现与监控、告警配置实战
运维·kubernetes·go·prometheus·consul
被一米六支配的恐惧4 天前
k8s部署grafana
容器·kubernetes·grafana
听说唐僧不吃肉4 天前
Prometheus实现负载均衡并将多个实例数据汇总到一个主Prometheus
负载均衡·prometheus
敏君宝爸4 天前
SpringBoot2.x整合Prometheus+Grafana以及自定义采集
spring boot·grafana·prometheus
风中凌乱5 天前
ClickHouse接入prometheus监控
服务器·clickhouse·prometheus
敏君宝爸5 天前
prometheus整合jmx_exporter 使用jmx_exporter监控Kafka
分布式·kafka·prometheus
企鹅侠客6 天前
Prometheus告警从触发到收到通知延迟在哪?
运维·prometheus·监控