搭建基础监控系统
前言
- 适用场景:内网离线部署,只需要了解服务器基本情况,不需要告警系统。
- 需要准备的安装包:
- grafana的docker包(先在线下载,然后
docker save
保存镜像。如果没有docker,还需要准备docker的离线安装包) - prometheus和node_exporter官方下载地址
- 从grafana官方下载dashboard的json文件,ID为8919或1860
- grafana的docker包(先在线下载,然后
环境信息
系统版本 | IP | 应用 | 应用版本 | 说明 |
---|---|---|---|---|
Debian 12 x86-64 | 192.168.0.11 | prometheus | 2.45.2 | 服务端 |
Debian 12 x86-64 | 192.168.0.11 | node_exporter | 1.7.0 | 系统监控客户端 |
Debian 12 x86-64 | 192.168.0.11 | grafana | 10.2.3 | 监控数据可视化 |
安装prometheus
- 解压和创建目录
mkdir -p /home/apps
tar xf prometheus-2.37.1.linux-amd64.tar.gz -C /home/apps
cd /home/apps
mv prometheus-2.37.1.linux-amd64 prometheus
rm -f prometheus-2.37.1.linux-amd64.tar.gz
cd prometheus
mkdir sd_configs data
- 编辑服务配置文件:
vim /home/apps/prometheus/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:
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"
# 修改以下内容
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
file_sd_configs:
- files: ['/home/apps/prometheus/sd_configs/*.yml']
refresh_interval: 10s
- 启动。(启动脚本可参考"附录 - prometheus启动脚本")
nohup /home/apps/prometheus/prometheus \
--storage.tsdb.path=/home/apps/prometheus/data \
--config.file=/home/apps/prometheus/prometheus.yml \
--web.listen-address=:19090 \
--storage.tsdb.retention=15d > /dev/null 2>&1 &
参数说明:
-storage.tsdb.path
:数据存储路径-config.file
:配置文件路径-web.listen-address
:服务监听端口-storage.tsdb.retention
:数据存储期限。这里设置为15天
- 编辑文件服务发现的配置文件:
vim /home/web/prometheus/prometheus/sd_configs/nodes.yml
- targets: ['192.168.0.11:19091']
labels:
instance: 192.168.0.11
- Prometheus服务端配置完成