基于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_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就行
相关推荐
链块学院 2020-11-06
afanti 2020-09-14
白开水 2020-07-19
liyansring 2020-07-18
shenzhenzsw 2020-07-18
啦啦啦啦啦 2020-06-28
yangliuhbhd 2020-06-12
小爷有点狂 2020-06-12
无风的雨 2020-06-12
changecan 2020-06-11
蒜蓉粉丝蒸扇贝 2020-06-10
lihongtai 2020-06-08
liaochaowu 2020-06-06
zwt00 2020-06-05
scmrpu 2020-06-02
小信 2020-05-14