基于docker部署prometheus+grafana
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于docker部署prometheus+grafana相关的知识,希望对你有一定的参考价值。
参考技术A
启动node-exporter
启动prometheus
启动grafana
linux监控模板ID:11074
关于新增监控设备,只需要把IP写入ip文件,执行addjson.sh生产文件即可,系统6s扫描一次文件,一个机器对应一个json文件。
至此部署完成!
基于docker-compose部署Prometheus + Grafana监控系统
系统:CentOS Linux release 8.1.1911 (Core)
docker: Docker version 19.03.8, build afacb8b
docker-compose: 1.23
1. 安装docker
安装以下依赖包
yum install -y yum-utils device-mapper-persistent-data lvm2
添加docker的yum源
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
配置镜像加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-‘EOF‘
{
"registry-mirrors": ["https://zggyaen3.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
更新yum源缓存, 安装docker-ce
$ sudo yum makecache fast
$ sudo yum install docker-ce
普通用户需要加入docker组
$ sudo usermod -a -G docker ${USER}
修改docker存储位置(可以不改)
$ sudo systemctl stop docker
$ sudo mv /var/lib/docker /home/lan/docker
$ sudo ln -s /home/lan/docker /var/lib/docker
$ sudo systemctl start docker
$ sudo systemctl enable docker
2. docker-compose安装
$ sudo curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
如果下载很慢可手动下载,再上传至系统
下载路径: https://github.com/docker/compose/releases/ 可以选择对应的版本下载
3. 部署Prometheus, node-exporter, Grafana
编写docker-compose文件
version: "3"
services:
prom:
image: quay.io/prometheus/prometheus:latest
volumes:
- ./monitor/prometheus.yml:/etc/prometheus/prometheus.yml
command: "--config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/prometheus"
ports:
- 23333:9090 # prometheus的访问地址被我改成了23333
depends_on:
- exporter
exporter:
image: prom/node-exporter:latest
ports:
- "9100:9100"
# network_mode: host
grafana:
image: grafana/grafana
ports:
- "3000:3000"
environment:
- “GF_SECURITY_ADMIN_PASSWORD=Gz2020@”
- “GF_INSTALL_PLUGINS=alexanderzobnin-zabbix-app”
restart: "always"
volumes:
- “grafana-etc:/etc/grafana/”
- $GRAFANA_DIR/data:/var/lib/grafana:rw
- $GRAFANA_DIR$GRAFANA_plugins:/var/lib/grafana/plugins:rw
- /etc/localtime:/etc/localtime
depends_on:
- prom
4. 访问Prometheus
修改Prometheus配置文件,增加node-exporter监控
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: ‘prometheus‘
static_configs:
- targets: [‘localhost:9090‘]
- job_name: ‘server‘
static_configs:
- targets: [‘ip:9100‘]
验证Prometheus是否收到数据
ip:9100/metrics
5. Grafana配置
访问 http://ip:3000 初始账号:admin 初始密码: admin
1. 点击设置 --> Data Sources --> Add data source --> Prometheus --> URL(填写 http://ip:23333)
2. 添加图形插件:
访问地址https://grafana.com/grafana/dashboards/8919 --> Download JSON --> 回到自己的grafana主页面 --> 左上角的home --> Import dashboard --> Upload.json file --> 该填的都填了,可以点Import就行
以上是关于基于docker部署prometheus+grafana的主要内容,如果未能解决你的问题,请参考以下文章
基于docker-compose部署Prometheus + Grafana监控系统
基于docker-compose部署Prometheus + Grafana监控系统
基于consul对接prometheus监控docker容器资源