1. 服务端prometheus安装部署
下载地址:https://prometheus.io/
- 对
prometheus
进行解压(这里进入存放文件目录下进行解压)
tar -zxvf prometheus-2.53.0.linux-amd64.tar.gz
-
启动
prometheus
./prometheus --config.file=prometheus.yml
-
进行
prometheus
系统服务配置vim /usr/lib/systemd/system/prometheus.service
将以下代码写入
prometheus.service
[Unit] Description=https://prometheus.io [Service] Restart=on-failure ExecStart=/prometheus/prometheus-2.53.0/prometheus --config.file=/prometheus/prometheus-2.53.0/prometheus.yml --storage.tsdb.path=/prometheus/data --storage.tsdb.retention.time=60d --web.enable-lifecycle [Install] WantedBy=multi-user.target
注:
curl -XPOST http://ip:9090/-/reload或者浏览器直接请求
-
启动
prometheus
并查看状态systemctl start prometheus
systemctl status prometheus
访问地址:
服务器IP:9090
2. grafana安装
下载地址:https://grafana.com/grafana/download
-
对
grafana
进行解压(这里进入存放文件目录下进行解压)tar -zxvf grafana-enterprise-11.1.0.linux-amd64.tar.gz
-
进行
grafana
系统服务配置vim /usr/lib/systemd/system/grafana.service
将以下代码写入
grafana.service
[Unit] Description=https://docs.grafana.org [Service] Restart=on-failure ExecStart=/prometheus/grafana/bin/grafana-server --config=/prometheus/grafana/conf/defaults.ini --homepath=/prometheus/grafana/ [Install] WantedBy=multi-user.target
-
修改
default.ini
default_language = zh-Hans
-
启动
grafana
并查看状态systemctl start grafana
systemctl status grafana
访问地址:
服务器IP:3000
3. 客户端node_exporter
安装
下载地址:https://prometheus.io/download/
-
对
node_exporter
进行解压(这里进入存放文件目录下进行解压)tar -zxvf attachment\;\ filename\=node_exporter-1.8.1.linux-amd64.tar.gz
-
为其进行系统服务配置
vim /usr/lib/systemd/system/node_exporter.service
将以下代码写入
node_exporter.service
[Unit] Description=node_exporter Documentation=https://prometheus.io [Service] Restart=on-failure ExecStart=/prometheus/node_exporter/node_exporter [Install] WantedBy=multi-user.target
-
启动
node_exporter
并查看状态systemctl start node_exporter
systemctl status node_exporter
访问地址:
服务器IP:9100/metrics
4. 将node_exporter
加到prometheus
中
-
修改
prometheus.yml
,在scrape_configs
下添加- job_name: "node_exporter" static_configs: - targets: ["192.168.109.1:9100","192.168.109.2:9100"] # targets处可添加多个节点
-
重新加载配置文件
curl -XPOST http://ip:9090/-/reload
之后在prometheus的status下的targets下可以看到node_exporter
5. grafana
添加仪表盘
-
添加
Prometheus
连接 --> 数据源 --> 添加新数据源 --> 选择prometheus --> 在connection处添加prometheus地址 --> save & test
-
添加仪表板
仪表板 --> 新建仪表板 --> 导入仪表板 --> 在https://grafana.com/grafana/dashboards选择仪表板并copy id to clipboard --> 在导入仪表板的界面粘贴ID并加载
模板下载样例:https://grafana.com/grafana/dashboards/16098-node-exporter-dashboard-20240520-job/
6. 监控redis
-
下载
redis_exporter
https://github.com/oliver006/redis_exporter/releases
tar -zxvf attachment\;\ filename\=redis_exporter-v1.61.0.linux-amd64.tar.gz
-
为其进行系统服务配置
vim /usr/lib/systemd/system/redis_exporter.service
[Unit] Description=redis_exporter Documentation=https://github.com/oliver006/redis_exporter [Service] Restart=on-failure ExecStart=/data/prometheus/redis_exporter/redis_exporter -redis.addr ip:9121 -redis.password redis密码 [Install] WantedBy=multi-user.target
注:上述
ExecStart=/data/prometheus/redis_exporter/redis_exporter -redis.addr ip:端口 -redis.password redis密码
中一定要修改自己的redisip和密码
-
启动
redis_exporter
systemctl start redis_exporter
-
查看
redis_exporter
状态systemctl status redis_exporter
-
修改
prometheus.yml
,在scrape_configs
下添加:- job_name: "redis_exporter" static_configs: - targets: ["192.168.109.1:9121"] # targets处可添加多个节点
-
重新加载配置文件
curl -XPOST http://ip:9090/-/reload