### 一、prometheus搭建

prometheus官网下载地址:[Download](https://prometheus.io/download/)

下载最新的包2022-11-23

```

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

```

创建prometheus目录

```

mkdir -p /opt/monitor

```

解压移动

```

tar -zxf prometheus-2.40.3.linux-amd64.tar.gz

mv prometheus-2.40.3.linux-amd64 /opt/monitor/prometheus

```

添加systemctl管理

vim /etc/systemd/system/prometheus.service

```

[Unit]

Description=prometheus

[Service]

ExecStart=/opt/monitor/prometheus/prometheus --config.file=/opt/monitor/prometheus/prometheus.yml

ExecReload=/bin/kill -HUP $MAINPID

KillMode=process

Restart=on-failure

[Install]

WantedBy=multi-user.target

```

启动prometheus

```

systemctl daemon-reload

systemctl start prometheus.service

systemctl status prometheus.service

```

### granfana搭建

granfana官网下载地址:[Download](https://grafana.com/grafana/download)

#下载截止2022-10-23最新版本

```

wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.2.6.linux-amd64.tar.gz

```

```

tar -zxvf grafana-enterprise-9.2.6.linux-amd64.tar.gz

mkdir -p /opt/monitor

mv grafana-9.2.6 /opt/monitor/grafana

```

vim /etc/systemd/system/grafana.service

```

[Unit]

Description=grafana

[Service]

ExecStart=/opt/monitor/grafana/bin/grafana-server -homepath=/opt/monitor/grafana

ExecReload=/bin/kill -HUP $MAINPID

KillMode=process

Restart=on-failure

[Install]

WantedBy=multi-user.target

```

```

systemctl daemon-reload

systemctl start grafana.service

systemctl status grafana.service

```

### node_exporter:用于监控Linux系统的指标采集器

prometheus采集器地址:[Exporters and integrations | Prometheus](https://prometheus.io/docs/instrumenting/exporters/)

```

wget https://github.com/prometheus/node_exporter/releases/download/v1.4.0/node_exporter-1.4.0.linux-amd64.tar.gz

```

```

tar -zxf node_exporter-1.4.0.linux-amd64.tar.gz

mv node_exporter-1.4.0.linux-amd64 /usr/local/node_exporter

```

vim /etc/systemd/system/node_exporter.service

```

[Unit]

Description=node_exporter

[Service]

ExecStart=/usr/local/node_exporter/node_exporter

#ExecStart=/usr/local/node_exporter/node_exporter --web.config=/usr/local/node_exporter/config.yml

ExecReload=/bin/kill -HUP $MAINPID

KillMode=process

Restart=on-failure

[Install]

WantedBy=multi-user.target

```

```

systemctl daemon-reload

systemctl start node_exporter.service

systemctl status node_exporter.service

```

配置prometheus

末尾添加配置,ip地址为安装node_exporter的地址

vim /opt/monitor/prometheus/prometheus.yml

```

- job_name: "node"

static_configs:

- targets: ["192.168.1.50:9100"]

```

访问prometheus的ip:9090查看

点击Status ----> Targets 查看

![image-1669626855725](https://zmzycc.top/upload/2022/11/image-1669626855725.png)

登陆granfana页面ip:3000

默认密码admin admin 初次登陆需要修改密码

点击左侧设置 ----> Data sources

![image-1669627042415](https://zmzycc.top/upload/2022/11/image-1669627042415.png)

添加监控模板

![image-1669627370350](https://zmzycc.top/upload/2022/11/image-1669627370350.png)

效果如图

![image-1669627398690](https://zmzycc.top/upload/2022/11/image-1669627398690.png)