【盲盒】系列:标题不写内容。
比如Prometheus
最基础的样例10分钟即可部署
web-config, 这个用的Bcrypt - Salt盐选的10位的(在前几位也能看出来10)
从官网 获取一个监控 Prometheus 的面板 Prometheus 2.0 Overview Id:3662
https://kr.yetoc.lol/s/G9HW
1. 带数据库
https://prometheus.io/download/
2. 轻量节点输出: Node_exporter
https://github.com/prometheus/node_exporter/releases/download/v1.8.1/node_exporter-1.8.1.linux-amd64.tar.gz
Prometheus
docker network create devopsnetwork
mkdir -p grafana_data && chown -R 472:472 ./grafana_data
mkdir prometheus_data && chown 65534 ./prometheus_data
compose.yml prometheus.yml web-config.yml
version: '3.1'
services:
prometheus:
restart: always
container_name: prometheus
image: prom/prometheus:v2.47.2
command:
# 配置文件
- '--config.file=/etc/prometheus/prometheus.yml'
# 指定web面板账号密码访问
- '--web.config.file=/etc/prometheus/web-config.yml'
# 数据目录
- '--storage.tsdb.path=/prometheus'
# 数据保留时间
- '--storage.tsdb.retention.time=30d'
# 运行使用 curl -X POST http://localhost:9090/-/reload 重载其配置
- '--web.enable-lifecycle'
volumes:
# 需要权限 mkdir prometheus_data && chown 65534 ./prometheus_data
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- ./prometheus_data:/prometheus
- ./web-config.yml:/etc/prometheus/web-config.yml
ports:
- 9090:9090
networks:
- devopsnetwork
networks:
devopsnetwork:
external: true
prometheus.yml
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
- job_name: 'prometheus' #这里有两个,第一个job是采集自身的9090
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
# 启用了账号密码 web-config.yml basic_auth_users 需要配置
basic_auth:
username: root
password: A100000
- job_name: 'node_exporter' #第二个job是采集node_exporter,节点输出者这个有很多服务器自身指标,CPU资源等
scrape_interval: 5s
static_configs:
- targets: ['localhost:9100']
- web-config.yml
basic_auth_users:
root:$2a$10$pdRThlPipUQ1Q6/vfDjWAuV6aIwAVGn.02iwfu5s1n.OHTQx/Rb9y
- node-exporter
https://github.com/prometheus/node_exporter/releases/download/v1.8.1/node_exporter-1.8.1.linux-amd64.tar.gz
解压即可使用
tar -xf node_exporter-1.8.1.linux-amd64.tar.gz
nohup ./node_exporter &
或者打包成systemctl service
sudo mv node_exporter-1.8.1.linux-amd64 /usr/local/bin/node_exporter
sudo vim /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=nobody
ExecStart=/usr/local/bin/node_exporter/node_exporter
[Install]
WantedBy=default.target
sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl enable node_exporter
# sudo systemctl status node_exporter #查看状态
Grafana:
compose.yml:
version: '3.1'
services:
grafana:
restart: always
container_name: grafana
image: grafana/grafana:10.2.0
ports:
- "3000:3000"
volumes:
- ./grafana_data:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_USER=root
- GF_SECURITY_ADMIN_PASSWORD=A100000
- GF_USERS_ALLOW_SIGN_UP=false
networks:
- devopsnetwork
networks:
devopsnetwork:
external: true
启动:
docker compose up -d
最终效果: